@@ -601,7 +601,7 @@ describe 'Go grammar', ->
601
601
testVarDeclaration decl[1 ], ' foo'
602
602
testOpAddress decl[3 ], ' *'
603
603
testOpBracket closing[0 ], ' )'
604
-
604
+
605
605
it ' tokenizes all parts of variable initializations correctly' , ->
606
606
[kwd , decl , init , _ , closing ] = grammar .tokenizeLines ' var (\n\t m = map[string]int{\n\t\t "key": 10,\n\t }\n )'
607
607
testVar kwd[0 ]
@@ -634,3 +634,86 @@ describe 'Go grammar', ->
634
634
testVarAssignment tokens[8 ], ' z'
635
635
testOpAssignment tokens[10 ], ' :='
636
636
testOpTermination tokens[16 ], ' ;'
637
+
638
+
639
+ describe ' testing type highlighting' , ->
640
+ typeCheckers = [
641
+ {
642
+ strToCheck : ' a.A' ,
643
+ expected :
644
+ [{value : ' a' , scope : ' entity.name.package.go' },
645
+ {value : ' .' , scope : ' punctuation.other.period.go' },
646
+ {value : ' A' , scope : ' entity.name.type.go' }]
647
+ },
648
+ {
649
+ strToCheck : ' A' ,
650
+ expected :
651
+ [{value : ' A' , scope : ' entity.name.type.go' }]
652
+ },
653
+ {
654
+ strToCheck : ' []A' ,
655
+ expected :
656
+ [{value : ' [' , scope : ' punctuation.other.bracket.square.go' },
657
+ {value : ' ]' , scope : ' punctuation.other.bracket.square.go' },
658
+ {value : ' A' , scope : ' entity.name.type.go' }]
659
+ },
660
+ {
661
+ strToCheck : ' map[int]B' ,
662
+ expected :
663
+ [{value : ' map' , scope : ' keyword.map.go' },
664
+ {value : ' [' , scope : ' punctuation.other.bracket.square.go' },
665
+ {value : ' int' , scope : ' storage.type.numeric.go' },
666
+ {value : ' ]' , scope : ' punctuation.other.bracket.square.go' },
667
+ {value : ' B' , scope : ' entity.name.type.go' }]
668
+ },
669
+ {
670
+ strToCheck : ' map[B]int' ,
671
+ expected :
672
+ [{value : ' map' , scope : ' keyword.map.go' },
673
+ {value : ' [' , scope : ' punctuation.other.bracket.square.go' },
674
+ {value : ' B' , scope : ' entity.name.type.go' },
675
+ {value : ' ]' , scope : ' punctuation.other.bracket.square.go' },
676
+ {value : ' int' , scope : ' storage.type.numeric.go' }]
677
+ },
678
+ ]
679
+ testValueAndScope = (token , expected ) ->
680
+ expect (token .value ).toBe expected .value
681
+ expect (token .scopes ).toEqual [' source.go' , expected .scope ]
682
+ verifyInit = (offset , expected , tokens ) ->
683
+ for i in [0 .. expected .length - 1 ]
684
+ console .log tokens[i], expected[i]
685
+ testValueAndScope tokens[i+ offset], expected[i]
686
+ describe ' in initialization statements' , ->
687
+ describe ' in initialize statements with curly braces ' , ->
688
+ it ' tokenizes the package, type and puctuation' , ->
689
+ for checker in typeCheckers
690
+ {tokens } = grammar .tokenizeLine checker .strToCheck + ' {'
691
+ verifyInit 0 , checker .expected , tokens
692
+ testValueAndScope tokens[checker .expected .length ], {value : ' {' , scope : ' punctuation.other.bracket.curly.go' }
693
+ describe ' in initialize statements with make' , ->
694
+ toTest = typeCheckers .concat [{
695
+ strToCheck : ' string' ,
696
+ expected :
697
+ [{value : ' string' , scope : ' storage.type.string.go' }]
698
+ },
699
+ {
700
+ strToCheck : ' chan <- A' ,
701
+ expected :
702
+ [{value : ' chan' , scope : ' entity.name.type.go' },
703
+ {value : ' <-' , scope : ' entity.name.type.go' },
704
+ {value : ' A' , scope : ' entity.name.type.go' }]
705
+ }]
706
+ it ' tokenizes the package, type and puctuation in simple make statemnt' , ->
707
+ for checker in typeCheckers
708
+ {tokens } = grammar .tokenizeLine ' make(' + checker .strToCheck + ' )'
709
+ verifyInit 2 , checker .expected , tokens
710
+ testValueAndScope tokens[0 ], {value : ' make' , scope : ' support.function.builtin.go' }
711
+ testValueAndScope tokens[1 ], {value : ' (' , scope : ' punctuation.other.bracket.round.go' }
712
+ testValueAndScope tokens[2 + checker .expected .length ], {value : ' )' , scope : ' punctuation.other.bracket.round.go' }
713
+ it ' tokenizes the package, type and puctuation in a non-simple make statemnt' , ->
714
+ for checker in typeCheckers
715
+ {tokens } = grammar .tokenizeLine ' make(' + checker .strToCheck + ' ,'
716
+ verifyInit 2 , checker .expected , tokens
717
+ testValueAndScope tokens[0 ], {value : ' make' , scope : ' support.function.builtin.go' }
718
+ testValueAndScope tokens[1 ], {value : ' (' , scope : ' punctuation.other.bracket.round.go' }
719
+ testValueAndScope tokens[2 + checker .expected .length ], {value : ' ,' , scope : ' punctuation.other.comma.go' }
0 commit comments