@@ -14,8 +14,9 @@ public class ParserTests
14
14
15
15
[ Theory ]
16
16
[ InlineData ( IgnoreOptions . None ) ]
17
- //[InlineData(IgnoreOptions.IgnoreComments)]
18
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
17
+ //[InlineData(IgnoreOptions.Comments)]
18
+ [ InlineData ( IgnoreOptions . Locations ) ]
19
+ //[InlineData(IgnoreOptions.All)]
19
20
public void Extra_Comments_Should_Read_Correctly ( IgnoreOptions options )
20
21
{
21
22
string query = "ExtraComments" . ReadGraphQLFile ( ) ;
@@ -71,9 +72,10 @@ public void Comments_Can_Be_Ignored(IgnoreOptions options)
71
72
72
73
[ Theory ]
73
74
[ InlineData ( IgnoreOptions . None ) ]
74
- //[InlineData(IgnoreOptions.IgnoreComments)]
75
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
76
- public void Comments_on_FragmentSpread_Should_Read_Correclty ( IgnoreOptions options )
75
+ //[InlineData(IgnoreOptions.Comments)]
76
+ [ InlineData ( IgnoreOptions . Locations ) ]
77
+ //[InlineData(IgnoreOptions.All)]
78
+ public void Comments_on_FragmentSpread_Should_Read_Correctly ( IgnoreOptions options )
77
79
{
78
80
string query = "CommentsOnFragmentSpread" . ReadGraphQLFile ( ) ;
79
81
@@ -89,9 +91,55 @@ public void Comments_on_FragmentSpread_Should_Read_Correclty(IgnoreOptions optio
89
91
90
92
[ Theory ]
91
93
[ InlineData ( IgnoreOptions . None ) ]
92
- //[InlineData(IgnoreOptions.IgnoreComments)]
93
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
94
- public void Comments_on_FragmentInline_Should_Read_Correclty ( IgnoreOptions options )
94
+ //[InlineData(IgnoreOptions.Comments)]
95
+ [ InlineData ( IgnoreOptions . Locations ) ]
96
+ //[InlineData(IgnoreOptions.All)]
97
+ public void Comments_on_Values_Should_Read_Correctly ( IgnoreOptions options )
98
+ {
99
+ string query = "CommentsOnValues" . ReadGraphQLFile ( ) ;
100
+
101
+ using var document = query . Parse ( new ParserOptions { Ignore = options } ) ;
102
+ document . Definitions . Count . ShouldBe ( 1 ) ;
103
+ var def = document . Definitions . First ( ) as GraphQLOperationDefinition ;
104
+ def . SelectionSet . Selections . Count . ShouldBe ( 1 ) ;
105
+ var field = def . SelectionSet . Selections . First ( ) as GraphQLFieldSelection ;
106
+ field . SelectionSet . Selections . Count . ShouldBe ( 1 ) ;
107
+ field . Arguments . Count . ShouldBe ( 9 ) ;
108
+
109
+ var boolValue = field . Arguments [ 0 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
110
+ boolValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for bool" ) ;
111
+
112
+ var nullValue = field . Arguments [ 1 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
113
+ nullValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for null" ) ;
114
+
115
+ var enumValue = field . Arguments [ 2 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
116
+ enumValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for enum" ) ;
117
+
118
+ var listValue = field . Arguments [ 3 ] . Value . ShouldBeAssignableTo < GraphQLListValue > ( ) ;
119
+ listValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for list" ) ;
120
+
121
+ var objValue = field . Arguments [ 4 ] . Value . ShouldBeAssignableTo < GraphQLObjectValue > ( ) ;
122
+ objValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for object" ) ;
123
+
124
+ var intValue = field . Arguments [ 5 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
125
+ intValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for int" ) ;
126
+
127
+ var floatValue = field . Arguments [ 6 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
128
+ floatValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for float" ) ;
129
+
130
+ var stringValue = field . Arguments [ 7 ] . Value . ShouldBeAssignableTo < GraphQLScalarValue > ( ) ;
131
+ stringValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for string" ) ;
132
+
133
+ var varValue = field . Arguments [ 8 ] . Value . ShouldBeAssignableTo < GraphQLVariable > ( ) ;
134
+ varValue . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( "comment for variable" ) ;
135
+ }
136
+
137
+ [ Theory ]
138
+ [ InlineData ( IgnoreOptions . None ) ]
139
+ //[InlineData(IgnoreOptions.Comments)]
140
+ [ InlineData ( IgnoreOptions . Locations ) ]
141
+ //[InlineData(IgnoreOptions.All)]
142
+ public void Comments_on_FragmentInline_Should_Read_Correctly ( IgnoreOptions options )
95
143
{
96
144
string query = "CommentsOnInlineFragment" . ReadGraphQLFile ( ) ;
97
145
@@ -107,9 +155,10 @@ public void Comments_on_FragmentInline_Should_Read_Correclty(IgnoreOptions optio
107
155
108
156
[ Theory ]
109
157
[ InlineData ( IgnoreOptions . None ) ]
110
- //[InlineData(IgnoreOptions.IgnoreComments)]
111
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
112
- public void Comments_on_Variable_Should_Read_Correclty ( IgnoreOptions options )
158
+ //[InlineData(IgnoreOptions.Comments)]
159
+ [ InlineData ( IgnoreOptions . Locations ) ]
160
+ //[InlineData(IgnoreOptions.All)]
161
+ public void Comments_on_Variable_Should_Read_Correctly ( IgnoreOptions options )
113
162
{
114
163
string query = "CommentsOnVariables" . ReadGraphQLFile ( ) ;
115
164
@@ -124,8 +173,9 @@ public void Comments_on_Variable_Should_Read_Correclty(IgnoreOptions options)
124
173
125
174
[ Theory ]
126
175
[ InlineData ( IgnoreOptions . None ) ]
127
- //[InlineData(IgnoreOptions.IgnoreComments)]
128
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
176
+ //[InlineData(IgnoreOptions.Comments)]
177
+ [ InlineData ( IgnoreOptions . Locations ) ]
178
+ //[InlineData(IgnoreOptions.All)]
129
179
public void Comments_On_SelectionSet_Should_Read_Correctly ( IgnoreOptions options )
130
180
{
131
181
using var document = @"
@@ -147,9 +197,10 @@ public void Comments_On_SelectionSet_Should_Read_Correctly(IgnoreOptions options
147
197
148
198
[ Theory ]
149
199
[ InlineData ( IgnoreOptions . None ) ]
150
- //[InlineData(IgnoreOptions.IgnoreComments)]
151
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
152
- public void Comments_On_Enums_Should_Read_Correctly ( IgnoreOptions options )
200
+ //[InlineData(IgnoreOptions.Comments)]
201
+ [ InlineData ( IgnoreOptions . Locations ) ]
202
+ //[InlineData(IgnoreOptions.All)]
203
+ public void Comments_On_Enum_Definitions_Should_Read_Correctly ( IgnoreOptions options )
153
204
{
154
205
using var document = @"
155
206
# different animals
@@ -352,20 +403,31 @@ public void Parse_FieldWithOperationTypeAndNameInput_SelectionSetContainsSingleF
352
403
353
404
[ Theory ]
354
405
[ InlineData ( IgnoreOptions . None ) ]
355
- //[InlineData(IgnoreOptions.IgnoreComments)]
356
- //[InlineData(IgnoreOptions.IgnoreCommentsAndLocations)]
406
+ [ InlineData ( IgnoreOptions . Comments ) ]
407
+ [ InlineData ( IgnoreOptions . Locations ) ]
408
+ [ InlineData ( IgnoreOptions . All ) ]
357
409
public void Parse_KitchenSink_DoesNotThrowError ( IgnoreOptions options )
358
410
{
359
411
using var document = "KitchenSink" . ReadGraphQLFile ( ) . Parse ( new ParserOptions { Ignore = options } ) ;
360
412
var typeDef = document . Definitions . OfType < GraphQLObjectTypeDefinition > ( ) . First ( d => d . Name . Value == "Foo" ) ;
361
413
var fieldDef = typeDef . Fields . First ( d => d . Name . Value == "three" ) ;
362
- fieldDef . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( $ " multiline comments{ _nl } with very importand description #{ _nl } # and symbol # and ##") ;
414
+ if ( options . HasFlag ( IgnoreOptions . Comments ) )
415
+ fieldDef . Comment . ShouldBeNull ( ) ;
416
+ else
417
+ fieldDef . Comment . ShouldNotBeNull ( ) . Text . ShouldBe ( $ " multiline comments{ _nl } with very importand description #{ _nl } # and symbol # and ##") ;
363
418
364
419
// Schema description
365
420
// https://github.com/graphql/graphql-spec/pull/466
366
421
var comment = document . Definitions . OfType < GraphQLSchemaDefinition > ( ) . First ( ) . Comment ;
367
- comment . ShouldNotBeNull ( ) ;
368
- ( ( string ) comment . Text ) . StartsWith ( " Copyright (c) 2015, Facebook, Inc." ) . ShouldBeTrue ( ) ;
422
+ if ( options . HasFlag ( IgnoreOptions . Comments ) )
423
+ {
424
+ comment . ShouldBeNull ( ) ;
425
+ }
426
+ else
427
+ {
428
+ comment . ShouldNotBeNull ( ) ;
429
+ ( ( string ) comment . Text ) . StartsWith ( " Copyright (c) 2015, Facebook, Inc." ) . ShouldBeTrue ( ) ;
430
+ }
369
431
}
370
432
371
433
[ Theory ]
@@ -777,7 +839,7 @@ directive @TestDirective (
777
839
" . Parse ( new ParserOptions { Ignore = options } ) ;
778
840
var defs = document . Definitions ;
779
841
defs . Count . ShouldBe ( 8 ) ;
780
- var parseComments = options == IgnoreOptions . None ;
842
+ var parseComments = ! options . HasFlag ( IgnoreOptions . Comments ) ;
781
843
782
844
var schemaDef = defs . Single ( x => x is GraphQLSchemaDefinition ) as GraphQLSchemaDefinition ;
783
845
schemaDef . Description . Value . ShouldBe ( "Super schema" ) ;
@@ -961,7 +1023,7 @@ directive @TestDirective (
961
1023
" . Parse ( new ParserOptions { Ignore = options } ) ;
962
1024
var defs = document . Definitions ;
963
1025
defs . Count . ShouldBe ( 8 ) ;
964
- var parseComments = options == IgnoreOptions . None ;
1026
+ var parseComments = ! options . HasFlag ( IgnoreOptions . Comments ) ;
965
1027
966
1028
var schemaDef = defs . Single ( x => x is GraphQLSchemaDefinition ) as GraphQLSchemaDefinition ;
967
1029
schemaDef . Description . Value . ShouldBe ( "Super schema" ) ;
@@ -1145,7 +1207,7 @@ directive @TestDirective (
1145
1207
" . Parse ( new ParserOptions { Ignore = options } ) ;
1146
1208
var defs = document . Definitions ;
1147
1209
defs . Count . ShouldBe ( 8 ) ;
1148
- var parseComments = options == IgnoreOptions . None ;
1210
+ var parseComments = ! options . HasFlag ( IgnoreOptions . Comments ) ;
1149
1211
1150
1212
var schemaDef = defs . Single ( x => x is GraphQLSchemaDefinition ) as GraphQLSchemaDefinition ;
1151
1213
schemaDef . Description . Value . ShouldBe ( "Super schema" ) ;
0 commit comments