@@ -14,46 +14,42 @@ function preElementWithHTML(html) {
14
14
return element ;
15
15
}
16
16
17
- let tests = { } ;
18
-
19
- tests = {
20
- ...tests ,
21
-
22
- "mark first word on line" : ( ) => {
17
+ describe ( "markEditorText" , ( ) => {
18
+ it ( "mark first word on line" , ( ) => {
23
19
let editor = preElementWithHTML ( "hello world" ) ;
24
20
markEditorText ( editor , dom . window , [ { begin : 0 , end : 5 } ] ) ;
25
21
assert . strictEqual ( editor . innerHTML , "<mark>hello</mark> world" ) ;
26
- } ,
22
+ } ) ;
27
23
28
- "mark last word on line" : ( ) => {
24
+ it ( "mark last word on line" , ( ) => {
29
25
let editor = preElementWithHTML ( "hello world" ) ;
30
26
markEditorText ( editor , dom . window , [ { begin : 6 , end : 11 } ] ) ;
31
27
assert . strictEqual ( editor . innerHTML , "hello <mark>world</mark>" ) ;
32
- } ,
28
+ } ) ;
33
29
34
- "mark across two text nodes" : ( ) => {
30
+ it ( "mark across two text nodes" , ( ) => {
35
31
// <pre>helloworld</pre>
36
32
let editor = dom . window . document . createElement ( "pre" ) ;
37
33
editor . appendChild ( dom . window . document . createTextNode ( "hello" ) ) ;
38
34
editor . appendChild ( dom . window . document . createTextNode ( "world" ) ) ;
39
35
40
36
markEditorText ( editor , dom . window , [ { begin : 3 , end : 8 } ] ) ;
41
37
assert . strictEqual ( editor . innerHTML , "hel<mark>lowor</mark>ld" ) ;
42
- } ,
38
+ } ) ;
43
39
44
- "marking deletes existing non-overlapping marks" : ( ) => {
40
+ it ( "marking deletes existing non-overlapping marks" , ( ) => {
45
41
let editor = preElementWithHTML ( "<mark>hello</mark> world" ) ;
46
42
markEditorText ( editor , dom . window , [ { begin : 6 , end : 11 } ] ) ;
47
43
assert . strictEqual ( editor . innerHTML , "hello <mark>world</mark>" ) ;
48
- } ,
44
+ } ) ;
49
45
50
- "marking with no marks deletes existing marks" : ( ) => {
46
+ it ( "marking with no marks deletes existing marks" , ( ) => {
51
47
let editor = preElementWithHTML ( "<mark>hello</mark> <mark>world</mark>" ) ;
52
48
markEditorText ( editor , dom . window , [ ] ) ;
53
49
assert . strictEqual ( editor . innerHTML , "hello world" ) ;
54
- } ,
50
+ } ) ;
55
51
56
- "multiple new marks" : ( ) => {
52
+ it ( "multiple new marks" , ( ) => {
57
53
let editor = preElementWithHTML ( "hello world" ) ;
58
54
markEditorText ( editor , dom . window , [
59
55
{ begin : 0 , end : 5 } ,
@@ -63,51 +59,51 @@ tests = {
63
59
editor . innerHTML ,
64
60
"<mark>hello</mark> <mark>world</mark>"
65
61
) ;
66
- } ,
62
+ } ) ;
67
63
68
- "marking removes empty <mark>" : ( ) => {
64
+ it ( "marking removes empty <mark>" , ( ) => {
69
65
let editor = preElementWithHTML ( "<mark></mark> world" ) ;
70
66
markEditorText ( editor , dom . window , [ { begin : 1 , end : 6 } ] ) ;
71
67
assert . strictEqual ( editor . innerHTML , " <mark>world</mark>" ) ;
72
- } ,
68
+ } ) ;
73
69
74
- "marking preserves <br> immediately after mark" : ( ) => {
70
+ it ( "marking preserves <br> immediately after mark" , ( ) => {
75
71
let editor = preElementWithHTML ( "hello<br>world" ) ;
76
72
markEditorText ( editor , dom . window , [ { begin : 0 , end : 5 } ] ) ;
77
73
assert . strictEqual ( editor . innerHTML , "<mark>hello</mark><br>world" ) ;
78
- } ,
74
+ } ) ;
79
75
80
- "marking preserves <br> before inserted mark" : ( ) => {
76
+ it ( "marking preserves <br> before inserted mark" , ( ) => {
81
77
let editor = preElementWithHTML ( "one<br>twothree" ) ;
82
78
markEditorText ( editor , dom . window , [ { begin : 7 , end : 7 + "three" . length } ] ) ;
83
79
assert . strictEqual ( editor . innerHTML , "one<br>two<mark>three</mark>" ) ;
84
- } ,
80
+ } ) ;
85
81
86
- "marking preserves <br> after inserted mark" : ( ) => {
82
+ it ( "marking preserves <br> after inserted mark" , ( ) => {
87
83
let editor = preElementWithHTML ( "onetwo<br>three" ) ;
88
84
markEditorText ( editor , dom . window , [ { begin : 0 , end : 3 } ] ) ;
89
85
assert . strictEqual ( editor . innerHTML , "<mark>one</mark>two<br>three" ) ;
90
- } ,
86
+ } ) ;
91
87
92
- "mark exactly over existing <mark>" : ( ) => {
88
+ it ( "mark exactly over existing <mark>" , ( ) => {
93
89
let editor = preElementWithHTML ( "<mark>hello</mark> world" ) ;
94
90
markEditorText ( editor , dom . window , [ { begin : 0 , end : 5 } ] ) ;
95
91
assert . strictEqual ( editor . innerHTML , "<mark>hello</mark> world" ) ;
96
- } ,
92
+ } ) ;
97
93
98
- "mark starts at end of existing <mark>" : ( ) => {
94
+ it ( "mark starts at end of existing <mark>" , ( ) => {
99
95
let editor = preElementWithHTML ( "<mark>hello</mark>world" ) ;
100
96
markEditorText ( editor , dom . window , [ { begin : 5 , end : 10 } ] ) ;
101
97
assert . strictEqual ( editor . innerHTML , "hello<mark>world</mark>" ) ;
102
- } ,
98
+ } ) ;
103
99
104
- "add empty mark" : ( ) => {
100
+ it ( "add empty mark" , ( ) => {
105
101
let editor = preElementWithHTML ( "helloworld" ) ;
106
102
markEditorText ( editor , dom . window , [ { begin : 5 , end : 5 } ] ) ;
107
103
assert . strictEqual ( editor . innerHTML , "hello<mark></mark>world" ) ;
108
- } ,
104
+ } ) ;
109
105
110
- "add empty mark immediately after non-empty mark" : ( ) => {
106
+ it ( "add empty mark immediately after non-empty mark" , ( ) => {
111
107
let editor = preElementWithHTML ( "helloworld" ) ;
112
108
markEditorText ( editor , dom . window , [
113
109
{ begin : 0 , end : 5 } ,
@@ -117,22 +113,20 @@ tests = {
117
113
editor . innerHTML ,
118
114
"<mark>hello</mark><mark></mark>world"
119
115
) ;
120
- } ,
121
- } ;
116
+ } ) ;
122
117
123
- tests = {
124
- ...tests ,
125
-
126
- "identical marks are merged" : ( ) => {
118
+ it ( "identical marks are merged" , ( ) => {
127
119
let editor = preElementWithHTML ( "helloworld" ) ;
128
120
markEditorText ( editor , dom . window , [
129
121
{ begin : 0 , end : 5 } ,
130
122
{ begin : 0 , end : 5 } ,
131
123
] ) ;
132
124
assert . strictEqual ( editor . innerHTML , "<mark>hello</mark>world" ) ;
133
- } ,
125
+ } ) ;
126
+ } ) ;
134
127
135
- "marks are sorted before processing" : ( ) => {
128
+ describe ( "sanitizeMarks" , ( ) => {
129
+ it ( "marks are sorted before processing" , ( ) => {
136
130
let marks = [
137
131
{ begin : 6 , end : 11 } ,
138
132
{ begin : 0 , end : 5 } ,
@@ -141,41 +135,24 @@ tests = {
141
135
{ begin : 0 , end : 5 } ,
142
136
{ begin : 6 , end : 11 } ,
143
137
] ) ;
144
- } ,
138
+ } ) ;
145
139
146
- "empty marks are preserved" : ( ) => {
140
+ it ( "empty marks are preserved" , ( ) => {
147
141
let marks = [ { begin : 6 , end : 6 } ] ;
148
142
assert . deepStrictEqual ( sanitizeMarks ( marks ) , [ { begin : 6 , end : 6 } ] ) ;
149
- } ,
150
- } ;
151
-
152
- tests = {
153
- ...tests ,
143
+ } ) ;
144
+ } ) ;
154
145
155
- "parse and lint returns errors" : async ( ) => {
146
+ describe ( "parseAndLint" , ( ) => {
147
+ it ( "parse and lint returns errors" , async ( ) => {
156
148
let input = "undeclared_variable;\nanother_undeclared_variable;\n" ;
157
149
let qljs = await loadQuickLintJS ( ) ;
158
150
let marks = qljs . parseAndLint ( input ) ;
159
151
assert . deepStrictEqual ( marks , [
160
152
{ begin : 0 , end : "undeclared_variable" . length } ,
161
153
{ begin : 21 , end : 21 + "another_undeclared_variable" . length } ,
162
154
] ) ;
163
- } ,
164
- } ;
165
-
166
- async function main ( ) {
167
- for ( let testName in tests ) {
168
- if ( Object . prototype . hasOwnProperty . call ( tests , testName ) ) {
169
- let test = tests [ testName ] ;
170
- console . log ( `Running ${ testName } ...` ) ;
171
- await test ( ) ;
172
- }
173
- }
174
- console . log ( "All tests passed" ) ;
175
- }
176
- main ( ) . catch ( ( error ) => {
177
- console . error ( error . stack ) ;
178
- process . exit ( 1 ) ;
155
+ } ) ;
179
156
} ) ;
180
157
181
158
// quick-lint-js finds bugs in JavaScript programs.
0 commit comments