Skip to content

Commit cdf3d60

Browse files
committed
Refactor Invalid Sample tests
1 parent 967190b commit cdf3d60

File tree

48 files changed

+96
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+96
-101
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
enum Test [a] { test }
2+
enum Dup [a] { dup }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Multiple Enums with alias 'a' found. Names 'Test' 'Dup'
2+
Multiple Types with alias 'a' found. Names 'Test' 'Dup'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Duals with name 'Test' can't be merged
2+
Group of DualField for 'field' is not singular ModifiedType['Test', 'Test []']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Inputs with name 'Test' can't be merged
2+
Group of InputField for 'field' is not singular ModifiedType['Test', 'Test []']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Outputs with name 'Test' can't be merged
2+
Group of OutputField for 'field' is not singular ModifiedType['Test', 'Test []']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
object Test { field: Test }
2+
object Test { field: Test[] }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Duals with name 'Test' can't be merged
2+
Group of DualField for 'field' is not singular ModifiedType['Test', 'Test1']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Inputs with name 'Test' can't be merged
2+
Group of InputField for 'field' is not singular ModifiedType['Test', 'Test1']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Multiple Outputs with name 'Test' can't be merged
2+
Group of OutputField for 'field' is not singular ModifiedType['Test', 'Test1']
3+
Multiple Types with name 'Test' can't be merged
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test { field: Test }
2+
object Test { field: Test1 }
3+
object Test1 { }

Diff for: test/GqlPlus.ComponentTestBase/Samples/Schema/Objects/Invalid/option-diff-name.verify-errors

-1
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8a86bba (HEAD -> yaml) 2025-04-06 Correct verify errors
1+
9f81ed8 (HEAD -> refactor-component-parse-tests) 2025-04-11 Move Invalid Merge samples to samples/Merges/Invalid

Diff for: test/GqlPlus.ComponentTestBase/TestSchemaAsts.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ protected override async Task Label_Inputs(string label, IEnumerable<string> inp
1818
{
1919
IEnumerable<IGqlpSchema> asts = inputs.Select(input => checks.ParseInput(input, label));
2020

21-
await Test_Asts(asts, test, label);
21+
await Test_Asts(asts, test, label, [label], "");
2222
}
2323

24-
protected virtual Task Test_Asts(IEnumerable<IGqlpSchema> asts, string test, string label, string[]? dirs = null)
25-
=> Test_Asts(asts, test, label, dirs ?? [label], "");
26-
2724
protected abstract Task Test_Asts(IEnumerable<IGqlpSchema> asts, string test, string label, string[] dirs, string section, string input = "");
2825
}

Diff for: test/GqlPlus.ComponentTestBase/TestSchemaResult.cs

+28-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@ public abstract class TestSchemaResult(
77
ISchemaParseChecks checks
88
) : TestSchemaInputs
99
{
10+
[Theory]
11+
[ClassData(typeof(SamplesSchemaMergesInvalidData))]
12+
public async Task Test_MergesInvalid(string model)
13+
=> await ReplaceFileAsync("Merges/Invalid", model, SampleInvalid_Input);
14+
15+
[Theory]
16+
[ClassData(typeof(SamplesSchemaObjectsInvalidData))]
17+
public async Task Test_ObjectsInvalid(string model)
18+
=> await ReplaceFileAsync("Objects/Invalid", model, SampleInvalid_Input);
19+
20+
[Theory]
21+
[ClassData(typeof(SamplesSchemaGlobalsInvalidData))]
22+
public async Task Test_GlobalsInvalid(string global)
23+
=> await ReplaceFileAsync("Globals/Invalid", global, SampleInvalid_Input);
24+
25+
[Theory]
26+
[ClassData(typeof(SamplesSchemaSimpleInvalidData))]
27+
public async Task Test_SimpleInvalid(string simple)
28+
=> await ReplaceFileAsync("Simple/Invalid", simple, SampleInvalid_Input);
29+
30+
protected virtual async Task SampleInvalid_Input(string input, string section, string test)
31+
{
32+
IResult<IGqlpSchema> parse = checks.Parse(input, "Schema");
33+
34+
await Result_Invalid(parse, test, "Sample", ["Schema", section], test, section);
35+
}
36+
1037
protected override async Task Label_Input(string label, string input, string[] dirs, string test, string section)
1138
{
1239
IResult<IGqlpSchema> result = checks.Parse(input, label);
@@ -17,6 +44,6 @@ protected override async Task Label_Input(string label, string input, string[] d
1744
protected override Task Label_Inputs(string label, IEnumerable<string> inputs, string test)
1845
=> base.Label_Inputs(label, inputs, test);
1946

20-
2147
protected abstract Task Result_Valid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "");
48+
protected abstract Task Result_Invalid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "");
2249
}

