diff --git a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java index 6b61c658bb..63c9cd5aee 100644 --- a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java +++ b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java @@ -100,6 +100,11 @@ public class CsTokenizerTest extends CpdTextComparisonTest { doTest("listOfNumbers", "_ignored", skipLiteralSequences()); } + @Test + public void testCSharp7And8Additions() { + doTest("csharp7And8Additions"); + } + private Properties ignoreUsings() { return properties(true, false); } diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.cs b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.cs new file mode 100644 index 0000000000..6d14774d75 --- /dev/null +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.cs @@ -0,0 +1,26 @@ +#nullable enable +using System; +using System.Collections.Generic; + +class CSharp7And8Additions +{ + private static void Literals() + { + int x = 30_000_000; // digit separators + int b = 0b00101000; // boolean literal + } + + private static unsafe void DisplaySize() where T : unmanaged // unmanaged keyword + { + Console.WriteLine($"{typeof(T)} is unmanaged and its size is {sizeof(T)} bytes"); + } + + private static void Operators() + { + List? l = null; + (l ??= new List()).Add(5); // null-coalescing assignment operator + + var array = new int[] { 1, 2, 3, 4, 5 }; + var slice1 = array[2..^3]; // range operator + } +} diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.txt b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.txt new file mode 100644 index 0000000000..5d689e8505 --- /dev/null +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/csharp7And8Additions.txt @@ -0,0 +1,155 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [#] 1 1 +L2 + [using] 1 5 + [System] 7 12 + [;] 13 13 +L3 + [using] 1 5 + [System] 7 12 + [.] 13 13 + [Collections] 14 24 + [.] 25 25 + [Generic] 26 32 + [;] 33 33 +L5 + [class] 1 5 + [CSharp7And8Additions] 7 26 +L6 + [{] 1 1 +L7 + [private] 5 11 + [static] 13 18 + [void] 20 23 + [Literals] 25 32 + [(] 33 33 + [)] 34 34 +L8 + [{] 5 5 +L9 + [int] 9 11 + [x] 13 13 + [=] 15 15 + [30_000_000] 17 26 + [;] 27 27 +L10 + [int] 9 11 + [b] 13 13 + [=] 15 15 + [0b00101000] 17 26 + [;] 27 27 +L11 + [}] 5 5 +L13 + [private] 5 11 + [static] 13 18 + [unsafe] 20 25 + [void] 27 30 + [DisplaySize] 32 42 + [<] 43 43 + [T] 44 44 + [>] 45 45 + [(] 46 46 + [)] 47 47 + [where] 49 53 + [T] 55 55 + [:] 57 57 + [unmanaged] 59 67 +L14 + [{] 5 5 +L15 + [Console] 9 15 + [.] 16 16 + [WriteLine] 17 25 + [(] 26 26 + [$"] 27 28 + [typeof] 30 35 + [(] 36 36 + [T] 37 37 + [)] 38 38 + [ is unmanaged and its size is ] 40 69 + [sizeof] 71 76 + [(] 77 77 + [T] 78 78 + [)] 79 79 + [ bytes] 81 86 + ["] 87 87 + [)] 88 88 + [;] 89 89 +L16 + [}] 5 5 +L18 + [private] 5 11 + [static] 13 18 + [void] 20 23 + [Operators] 25 33 + [(] 34 34 + [)] 35 35 +L19 + [{] 5 5 +L20 + [List] 9 12 + [<] 13 13 + [int] 14 16 + [>] 17 17 + [?] 18 18 + [l] 20 20 + [=] 22 22 + [null] 24 27 + [;] 28 28 +L21 + [(] 9 9 + [l] 10 10 + [??=] 12 14 + [new] 16 18 + [List] 20 23 + [<] 24 24 + [int] 25 27 + [>] 28 28 + [(] 29 29 + [)] 30 30 + [)] 31 31 + [.] 32 32 + [Add] 33 35 + [(] 36 36 + [5] 37 37 + [)] 38 38 + [;] 39 39 +L23 + [var] 9 11 + [array] 13 17 + [=] 19 19 + [new] 21 23 + [int] 25 27 + [\[] 28 28 + [\]] 29 29 + [{] 31 31 + [1] 33 33 + [,] 34 34 + [2] 36 36 + [,] 37 37 + [3] 39 39 + [,] 40 40 + [4] 42 42 + [,] 43 43 + [5] 45 45 + [}] 47 47 + [;] 48 48 +L24 + [var] 9 11 + [slice1] 13 18 + [=] 20 20 + [array] 22 26 + [\[] 27 27 + [2] 28 28 + [..] 29 30 + [^] 31 31 + [3] 32 32 + [\]] 33 33 + [;] 34 34 +L25 + [}] 5 5 +L26 + [}] 1 1 +EOF