11/// <reference path="..\..\..\..\src\harness\external\mocha.d.ts" />
22/// <reference path="..\..\..\..\src\harness\harnessLanguageService.ts" />
33
4- interface Classification {
5- position : number ;
6- length : number ;
7- class : ts . TokenClass ;
8- }
9-
10- interface ClassiferResult {
11- tuples : Classification [ ] ;
12- finalEndOfLineState : ts . EndOfLineState ;
13- }
14-
154interface ClassificationEntry {
165 value : any ;
17- class : ts . TokenClass ;
6+ classification : ts . TokenClass ;
187}
198
209describe ( 'Colorization' , function ( ) {
21- var mytypescriptLS = new Harness . LanguageService . TypeScriptLS ( ) ;
22- var myclassifier = mytypescriptLS . getClassifier ( ) ;
23-
24- function getLexicalClassifications ( code : string , initialEndOfLineState : ts . EndOfLineState = ts . EndOfLineState . Start ) : ClassiferResult {
25- var classResult = myclassifier . getClassificationsForLine ( code , initialEndOfLineState ) . split ( '\n' ) ;
26- var tuples : Classification [ ] = [ ] ;
27- var i = 0 ;
28- var position = 0 ;
29-
30- for ( ; i < classResult . length - 1 ; i += 2 ) {
31- var t = tuples [ i / 2 ] = {
32- position : position ,
33- length : parseInt ( classResult [ i ] ) ,
34- class : parseInt ( classResult [ i + 1 ] )
35- } ;
36-
37- assert . isTrue ( t . length > 0 , "Result length should be greater than 0, got :" + t . length ) ;
38- position += t . length ;
39- }
40- var finalEndOfLineState = classResult [ classResult . length - 1 ] ;
41-
42- assert . equal ( position , code . length , "Expected cumulative length of all entries to match the length of the source. expected: " + code . length + ", but got: " + position ) ;
43-
44- return {
45- tuples : tuples ,
46- finalEndOfLineState : parseInt ( finalEndOfLineState )
47- } ;
48- }
49-
50- function verifyClassification ( classification : Classification , expectedLength : number , expectedClass : number ) {
51- assert . isNotNull ( classification ) ;
52- assert . equal ( classification . length , expectedLength , "Classification length does not match expected. Expected: " + expectedLength + ", Actual: " + classification . length ) ;
53- assert . equal ( classification . class , expectedClass , "Classification class does not match expected. Expected: " + ts . TokenClass [ expectedClass ] + ", Actual: " + ts . TokenClass [ classification . class ] ) ;
54- }
55-
56- function getEntryAtPosistion ( result : ClassiferResult , position : number ) {
57- for ( var i = 0 , n = result . tuples . length ; i < n ; i ++ ) {
58- if ( result . tuples [ i ] . position === position ) return result . tuples [ i ] ;
10+ // Use the shim adaptor to ensure test coverage of the shim layer for the classifier
11+ var languageServiceAdabtor = new Harness . LanguageService . ShimLanugageServiceAdaptor ( ) ;
12+ var classifier = languageServiceAdabtor . getClassifier ( ) ;
13+
14+ function getEntryAtPosistion ( result : ts . ClassificationResult , position : number ) {
15+ var entryPosition = 0 ;
16+ for ( var i = 0 , n = result . entries . length ; i < n ; i ++ ) {
17+ var entry = result . entries [ i ] ;
18+ if ( entryPosition === position ) {
19+ return entry ;
20+ }
21+ entryPosition += entry . length ;
5922 }
6023 return undefined ;
6124 }
6225
63- function punctuation ( text : string ) { return { value : text , class : ts . TokenClass . Punctuation } ; }
64- function keyword ( text : string ) { return { value : text , class : ts . TokenClass . Keyword } ; }
65- function operator ( text : string ) { return { value : text , class : ts . TokenClass . Operator } ; }
66- function comment ( text : string ) { return { value : text , class : ts . TokenClass . Comment } ; }
67- function whitespace ( text : string ) { return { value : text , class : ts . TokenClass . Whitespace } ; }
68- function identifier ( text : string ) { return { value : text , class : ts . TokenClass . Identifier } ; }
69- function numberLiteral ( text : string ) { return { value : text , class : ts . TokenClass . NumberLiteral } ; }
70- function stringLiteral ( text : string ) { return { value : text , class : ts . TokenClass . StringLiteral } ; }
71- function regExpLiteral ( text : string ) { return { value : text , class : ts . TokenClass . RegExpLiteral } ; }
72- function finalEndOfLineState ( value : number ) { return { value : value , class : < ts . TokenClass > undefined } ; }
26+ function punctuation ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Punctuation } ; }
27+ function keyword ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Keyword } ; }
28+ function operator ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Operator } ; }
29+ function comment ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Comment } ; }
30+ function whitespace ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Whitespace } ; }
31+ function identifier ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . Identifier } ; }
32+ function numberLiteral ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . NumberLiteral } ; }
33+ function stringLiteral ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . StringLiteral } ; }
34+ function regExpLiteral ( text : string ) : ClassificationEntry { return { value : text , classification : ts . TokenClass . RegExpLiteral } ; }
35+ function finalEndOfLineState ( value : number ) : ClassificationEntry { return { value : value , classification : < ts . TokenClass > undefined } ; }
7336
7437 function testLexicalClassification ( text : string , initialEndOfLineState : ts . EndOfLineState , ...expectedEntries : ClassificationEntry [ ] ) : void {
75- var result = getLexicalClassifications ( text , initialEndOfLineState ) ;
38+ var result = classifier . getClassificationsForLine ( text , initialEndOfLineState ) ;
7639
7740 for ( var i = 0 , n = expectedEntries . length ; i < n ; i ++ ) {
7841 var expectedEntry = expectedEntries [ i ] ;
7942
80- if ( expectedEntry . class === undefined ) {
81- assert . equal ( result . finalEndOfLineState , expectedEntry . value , "final endOfLineState does not match expected." ) ;
43+ if ( expectedEntry . classification === undefined ) {
44+ assert . equal ( result . finalLexState , expectedEntry . value , "final endOfLineState does not match expected." ) ;
8245 }
8346 else {
8447 var actualEntryPosition = text . indexOf ( expectedEntry . value ) ;
@@ -87,7 +50,7 @@ describe('Colorization', function () {
8750 var actualEntry = getEntryAtPosistion ( result , actualEntryPosition ) ;
8851
8952 assert ( actualEntry , "Could not find classification entry for '" + expectedEntry . value + "' at position: " + actualEntryPosition ) ;
90- assert . equal ( actualEntry . class , expectedEntry . class , "Classification class does not match expected. Expected: " + ts . TokenClass [ expectedEntry . class ] + ", Actual: " + ts . TokenClass [ actualEntry . class ] ) ;
53+ assert . equal ( actualEntry . classification , expectedEntry . classification , "Classification class does not match expected. Expected: " + ts . TokenClass [ expectedEntry . classification ] + ", Actual: " + ts . TokenClass [ actualEntry . classification ] ) ;
9154 assert . equal ( actualEntry . length , expectedEntry . value . length , "Classification length does not match expected. Expected: " + ts . TokenClass [ expectedEntry . value . length ] + ", Actual: " + ts . TokenClass [ actualEntry . length ] ) ;
9255 }
9356 }
@@ -320,8 +283,6 @@ describe('Colorization', function () {
320283 } ) ;
321284
322285 it ( "LexicallyClassifiesConflictTokens" , ( ) => {
323- debugger ;
324-
325286 // Test conflict markers.
326287 testLexicalClassification (
327288"class C {\r\n\
0 commit comments