-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathArrayParseTest.cs
More file actions
64 lines (59 loc) · 2.12 KB
/
ArrayParseTest.cs
File metadata and controls
64 lines (59 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace ConsoleAppFramework.GeneratorTests;
[ClassDataSource<VerifyHelper>]
public class ArrayParseTest(VerifyHelper verifier)
{
[Test]
public async Task Params()
{
var code = """
ConsoleApp.Run(args, (params int[] foo) =>
{
Console.Write("[" + string.Join(", ", foo) + "]");
});
""";
await verifier.Execute(code, args: "--foo", expected: "[]");
await verifier.Execute(code, args: "--foo 10", expected: "[10]");
await verifier.Execute(code, args: "--foo 10 20 30", expected: "[10, 20, 30]");
}
[Test]
public async Task ArgumentParams()
{
var code = """
ConsoleApp.Run(args, ([Argument]string title, [Argument]params int[] foo) =>
{
Console.Write(title + "[" + string.Join(", ", foo) + "]");
});
""";
await verifier.Execute(code, args: "aiueo", expected: "aiueo[]");
await verifier.Execute(code, args: "aiueo 10", expected: "aiueo[10]");
await verifier.Execute(code, args: "aiueo 10 20 30", expected: "aiueo[10, 20, 30]");
}
[Test]
public async Task ParseArray()
{
var code = """
ConsoleApp.Run(args, (int[] ix, string[] sx) =>
{
Console.Write("[" + string.Join(", ", ix) + "]");
Console.Write("[" + string.Join(", ", sx) + "]");
});
""";
await verifier.Execute(code, args: "--ix 1,2,3,4,5 --sx a,b,c,d,e", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
var largeIntArray = string.Join(",", Enumerable.Range(0, 1000));
var expectedIntArray = string.Join(", ", Enumerable.Range(0, 1000));
await verifier.Execute(code, args: $"--ix {largeIntArray} --sx a,b,c,d,e", expected: $"[{expectedIntArray}][a, b, c, d, e]");
}
[Test]
public async Task JsonArray()
{
var code = """
ConsoleApp.Run(args, (int[] ix, string[] sx) =>
{
Console.Write("[" + string.Join(", ", ix) + "]");
Console.Write("[" + string.Join(", ", sx) + "]");
});
""";
await verifier.Execute(code, args: "--ix [] --sx []", expected: "[][]");
await verifier.Execute(code, args: "--ix [1,2,3,4,5] --sx [\"a\",\"b\",\"c\",\"d\",\"e\"]", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
}
}