@@ -440,3 +440,75 @@ test('exotic precision statements', () => {
440
440
. specifier . specifier . token
441
441
) . toBe ( 'sampler2DRectShadow' ) ;
442
442
} ) ;
443
+
444
+ test ( 'warns when grammar stage is unknown' , ( ) => {
445
+ const consoleWarnMock = jest
446
+ . spyOn ( console , 'warn' )
447
+ . mockImplementation ( ( ) => { } ) ;
448
+
449
+ // we don't know if this is vertex or fragment so it should warn
450
+ c . parseSrc ( `
451
+ void main() {
452
+ gl_Position = vec4(0.0);
453
+ }
454
+ ` ) ;
455
+
456
+ expect ( consoleWarnMock ) . toHaveBeenCalled ( ) ;
457
+ consoleWarnMock . mockRestore ( ) ;
458
+ } ) ;
459
+
460
+ test ( 'does not warn on built in stage variable' , ( ) => {
461
+ const consoleWarnMock = jest
462
+ . spyOn ( console , 'warn' )
463
+ . mockImplementation ( ( ) => { } ) ;
464
+
465
+ c . parseSrc (
466
+ `
467
+ void main() {
468
+ gl_Position = vec4(0.0);
469
+ }
470
+ ` ,
471
+ { stage : 'vertex' }
472
+ ) ;
473
+
474
+ expect ( consoleWarnMock ) . not . toHaveBeenCalled ( ) ;
475
+ consoleWarnMock . mockRestore ( ) ;
476
+ } ) ;
477
+
478
+ test ( 'does not warn on built in either stage variable' , ( ) => {
479
+ const consoleWarnMock = jest
480
+ . spyOn ( console , 'warn' )
481
+ . mockImplementation ( ( ) => { } ) ;
482
+
483
+ c . parseSrc (
484
+ `
485
+ void main() {
486
+ gl_Position = vec4(0.0);
487
+ gl_FragColor = vec4(0.0);
488
+ }
489
+ ` ,
490
+ { stage : 'either' }
491
+ ) ;
492
+
493
+ expect ( consoleWarnMock ) . not . toHaveBeenCalled ( ) ;
494
+ consoleWarnMock . mockRestore ( ) ;
495
+ } ) ;
496
+
497
+ test ( 'warn on variable from wrong stage' , ( ) => {
498
+ const consoleWarnMock = jest
499
+ . spyOn ( console , 'warn' )
500
+ . mockImplementation ( ( ) => { } ) ;
501
+
502
+ c . parseSrc (
503
+ `
504
+ void main() {
505
+ gl_Position = vec4(0.0);
506
+ gl_FragColor = vec4(0.0);
507
+ }
508
+ ` ,
509
+ { stage : 'fragment' }
510
+ ) ;
511
+
512
+ expect ( consoleWarnMock ) . toHaveBeenCalled ( ) ;
513
+ consoleWarnMock . mockRestore ( ) ;
514
+ } ) ;
0 commit comments