diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexTokenizerTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexTokenizerTest.java index ec002be37c..5e64f0082d 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexTokenizerTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexTokenizerTest.java @@ -47,6 +47,11 @@ public class ApexTokenizerTest extends CpdTextComparisonTest { doTest("comments"); } + @Test + public void testTabWidth() { + doTest("tabWidth"); + } + private Properties caseSensitive() { return properties(true); } diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.cls b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.cls new file mode 100644 index 0000000000..0bd91fc541 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.cls @@ -0,0 +1,10 @@ +/* + * Some comment + */ +public with sharing class Simple { + public String someParam { get; set; } + + public void getInit() { + someParam = "test"; + } +} diff --git a/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.txt b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..65b78a75c9 --- /dev/null +++ b/pmd-apex/src/test/resources/net/sourceforge/pmd/lang/apex/cpd/testdata/tabWidth.txt @@ -0,0 +1,35 @@ + [Image] or [Truncated image[ Bcol Ecol +L4 + [public] 1 6 + [with] 8 11 + [sharing] 13 19 + [class] 21 25 + [simple] 27 32 + [{] 34 34 +L5 + [public] 2 7 + [string] 9 14 + [someparam] 16 24 + [{] 26 26 + [get] 28 30 + [;] 31 31 + [set] 33 35 + [;] 36 36 + [}] 38 38 +L7 + [public] 2 7 + [void] 9 12 + [getinit] 14 20 + [(] 21 21 + [)] 22 22 + [{] 24 24 +L8 + [someparam] 3 11 + [=] 13 13 + [test] 16 19 + [;] 21 21 +L9 + [}] 2 2 +L10 + [}] 1 1 +EOF diff --git a/pmd-core/src/main/ant/alljavacc.xml b/pmd-core/src/main/ant/alljavacc.xml index e792989ba3..2940d3ee58 100644 --- a/pmd-core/src/main/ant/alljavacc.xml +++ b/pmd-core/src/main/ant/alljavacc.xml @@ -71,6 +71,10 @@ + + + + + +int main (int argc, const char * argv[]) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSLog (@"Hello, World!"); + [pool drain]; + return 0; +} diff --git a/pmd-objectivec/src/test/resources/net/sourceforge/pmd/lang/objc/cpd/testdata/tabWidth.txt b/pmd-objectivec/src/test/resources/net/sourceforge/pmd/lang/objc/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..04ee496964 --- /dev/null +++ b/pmd-objectivec/src/test/resources/net/sourceforge/pmd/lang/objc/cpd/testdata/tabWidth.txt @@ -0,0 +1,49 @@ + [Image] or [Truncated image[ Bcol Ecol +L3 + [int] 1 3 + [main] 5 8 + [(] 10 10 + [int] 11 13 + [argc] 15 18 + [,] 19 19 + [const] 21 25 + [char] 27 30 + [*] 32 32 + [argv] 34 37 + [\[] 38 38 + [\]] 39 39 + [)] 40 40 +L4 + [{] 1 1 +L5 + [NSAutoreleasePool] 2 18 + [*] 20 20 + [pool] 21 24 + [=] 26 26 + [\[] 28 28 + [\[] 29 29 + [NSAutoreleasePool] 30 46 + [alloc] 48 52 + [\]] 53 53 + [init] 55 58 + [\]] 59 59 + [;] 60 60 +L6 + [NSLog] 2 6 + [(] 8 8 + [@"Hello, World!"] 9 24 + [)] 25 25 + [;] 26 26 +L7 + [\[] 2 2 + [pool] 3 6 + [drain] 8 12 + [\]] 13 13 + [;] 14 14 +L8 + [return] 2 7 + [0] 9 9 + [;] 10 10 +L9 + [}] 1 1 +EOF diff --git a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/cpd/testdata/sample-plsql.txt b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/cpd/testdata/sample-plsql.txt index 3dea6a05ad..60e3cf1e3c 100644 --- a/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/cpd/testdata/sample-plsql.txt +++ b/pmd-plsql/src/test/resources/net/sourceforge/pmd/lang/plsql/cpd/testdata/sample-plsql.txt @@ -12,55 +12,55 @@ L3 [IS] 1 2 L19 [pi] 1 2 - [CONSTANT] 17 24 - [NUMBER] 26 31 - [:] 33 33 - [=] 34 34 - [3.1415] 36 41 - [;] 42 42 + [CONSTANT] 5 12 + [NUMBER] 14 19 + [:] 21 21 + [=] 22 22 + [3.1415] 24 29 + [;] 30 30 L20 [c] 1 1 - [CONSTANT] 17 24 - [NUMBER] 26 31 - [:] 33 33 - [=] 34 34 - [3.2e9] 36 40 - [;] 41 41 + [CONSTANT] 5 12 + [NUMBER] 14 19 + [:] 21 21 + [=] 22 22 + [3.2e9] 24 28 + [;] 29 29 L21 [d] 1 1 - [CONSTANT] 17 24 - [NUMBER] 26 31 - [:] 33 33 - [=] 34 34 - [3.2E9] 36 40 - [;] 41 41 + [CONSTANT] 5 12 + [NUMBER] 14 19 + [:] 21 21 + [=] 22 22 + [3.2E9] 24 28 + [;] 29 29 L22 [year_created] 1 12 - [CONSTANT] 17 24 - [NUMBER] 26 31 - [:] 33 33 - [=] 34 34 - [2001] 36 39 - [;] 40 40 + [CONSTANT] 14 21 + [NUMBER] 23 28 + [:] 30 30 + [=] 31 31 + [2001] 33 36 + [;] 37 37 L23 [author] 1 6 - [CONSTANT] 17 24 - [VARCHAR2] 26 33 - [(] 34 34 - [100] 35 37 - [)] 38 38 - [:] 40 40 - [=] 41 41 - ['altumano ''the wolf'''] 43 65 - [;] 66 66 + [CONSTANT] 9 16 + [VARCHAR2] 18 25 + [(] 26 26 + [100] 27 29 + [)] 30 30 + [:] 32 32 + [=] 33 33 + ['altumano ''the wolf'''] 35 57 + [;] 58 58 L24 [date_created] 1 12 - [CONSTANT] 17 24 - [DATE] 26 29 - [:] 31 31 - [=] 32 32 - ['29-oct-01'] 34 44 - [;] 45 45 + [CONSTANT] 15 22 + [DATE] 24 27 + [:] 29 29 + [=] 30 30 + ['29-oct-01'] 32 42 + [;] 43 43 L29 [TYPE] 1 4 [assc_array] 6 15 @@ -215,35 +215,35 @@ L63 [;] 38 38 L66 [current_pi] 1 10 - [NUMBER] 17 22 - [:] 24 24 - [=] 25 25 - [3.1415] 27 32 - [;] 33 33 + [NUMBER] 12 17 + [:] 19 19 + [=] 20 20 + [3.1415] 22 27 + [;] 28 28 L67 [current_year] 1 12 - [NUMBER] 17 22 - [:] 24 24 - [=] 25 25 - [2002] 27 30 - [;] 31 31 + [NUMBER] 14 19 + [:] 21 21 + [=] 22 22 + [2002] 24 27 + [;] 28 28 L68 [current_author] 1 14 - [VARCHAR2] 17 24 - [(] 25 25 - [100] 26 28 - [)] 29 29 - [:] 31 31 - [=] 32 32 - ['\\altumano\\ `the wolf` äöüõç'] 34 62 - [;] 63 63 + [VARCHAR2] 16 23 + [(] 24 24 + [100] 25 27 + [)] 28 28 + [:] 30 30 + [=] 31 31 + ['\\altumano\\ `the wolf` äöüõç'] 33 61 + [;] 62 62 L69 [current_date] 1 12 - [DATE] 17 20 - [:] 22 22 - [=] 23 23 - ['24-feb-02'] 25 35 - [;] 36 36 + [DATE] 15 18 + [:] 20 20 + [=] 21 21 + ['24-feb-02'] 23 33 + [;] 34 34 L72 [cursor] 1 6 [cur1] 8 11 diff --git a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java index 3a58771bc9..254b8cdbe8 100644 --- a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java +++ b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java @@ -41,4 +41,9 @@ public class PythonTokenizerTest extends CpdTextComparisonTest { public void testBackticks() { doTest("backticks"); } + + @Test + public void testTabWidth() { + doTest("tabWidth"); + } } diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.py b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.py new file mode 100644 index 0000000000..75aaad0f52 --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.py @@ -0,0 +1,4 @@ +def hello(): + return 'Hello world' + +print(hello()) diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.txt b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..5f5975d4f5 --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/tabWidth.txt @@ -0,0 +1,18 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [def] 1 3 + [hello] 5 9 + [(] 10 10 + [)] 11 11 + [:] 12 12 +L2 + [return] 2 7 + ['Hello world'] 9 21 +L4 + [print] 1 5 + [(] 6 6 + [hello] 7 11 + [(] 12 12 + [)] 13 13 + [)] 14 14 +EOF diff --git a/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java b/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java index b4398fdf36..e0d40af4f6 100644 --- a/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java +++ b/pmd-ruby/src/test/java/net/sourceforge/pmd/cpd/RubyTokenizerTest.java @@ -31,4 +31,9 @@ public class RubyTokenizerTest extends CpdTextComparisonTest { public void testSimple() { doTest("server"); } + + @Test + public void testTabWidth() { + doTest("tabWidth"); + } } diff --git a/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.rb b/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.rb new file mode 100644 index 0000000000..96a698d4e1 --- /dev/null +++ b/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.rb @@ -0,0 +1,22 @@ +require "socket" + +gs = TCPServer.open(0) +addr = gs.addr +addr.shift + +while true + ns = gs.accept + print(ns, " is accepted") + Thread.start do + s = ns # save to dynamic variable + while s.gets + s.write($_) + end + print(s, " is + gone + and + dead") + s.close + end +end + diff --git a/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.txt b/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..2ad6cba69f --- /dev/null +++ b/pmd-ruby/src/test/resources/net/sourceforge/pmd/lang/ruby/cpd/testdata/tabWidth.txt @@ -0,0 +1,44 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [require] 1 7 + ["socket"] 9 16 +L3 + [gs] 1 2 + [=] 4 4 + [tcpserver.open] 7 20 + [0] 22 22 +L4 + [addr] 1 4 + [=] 7 7 + [gs.addr] 9 15 +L5 + [addr.shift] 1 10 +L7 + [true] 7 10 +L8 + [ns] 2 3 + [=] 5 5 + [gs.accept] 7 15 +L9 + [print] 2 6 + [ns] 8 9 + [" is accepted"] 12 25 +L10 + [thread.start] 2 13 +L11 + [s] 3 3 + [=] 5 5 + [ns] 7 8 + [ # save to dynamic variable] 31 56 +L12 + [s.gets] 9 14 +L13 + [s.write] 4 10 + [$_] 12 13 +L15 + [print] 3 7 + [s] 9 9 + [" is \t\t gone\t\t [ 12 34 +L19 + [s.close] 3 9 +EOF diff --git a/pmd-scala-modules/pmd-scala-common/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java b/pmd-scala-modules/pmd-scala-common/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java index 6e2decfb8b..36865795c5 100644 --- a/pmd-scala-modules/pmd-scala-common/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java +++ b/pmd-scala-modules/pmd-scala-common/src/test/java/net/sourceforge/pmd/cpd/ScalaTokenizerTest.java @@ -41,4 +41,9 @@ public class ScalaTokenizerTest extends CpdTextComparisonTest { ex.expect(TokenMgrError.class); doTest("unlexable_sample"); } + + @Test + public void testTabWidth() { + doTest("tabWidth"); + } } diff --git a/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.scala b/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.scala new file mode 100644 index 0000000000..4016404612 --- /dev/null +++ b/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.scala @@ -0,0 +1,5 @@ +object Main { + def main(args: Array[String]): Unit = { + println("Hello, World!") + } +} diff --git a/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.txt b/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..a8aaf43fce --- /dev/null +++ b/pmd-scala-modules/pmd-scala-common/src/test/resources/net/sourceforge/pmd/lang/scala/cpd/testdata/tabWidth.txt @@ -0,0 +1,30 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [object] 1 7 + [Main] 8 12 + [{] 13 14 +L2 + [def] 2 5 + [main] 6 10 + [(] 10 11 + [args] 11 15 + [:] 15 16 + [Array] 17 22 + [\[] 22 23 + [String] 23 29 + [\]] 29 30 + [)] 30 31 + [:] 31 32 + [Unit] 33 37 + [=] 38 39 + [{] 40 41 +L3 + [println] 3 10 + [(] 10 11 + ["Hello, World!"] 11 26 + [)] 26 27 +L4 + [}] 2 3 +L5 + [}] 1 2 +EOF diff --git a/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java b/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java index 9dbafead40..2533851cbf 100644 --- a/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java +++ b/pmd-swift/src/test/java/net/sourceforge/pmd/cpd/SwiftTokenizerTest.java @@ -51,4 +51,9 @@ public class SwiftTokenizerTest extends CpdTextComparisonTest { public void testStackoverflowOnLongLiteral() { doTest("Issue628"); } + + @Test + public void testTabWidth() { + doTest("tabWidth"); + } } diff --git a/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.swift b/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.swift new file mode 100644 index 0000000000..182d7cfa5c --- /dev/null +++ b/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.swift @@ -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]) diff --git a/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.txt b/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.txt new file mode 100644 index 0000000000..ebb485c79c --- /dev/null +++ b/pmd-swift/src/test/resources/net/sourceforge/pmd/lang/swift/cpd/testdata/tabWidth.txt @@ -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