@@ -42,6 +42,11 @@ describe('parse', () => {
42
42
expect ( ( ) => {
43
43
return parse ( '{ ...on }' ) ;
44
44
} ) . toThrow ( ) ;
45
+ // But does accept "oN"
46
+ expect ( parse ( '{ ...oN }' ) ) . toHaveProperty (
47
+ 'definitions.0.selectionSet.selections.0.name.value' ,
48
+ 'oN'
49
+ ) ;
45
50
} ) ;
46
51
47
52
it ( 'parses directives on fragment spread' , ( ) => {
@@ -123,6 +128,16 @@ describe('parse', () => {
123
128
} ) . not . toThrow ( ) ;
124
129
} ) ;
125
130
131
+ it ( 'throws on invalid operations' , ( ) => {
132
+ expect ( ( ) => {
133
+ return parse ( `
134
+ invalid {
135
+ field
136
+ }
137
+ ` ) ;
138
+ } ) . toThrow ( ) ;
139
+ } ) ;
140
+
126
141
it ( 'parses named mutation operations' , ( ) => {
127
142
expect ( ( ) => {
128
143
return parse ( `
@@ -255,6 +270,7 @@ describe('parse', () => {
255
270
expect ( ( ) => parse ( '{ ... on Test }' ) ) . toThrow ( ) ;
256
271
expect ( ( ) => parse ( '{ ... {} }' ) ) . toThrow ( ) ;
257
272
expect ( ( ) => parse ( '{ ... }' ) ) . toThrow ( ) ;
273
+ expect ( ( ) => parse ( '{ . }' ) ) . toThrow ( ) ;
258
274
259
275
expect ( parse ( '{ ... on Test { field } }' ) ) . toHaveProperty (
260
276
'definitions.0.selectionSet.selections.0' ,
@@ -497,6 +513,19 @@ describe('parseValue', () => {
497
513
expect ( parseValue ( { body : 'null' } ) ) . toEqual ( { kind : Kind . NULL } ) ;
498
514
} ) ;
499
515
516
+ it ( 'parses scalars' , ( ) => {
517
+ expect ( parseValue ( 'null' ) ) . toEqual ( { kind : Kind . NULL } ) ;
518
+ expect ( parseValue ( 'true' ) ) . toEqual ( { kind : Kind . BOOLEAN , value : true } ) ;
519
+ expect ( parseValue ( 'false' ) ) . toEqual ( { kind : Kind . BOOLEAN , value : false } ) ;
520
+ } ) ;
521
+
522
+ it ( 'parses scalars without optimistic failures' , ( ) => {
523
+ // for *n*ull, *f*alse, *t*rue
524
+ expect ( parseValue ( 'n' ) ) . toEqual ( { kind : Kind . ENUM , value : 'n' } ) ;
525
+ expect ( parseValue ( 'f' ) ) . toEqual ( { kind : Kind . ENUM , value : 'f' } ) ;
526
+ expect ( parseValue ( 't' ) ) . toEqual ( { kind : Kind . ENUM , value : 't' } ) ;
527
+ } ) ;
528
+
500
529
it ( 'parses list values' , ( ) => {
501
530
const result = parseValue ( '[123 "abc"]' ) ;
502
531
expect ( result ) . toEqual ( {
@@ -542,6 +571,8 @@ describe('parseValue', () => {
542
571
kind : Kind . FLOAT ,
543
572
value : '-1.2e+3' ,
544
573
} ) ;
574
+
575
+ expect ( ( ) => parseValue ( '12e' ) ) . toThrow ( ) ;
545
576
} ) ;
546
577
547
578
it ( 'parses strings' , ( ) => {
@@ -580,6 +611,10 @@ describe('parseValue', () => {
580
611
value : ' " ' ,
581
612
block : false ,
582
613
} ) ;
614
+
615
+ expect ( ( ) => parseValue ( '"' ) ) . toThrow ( ) ;
616
+ expect ( ( ) => parseValue ( '"\n' ) ) . toThrow ( ) ;
617
+ expect ( ( ) => parseValue ( '"\r' ) ) . toThrow ( ) ;
583
618
} ) ;
584
619
585
620
it ( 'parses objects' , ( ) => {
@@ -674,6 +709,8 @@ describe('parseValue', () => {
674
709
value : ' """ ' ,
675
710
block : true ,
676
711
} ) ;
712
+
713
+ expect ( ( ) => parseValue ( '"""' ) ) . toThrow ( ) ;
677
714
} ) ;
678
715
679
716
it ( 'allows variables' , ( ) => {
0 commit comments