Ensure CPD uses tab width of 1 for tabs consistently
The columns that are reported by CPD were inconsistent across languages before. A language like Java (using a JavaCC-based tokenizer) would use a width of 8 for tabs, whereas a language like C# (using an Antlr-based tokenizer) would use 1 instead. This includes unit tests for most languages to ensure a tab character is counted as 1. The configuration for JavaCC has been adjusted to respect this as well.
This commit is contained in:
@ -51,4 +51,9 @@ public class SwiftTokenizerTest extends CpdTextComparisonTest {
|
||||
public void testStackoverflowOnLongLiteral() {
|
||||
doTest("Issue628");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabWidth() {
|
||||
doTest("tabWidth");
|
||||
}
|
||||
}
|
||||
|
29
pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.swift
vendored
Normal file
29
pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.swift
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// file for supporting swift 5.2 changes : https://github.com/apple/swift/blob/master/CHANGELOG.md#swift-52
|
||||
|
||||
// https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md
|
||||
struct Adder {
|
||||
var base: Int
|
||||
func callAsFunction(_ x: Int) -> Int {
|
||||
return x + base
|
||||
}
|
||||
}
|
||||
var adder = Adder(base: 3)
|
||||
adder(10) // returns 13, same as `adder.callAsFunction(10)`
|
||||
|
||||
// https://github.com/apple/swift-evolution/blob/master/proposals/0249-key-path-literal-function-expressions.md
|
||||
struct User {
|
||||
let email: String
|
||||
let isAdmin: Bool
|
||||
}
|
||||
|
||||
users.map(\.email) // this is equivalent to: users.map { $0[keyPath: \User.email] }
|
||||
|
||||
// https://bugs.swift.org/browse/SR-6118
|
||||
struct Subscriptable {
|
||||
subscript(x: Int, y: Int = 0) {
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
let s = Subscriptable()
|
||||
print(s[0])
|
111
pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.txt
vendored
Normal file
111
pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.txt
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
[Image] or [Truncated image[ Bcol Ecol
|
||||
L4
|
||||
[struct] 1 6
|
||||
[Adder] 8 12
|
||||
[{] 14 14
|
||||
L5
|
||||
[var] 2 4
|
||||
[base] 6 9
|
||||
[:] 10 10
|
||||
[Int] 12 14
|
||||
L6
|
||||
[func] 2 5
|
||||
[callAsFunction] 7 20
|
||||
[(] 21 21
|
||||
[_] 22 22
|
||||
[x] 24 24
|
||||
[:] 25 25
|
||||
[Int] 27 29
|
||||
[)] 30 30
|
||||
[->] 32 33
|
||||
[Int] 35 37
|
||||
[{] 39 39
|
||||
L7
|
||||
[return] 3 8
|
||||
[x] 10 10
|
||||
[+] 12 12
|
||||
[base] 14 17
|
||||
L8
|
||||
[}] 2 2
|
||||
L9
|
||||
[}] 1 1
|
||||
L10
|
||||
[var] 1 3
|
||||
[adder] 5 9
|
||||
[=] 11 11
|
||||
[Adder] 13 17
|
||||
[(] 18 18
|
||||
[base] 19 22
|
||||
[:] 23 23
|
||||
[3] 25 25
|
||||
[)] 26 26
|
||||
L11
|
||||
[adder] 1 5
|
||||
[(] 6 6
|
||||
[10] 7 8
|
||||
[)] 9 9
|
||||
L14
|
||||
[struct] 1 6
|
||||
[User] 8 11
|
||||
[{] 13 13
|
||||
L15
|
||||
[let] 2 4
|
||||
[email] 6 10
|
||||
[:] 11 11
|
||||
[String] 13 18
|
||||
L16
|
||||
[let] 2 4
|
||||
[isAdmin] 6 12
|
||||
[:] 13 13
|
||||
[Bool] 15 18
|
||||
L17
|
||||
[}] 1 1
|
||||
L19
|
||||
[users] 1 5
|
||||
[.] 6 6
|
||||
[map] 7 9
|
||||
[(] 10 10
|
||||
[\\] 11 11
|
||||
[.] 12 12
|
||||
[email] 13 17
|
||||
[)] 18 18
|
||||
L22
|
||||
[struct] 1 6
|
||||
[Subscriptable] 8 20
|
||||
[{] 22 22
|
||||
L23
|
||||
[subscript] 2 10
|
||||
[(] 11 11
|
||||
[x] 12 12
|
||||
[:] 13 13
|
||||
[Int] 15 17
|
||||
[,] 18 18
|
||||
[y] 20 20
|
||||
[:] 21 21
|
||||
[Int] 23 25
|
||||
[=] 27 27
|
||||
[0] 29 29
|
||||
[)] 30 30
|
||||
[{] 32 32
|
||||
L24
|
||||
[...] 3 5
|
||||
L25
|
||||
[}] 2 2
|
||||
L26
|
||||
[}] 1 1
|
||||
L28
|
||||
[let] 1 3
|
||||
[s] 5 5
|
||||
[=] 7 7
|
||||
[Subscriptable] 9 21
|
||||
[(] 22 22
|
||||
[)] 23 23
|
||||
L29
|
||||
[print] 1 5
|
||||
[(] 6 6
|
||||
[s] 7 7
|
||||
[\[] 8 8
|
||||
[0] 9 9
|
||||
[\]] 10 10
|
||||
[)] 11 11
|
||||
EOF
|
Reference in New Issue
Block a user