Diff for: test/GqlPlus.Modeller.ComponentTestBase/SchemaVerifyChecks.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using GqlPlus.Abstractions.Schema;
2-
using GqlPlus.Convert;
32
using GqlPlus.Merging;
43
using GqlPlus.Parsing;
54
using GqlPlus.Resolving;

Diff for: test/GqlPlus.Modeller.ComponentTestBase/TestSchemaVerify.cs

-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
using GqlPlus.Abstractions;
22
using GqlPlus.Abstractions.Schema;
33
using GqlPlus.Resolving;
4-
using Shouldly;
54

65
namespace GqlPlus;
76

87
public abstract class TestSchemaVerify(
98
ISchemaVerifyChecks checks
109
) : TestSchemaAsts(checks)
1110
{
12-
protected override async Task Test_Asts(IEnumerable<IGqlpSchema> asts, string test, string label, string[]? dirs = null)
13-
{
14-
(Structured result, ITypesContext context) = checks.Verify_Asts(asts);
15-
16-
await VerifyResult(result, label, test, "");
17-
18-
await CheckResultErrors(dirs ?? [label], test, context.Errors);
19-
}
20-
2111
protected override async Task Test_Asts(IEnumerable<IGqlpSchema> asts, string test, string label, string[] dirs, string section, string input = "")
2212
{
2313
(Structured result, ITypesContext context) = checks.Verify_Asts(asts);

Diff for: test/GqlPlus.Parser.ComponentTests/Sample/CanMergeSchemaTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ private void Check_CanMerge(IGqlpSchema[] schemas, string test)
3131

3232
result.ShouldBeEmpty(test);
3333
}
34+
35+
// Todo: Add error checking for invalid schemas
36+
protected override Task Result_Invalid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
37+
=> Task.CompletedTask;
3438
}

Diff for: test/GqlPlus.Parser.ComponentTests/Sample/MergeSchemaTests.cs

+4
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ private async Task Check_Merge(IGqlpSchema[] schemas, string test, string label,
2525

2626
await Verify(result.Select(s => s.Show()), CustomSettings(label, "Merge", test, section));
2727
}
28+
29+
// Todo: Add error checking for invalid schemas
30+
protected override Task Result_Invalid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
31+
=> Task.CompletedTask;
2832
}

Diff for: test/GqlPlus.Parser.ComponentTests/Sample/ParseSchemaTests.cs

+18-46
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,34 @@ namespace GqlPlus.Sample;
77

