Add tests for additional C# 7 and C# 8 features

This commit is contained in:
Maikel Steneker
2020-12-18 14:46:24 +01:00
parent 769cf5b316
commit ed8fbccb1c
3 changed files with 186 additions and 0 deletions

View File

@ -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);
}

View File

@ -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<T>() where T : unmanaged // unmanaged keyword
{
Console.WriteLine($"{typeof(T)} is unmanaged and its size is {sizeof(T)} bytes");
}
private static void Operators()
{
List<int>? l = null;
(l ??= new List<int>()).Add(5); // null-coalescing assignment operator
var array = new int[] { 1, 2, 3, 4, 5 };
var slice1 = array[2..^3]; // range operator
}
}

View File

@ -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