1
- import fs from 'fs' ;
2
- import path from 'path' ;
3
- import { AbbreviationContext } from 'emmet' ;
4
- import { deepStrictEqual as deepEqual , strictEqual as equal } from 'assert' ;
1
+ import { strictEqual as equal } from 'assert' ;
5
2
import Range from './assets/range' ;
6
3
import createSimulator from './assets/simutator' ;
7
4
import { IssueCollection , Issue , IssueSeverity } from './assets/issue' ;
8
5
import nova from './assets/nova' ;
9
- import { getHTMLContext , getCSSContext } from '../src/lib/context' ;
10
6
import { startTracking , getTracker , handleChange , handleSelectionChange } from '../src/abbreviation/AbbreviationTracker' ;
11
7
12
- function read ( fileName : string ) : string {
13
- const absPath = path . resolve ( __dirname , fileName ) ;
14
- return fs . readFileSync ( absPath , 'utf8' ) ;
15
- }
16
-
17
- function context ( name : string , attributes ?: { [ name : string ] : string } ) : AbbreviationContext {
18
- const result = { name } as AbbreviationContext ;
19
- if ( attributes ) {
20
- result . attributes = attributes ;
21
- }
22
- return result ;
23
- }
24
-
25
8
describe ( 'Autocomplete provider' , ( ) => {
26
9
before ( ( ) => {
27
10
global [ 'Range' ] = Range ;
@@ -38,93 +21,6 @@ describe('Autocomplete provider', () => {
38
21
delete global [ 'nova' ] ;
39
22
} ) ;
40
23
41
- it ( 'HTML context' , ( ) => {
42
- const html = read ( './samples/embedded-style.html' ) ;
43
-
44
- deepEqual ( getHTMLContext ( html , 298 ) , {
45
- syntax : 'html' ,
46
- context : context ( 'div' , { style : 'padding: 10px;' } )
47
- } ) ;
48
- // Inside tag, ignore context
49
- deepEqual ( getHTMLContext ( html , 276 ) , undefined ) ;
50
-
51
- // Inside tag but in `style` attribute value: syntax is `css` but no context
52
- // since caret is inside property name
53
- deepEqual ( getHTMLContext ( html , 286 ) , {
54
- syntax : 'css' ,
55
- inline : true
56
- } ) ;
57
-
58
- // Same as above but caret is inside CSS property value
59
- deepEqual ( getHTMLContext ( html , 290 ) , {
60
- syntax : 'css' ,
61
- inline : true ,
62
- context : context ( 'padding' )
63
- } ) ;
64
- deepEqual ( getHTMLContext ( html , 292 ) , {
65
- syntax : 'css' ,
66
- inline : true ,
67
- context : context ( 'padding' )
68
- } ) ;
69
-
70
- // Inside empty `style` attribute
71
- deepEqual ( getHTMLContext ( html , 351 ) , {
72
- syntax : 'css' ,
73
- inline : true
74
- } ) ;
75
- } ) ;
76
-
77
- it ( 'CSS in HTML' , ( ) => {
78
- const html = read ( './samples/embedded-style.html' ) ;
79
-
80
- // Inside <style> tag, inside selector block
81
- deepEqual ( getHTMLContext ( html , 212 ) , {
82
- syntax : 'css'
83
- } ) ;
84
-
85
- // Outside selector block
86
- deepEqual ( getHTMLContext ( html , 194 ) , undefined ) ;
87
-
88
- // Inside property value
89
- deepEqual ( getHTMLContext ( html , 224 ) , {
90
- syntax : 'css' ,
91
- context : context ( 'padding' )
92
- } ) ;
93
- } ) ;
94
-
95
- it ( 'CSS context' , ( ) => {
96
- const scss = read ( './samples/style.scss' ) ;
97
- const ctx = ( context ?: { } ) => {
98
- const result : any = { syntax : 'css' } ;
99
- if ( context ) {
100
- result . context = context ;
101
- }
102
-
103
- return result ;
104
- } ;
105
-
106
- // Not inside selector block
107
- deepEqual ( getCSSContext ( scss , 9 ) , undefined ) ;
108
-
109
- // ...but inside property (variable)
110
- deepEqual ( getCSSContext ( scss , 5 ) , ctx ( { name : '$foo' } ) ) ;
111
-
112
- // Inside selector
113
- deepEqual ( getCSSContext ( scss , 12 ) , undefined ) ;
114
-
115
- // Inside selector block
116
- deepEqual ( getCSSContext ( scss , 36 ) , ctx ( ) ) ;
117
-
118
- // Inside property value
119
- deepEqual ( getCSSContext ( scss , 32 ) , ctx ( { name : 'padding' } ) ) ;
120
-
121
- // Still inside selector block
122
- deepEqual ( getCSSContext ( scss , 125 ) , ctx ( ) ) ;
123
-
124
- // Not inside selector
125
- deepEqual ( getCSSContext ( scss , 128 ) , undefined ) ;
126
- } ) ;
127
-
128
24
it ( 'abbreviation tracker' , ( ) => {
129
25
const { editor, content, input, select } = createSimulator ( 'before d after' , 8 , {
130
26
onChange : handleChange ,
0 commit comments