@@ -7,62 +7,34 @@ namespace GqlPlus.Sample;
7
7
8
8
public class ParseSchemaTests (
9
9
ISchemaParseChecks checks
10
- ) : TestSchemaInputs
11
-
10
+ ) : TestSchemaResult ( checks )
12
11
{
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 = "" )
29
13
{
30
- string schema = await ReadSchema ( testName , testDirectory ) ;
14
+ if ( string . IsNullOrWhiteSpace ( section ) ) {
15
+ IGqlpSchema ast = result . Required ( ) ;
31
16
32
- await ParseInput_Invalid ( schema , testDirectory , testName ) ;
33
- }
17
+ await CheckErrors ( dirs , test , ast . Errors ) ;
34
18
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 ;
38
22
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
+ }
43
26
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
+ }
54
29
}
55
30
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 = "" )
57
32
{
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 } ) ) ;
62
36
}
63
37
64
- parse . IsOk ( ) . ShouldBeTrue ( test ) ;
65
-
66
- return Task . CompletedTask ;
38
+ await CheckErrors ( dirs , test , errors ) ;
67
39
}
68
40
}
0 commit comments