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