88
public class ParseSchemaTests(
99
ISchemaParseChecks checks
10-
) : TestSchemaInputs
11-
10+
) : TestSchemaResult(checks)
1211
{
13-
[Theory]
14-
[ClassData(typeof(SamplesSchemaGlobalsInvalidData))]
15-
public async Task Parse_GlobalsInvalid(string global)
16-
=> await ParseFile_Invalid("Globals/Invalid", global);
17-
18-
[Theory]
19-
[ClassData(typeof(SamplesSchemaSimpleInvalidData))]
20-
public async Task Parse_SimpleInvalid(string simple)
21-
=> await ParseFile_Invalid("Simple/Invalid", simple);
22-
23-
[Theory]
24-
[ClassData(typeof(SamplesSchemaObjectsInvalidData))]
25-
public async Task Parse_ObjectsInvalid(string obj)
26-
=> await ReplaceFileAsync("Objects/Invalid", obj, ParseInput_Invalid);
27-
28-
private async Task ParseFile_Invalid(string testDirectory, string testName)
12+
protected override async Task Result_Valid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
2913
{
30-
string schema = await ReadSchema(testName, testDirectory);
14+
if (string.IsNullOrWhiteSpace(section)) {
15+
IGqlpSchema ast = result.Required();
3116

32-
await ParseInput_Invalid(schema, testDirectory, testName);
33-
}
17+
await CheckErrors(dirs, test, ast.Errors);
3418

35-
private async Task ParseInput_Invalid(string input, string testDirectory, string test)
36-
{
37-
IResult<IGqlpSchema> parse = checks.Parse(input, "Schema");
19+
await Verify(ast.Show(), CustomSettings(label, "Parse", test));
20+
} else {
21+
string testName = section + " " + test;
3822

39-
TokenMessages result = [];
40-
if (!parse.IsOk()) {
41-
parse.IsError(e => result.Add(e with { Message = "Parse Error: " + e.Message }));
42-
}
23+
if (result is IResultError<SchemaAst> error) {
24+
error.Message.ShouldBeNull(testName);
25+
}
4326

44-
await CheckErrors(["Schema", testDirectory], test, result);
45-
}
46-
47-
protected override async Task Label_Input(string label, string input, string[] dirs, string test, string section = "")
48-
{
49-
IGqlpSchema ast = checks.ParseInput(input, label);
50-
51-
await CheckErrors(dirs, test, ast.Errors);
52-
53-
await Verify(ast.Show(), CustomSettings(label, "Parse", test, section));
27+
result.IsOk().ShouldBeTrue(testName);
28+
}
5429
}
5530

56-
protected override Task Sample_Input(string input, string section, string test)
31+
protected override async Task Result_Invalid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
5732
{
58-
IResult<IGqlpSchema> parse = checks.Parse(input, "Schema");
59-
60-
if (parse is IResultError<SchemaAst> error) {
61-
error.Message.ShouldBeNull(test);
33+
TokenMessages errors = [];
34+
if (!result.IsOk()) {
35+
result.IsError(e => errors.Add(e with { Message = "Parse Error: " + e.Message }));
6236
}
6337

64-
parse.IsOk().ShouldBeTrue(test);
65-
66-
return Task.CompletedTask;
38+
await CheckErrors(dirs, test, errors);
6739
}
6840
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using GqlPlus.Abstractions.Schema;
22
using GqlPlus.Ast.Schema;
3-
using GqlPlus.Parsing;
43
using GqlPlus.Result;
54
using GqlPlus.Token;
65
using GqlPlus.Verifying;
@@ -13,42 +12,6 @@ IVerify<IGqlpSchema> schemaVerifier
1312
) : TestSchemaResult(checks)
1413

1514
{
16-
[Theory]
17-
[ClassData(typeof(SamplesSchemaGlobalsInvalidData))]
18-
public async Task Verify_GlobalsInvalid(string global)
19-
=> await VerifyFile_Invalid("Globals/Invalid", global);
20-
21-
[Theory]
22-
[ClassData(typeof(SamplesSchemaSimpleInvalidData))]
23-
public async Task Verify_SimpleInvalid(string simple)
24-
=> await VerifyFile_Invalid("Simple/Invalid", simple);
25-
26-
[Theory]
27-
[ClassData(typeof(SamplesSchemaObjectsInvalidData))]
28-
public async Task Verify_ObjectsInvalid(string obj)
29-
=> await ReplaceFileAsync("Objects/Invalid", obj, VerifyInput_Invalid);
30-
31-
private async Task VerifyFile_Invalid(string testDirectory, string testName)
32-
{
33-
string schema = await ReadSchema(testName, testDirectory);
34-
35-
await VerifyInput_Invalid(schema, testDirectory, testName);
36-
}
37-
38-
private async Task VerifyInput_Invalid(string input, string testDirectory, string test)
39-
{
40-
IResult<IGqlpSchema> parse = checks.Parse(input, "Schema");
41-
42-
TokenMessages result = [];
43-
if (parse.IsOk()) {
44-
schemaVerifier.Verify(parse.Required(), result);
45-
} else {
46-
parse.IsError(e => result.Add(e with { Message = "Parse Error: " + e.Message }));
47-
}
48-
49-
await CheckErrors(["Schema", testDirectory], test, result, true);
50-
}
51-
5215
protected override async Task Result_Valid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
5316
{
5417
if (result is IResultError<SchemaAst> error) {
@@ -65,4 +28,17 @@ protected override async Task Result_Valid(IResult<IGqlpSchema> result, string t
6528
await CheckErrors(dirs, test, errors, true);
6629
}
6730
}
31+
32+
protected override async Task Result_Invalid(IResult<IGqlpSchema> result, string test, string label, string[] dirs, string section, string input = "")
33+
{
34+
35+
TokenMessages errors = [];
36+
if (result.IsOk()) {
37+
schemaVerifier.Verify(result.Required(), errors);
38+
} else {
39+
result.IsError(e => errors.Add(e with { Message = "Parse Error: " + e.Message }));
40+
}
41+
42+
await CheckErrors(dirs, test, errors, true);
43+
}
6844
}

0 commit comments

Comments
 (0)