@@ -2,15 +2,11 @@ import * as assert from 'assert';
22import { ClassCompletionItemProvider } from '../../extension' ;
33import {
44 workspace ,
5- TextDocument ,
65 Position ,
76 CancellationToken ,
87 Event ,
98 CompletionContext ,
109 CompletionTriggerKind ,
11- EndOfLine ,
12- Range ,
13- TextLine ,
1410 Uri ,
1511 CompletionItem
1612} from 'vscode' ;
@@ -29,48 +25,6 @@ class MockCompletionContext implements CompletionContext {
2925 triggerCharacter ?: string | undefined ;
3026}
3127
32- class MockTextDocument implements TextDocument {
33- uri ! : Uri ;
34- fileName ! : string ;
35- isUntitled ! : boolean ;
36- languageId ! : string ;
37- version ! : number ;
38- isDirty ! : boolean ;
39- isClosed ! : boolean ;
40- eol ! : EndOfLine ;
41- lineCount ! : number ;
42- readonly #text: string ;
43-
44- constructor ( text : string ) {
45- this . #text = text ;
46- }
47-
48- getText ( range ?: Range ) : string {
49- return this . #text;
50- }
51- save ( ) : Thenable < boolean > {
52- throw new Error ( 'Method not implemented.' ) ;
53- }
54- lineAt ( position : Position | number | any ) : TextLine | any {
55- throw new Error ( 'Method not implemented.' ) ;
56- }
57- offsetAt ( position : Position ) : number {
58- throw new Error ( 'Method not implemented.' ) ;
59- }
60- positionAt ( offset : number ) : Position {
61- throw new Error ( 'Method not implemented.' ) ;
62- }
63- getWordRangeAtPosition ( position : Position , regex ?: RegExp ) : Range | undefined {
64- throw new Error ( 'Method not implemented.' ) ;
65- }
66- validateRange ( range : Range ) : Range {
67- throw new Error ( 'Method not implemented.' ) ;
68- }
69- validatePosition ( position : Position ) : Position {
70- throw new Error ( 'Method not implemented.' ) ;
71- }
72- }
73-
7428suite ( 'Extension Test Suite' , ( ) => {
7529
7630 const position = new Position ( 0 , 0 ) ;
@@ -135,51 +89,76 @@ suite('Extension Test Suite', () => {
13589 "` ) ?. [ 2 ] , "http://example.com/example.css" ) ;
13690 } ) ;
13791
138- test ( 'Rejects empty documents ' , done => {
92+ test ( 'Rejects outside class attribute ' , async ( ) => {
13993 const provider = new ClassCompletionItemProvider ( ) ;
140- const document = new MockTextDocument ( `` ) ;
141- const result = provider . provideCompletionItems ( document , position , token , context ) as Thenable < CompletionItem [ ] > ;
142-
143- result . then ( items => done ( items ) , ( ) => done ( ) ) ;
94+ const content = `<a class=""></a>` ;
95+ const document = await workspace . openTextDocument ( { content, language : "html" } ) ;
96+
97+ try {
98+ const items = await ( provider . provideCompletionItems (
99+ document ,
100+ document . positionAt ( content . length ) ,
101+ token ,
102+ context ) as Thenable < CompletionItem [ ] > ) ;
103+
104+ assert . strictEqual ( items . length , 0 ) ;
105+ } catch ( e ) {
106+ assert . strictEqual ( e , undefined ) ;
107+ }
144108 } ) ;
145109
146- test ( 'Rejects outside class attribute ' , done => {
110+ test ( 'Completes from style tag ' , async ( ) => {
147111 const provider = new ClassCompletionItemProvider ( ) ;
148- const document = new MockTextDocument ( `<a class=""></a>` ) ;
149- const result = provider . provideCompletionItems ( document , position , token , context ) as Thenable < CompletionItem [ ] > ;
112+ const content = `<style>.test{}</style><a class="` ;
113+ const document = await workspace . openTextDocument ( { content, language : "html" } ) ;
114+
115+ const items = await ( provider . provideCompletionItems (
116+ document ,
117+ document . positionAt ( content . length ) ,
118+ token ,
119+ context ) as Thenable < CompletionItem [ ] > ) ;
150120
151- result . then ( items => done ( items ) , ( ) => done ( ) ) ;
121+ assert . strictEqual ( items . length , 1 ) ;
152122 } ) ;
153123
154- test ( 'Completes from style tag' , done => {
124+ test ( 'Completes from link tag' , async ( ) => {
155125 const provider = new ClassCompletionItemProvider ( ) ;
156- const document = new MockTextDocument ( `<style>.test{}</style><a class="` ) ;
126+ const content = `
127+ <link
128+ href="https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css" 129+ rel="stylesheet"
130+ >
131+ <a class="` ;
132+ const document = await workspace . openTextDocument ( { content, language : "html" } ) ;
133+
134+ const items = await ( provider . provideCompletionItems (
135+ document ,
136+ document . positionAt ( content . length ) ,
137+ token ,
138+ context ) as Thenable < CompletionItem [ ] > ) ;
139+
140+ assert . notStrictEqual ( items . length , 0 ) ;
141+ } ) ;
157142
158- const result = provider . provideCompletionItems ( document , position , token , context ) as Thenable < CompletionItem [ ] > ;
159143
160- result . then ( items => {
161- try {
162- assert . strictEqual ( items . length , 1 ) ;
163- done ( ) ;
164- } catch ( e ) {
165- done ( e ) ;
144+ test ( 'Completes from remote style' , async ( ) => {
145+ const provider = new class extends ClassCompletionItemProvider {
146+ getRemoteStyleSheets ( uri : Uri ) : string [ ] {
147+ return [
148+ "https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css" 149+ ] ;
166150 }
167- } , done ) ;
168- } ) ;
151+ } ( ) ;
169152
170- test ( 'Completes from link tag' , done => {
171- const provider = new ClassCompletionItemProvider ( ) ;
172- const document = new MockTextDocument ( `<link href="https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css" rel="stylesheet"><a class="` ) ; 153+ const content = `<a class="` ;
154+ const document = await workspace . openTextDocument ( { content, language : "html" } ) ;
173155
174- const result = provider . provideCompletionItems ( document , position , token , context ) as Thenable < CompletionItem [ ] > ;
156+ const items = await ( provider . provideCompletionItems (
157+ document ,
158+ document . positionAt ( content . length ) ,
159+ token ,
160+ context ) as Thenable < CompletionItem [ ] > ) ;
175161
176- result . then ( items => {
177- try {
178- assert . notStrictEqual ( items . length , 0 ) ;
179- done ( ) ;
180- } catch ( e ) {
181- done ( e ) ;
182- }
183- } , done ) ;
162+ assert . notStrictEqual ( items . length , 0 ) ;
184163 } ) ;
185164} ) ;
0 commit comments