@@ -84,31 +84,36 @@ suite('SemanticHighlighting Tests', () => {
84
84
return scopeRanges ;
85
85
} ;
86
86
87
+ const fileUri1 = vscode . Uri . parse ( 'file:///file1' ) ;
88
+ const fileUri2 = vscode . Uri . parse ( 'file:///file2' ) ;
89
+ const fileUri1Str = fileUri1 . toString ( ) ;
90
+ const fileUri2Str = fileUri2 . toString ( ) ;
91
+
87
92
class MockHighlighter extends semanticHighlighting . Highlighter {
88
93
applicationUriHistory : string [ ] = [ ] ;
89
94
// Override to make the highlighting calls accessible to the test. Also
90
95
// makes the test not depend on visible text editors.
91
- applyHighlights ( fileUri : string ) {
92
- this . applicationUriHistory . push ( fileUri ) ;
96
+ applyHighlights ( fileUri : vscode . Uri ) {
97
+ this . applicationUriHistory . push ( fileUri . toString ( ) ) ;
93
98
}
94
99
// Override to make it accessible from the test.
95
- getDecorationRanges ( fileUri : string ) {
100
+ getDecorationRanges ( fileUri : vscode . Uri ) {
96
101
return super . getDecorationRanges ( fileUri ) ;
97
102
}
98
103
// Override to make tests not depend on visible text editors.
99
- getVisibleTextEditorUris ( ) { return [ 'file1' , 'file2' ] ; }
104
+ getVisibleTextEditorUris ( ) { return [ fileUri1 , fileUri2 ] ; }
100
105
}
101
106
const highlighter = new MockHighlighter ( scopeTable ) ;
102
107
const tm = new semanticHighlighting . ThemeRuleMatcher ( [
103
108
{ scope : 'variable' , foreground : '1' } ,
104
109
{ scope : 'entity.type' , foreground : '2' } ,
105
110
] ) ;
106
111
// Recolorizes when initialized.
107
- highlighter . highlight ( 'file1' , [ ] ) ;
108
- assert . deepEqual ( highlighter . applicationUriHistory , [ 'file1' ] ) ;
112
+ highlighter . highlight ( fileUri1 , [ ] ) ;
113
+ assert . deepEqual ( highlighter . applicationUriHistory , [ fileUri1Str ] ) ;
109
114
highlighter . initialize ( tm ) ;
110
115
assert . deepEqual ( highlighter . applicationUriHistory ,
111
- [ 'file1' , 'file1' , 'file2' ] ) ;
116
+ [ fileUri1Str , fileUri1Str , fileUri2Str ] ) ;
112
117
// Groups decorations into the scopes used.
113
118
let highlightingsInLine : semanticHighlighting . SemanticHighlightingLine [ ] = [
114
119
{
@@ -128,10 +133,10 @@ suite('SemanticHighlighting Tests', () => {
128
133
} ,
129
134
] ;
130
135
131
- highlighter . highlight ( 'file1' , highlightingsInLine ) ;
136
+ highlighter . highlight ( fileUri1 , highlightingsInLine ) ;
132
137
assert . deepEqual ( highlighter . applicationUriHistory ,
133
- [ 'file1' , 'file1' , 'file2' , 'file1' ] ) ;
134
- assert . deepEqual ( highlighter . getDecorationRanges ( 'file1' ) ,
138
+ [ fileUri1Str , fileUri1Str , fileUri2Str , fileUri1Str ] ) ;
139
+ assert . deepEqual ( highlighter . getDecorationRanges ( fileUri1 ) ,
135
140
createHighlightingScopeRanges ( highlightingsInLine ) ) ;
136
141
// Keeps state separate between files.
137
142
const highlightingsInLine1 :
@@ -141,26 +146,29 @@ suite('SemanticHighlighting Tests', () => {
141
146
{ character : 2 , length : 1 , scopeIndex : 0 } ,
142
147
]
143
148
} ;
144
- highlighter . highlight ( 'file2' , [ highlightingsInLine1 ] ) ;
145
- assert . deepEqual ( highlighter . applicationUriHistory ,
146
- [ 'file1' , 'file1' , 'file2' , 'file1' , 'file2' ] ) ;
147
- assert . deepEqual ( highlighter . getDecorationRanges ( 'file2' ) ,
149
+ highlighter . highlight ( fileUri2 , [ highlightingsInLine1 ] ) ;
150
+ assert . deepEqual (
151
+ highlighter . applicationUriHistory ,
152
+ [ fileUri1Str , fileUri1Str , fileUri2Str , fileUri1Str , fileUri2Str ] ) ;
153
+ assert . deepEqual ( highlighter . getDecorationRanges ( fileUri2 ) ,
148
154
createHighlightingScopeRanges ( [ highlightingsInLine1 ] ) ) ;
149
155
// Does full colorizations.
150
- highlighter . highlight ( 'file1' , [ highlightingsInLine1 ] ) ;
151
- assert . deepEqual ( highlighter . applicationUriHistory ,
152
- [ 'file1' , 'file1' , 'file2' , 'file1' , 'file2' , 'file1' ] ) ;
156
+ highlighter . highlight ( fileUri1 , [ highlightingsInLine1 ] ) ;
157
+ assert . deepEqual ( highlighter . applicationUriHistory , [
158
+ fileUri1Str , fileUri1Str , fileUri2Str , fileUri1Str , fileUri2Str ,
159
+ fileUri1Str
160
+ ] ) ;
153
161
// After the incremental update to line 1, the old highlightings at line 1
154
162
// will no longer exist in the array.
155
163
assert . deepEqual (
156
- highlighter . getDecorationRanges ( 'file1' ) ,
164
+ highlighter . getDecorationRanges ( fileUri1 ) ,
157
165
createHighlightingScopeRanges (
158
166
[ highlightingsInLine1 , ...highlightingsInLine . slice ( 1 ) ] ) ) ;
159
167
// Closing a text document removes all highlightings for the file and no
160
168
// other files.
161
- highlighter . removeFileHighlightings ( 'file1' ) ;
162
- assert . deepEqual ( highlighter . getDecorationRanges ( 'file1' ) , [ ] ) ;
163
- assert . deepEqual ( highlighter . getDecorationRanges ( 'file2' ) ,
169
+ highlighter . removeFileHighlightings ( fileUri1 ) ;
170
+ assert . deepEqual ( highlighter . getDecorationRanges ( fileUri1 ) , [ ] ) ;
171
+ assert . deepEqual ( highlighter . getDecorationRanges ( fileUri2 ) ,
164
172
createHighlightingScopeRanges ( [ highlightingsInLine1 ] ) ) ;
165
173
} ) ;
166
174
} ) ;
0 commit comments