@@ -8,6 +8,7 @@ const OPTIONS = {
8
8
string : '[string]' ,
9
9
special : '[special]' ,
10
10
bracket : '[bracket]' ,
11
+ comment : '[comment]' ,
11
12
clear : '[clear]'
12
13
}
13
14
}
@@ -114,6 +115,26 @@ describe('unicode', () => {
114
115
expect ( hlUni ( 'SELECT * FROM a;SELECT * FROM b;' ) )
115
116
. toBe ( '[keyword]SELECT[clear] [special]*[clear] [keyword]FROM[clear] a[special];[clear][keyword]SELECT[clear] [special]*[clear] [keyword]FROM[clear] b[special];[clear]' )
116
117
} )
118
+
119
+ it ( 'comment single line' , ( ) => {
120
+ expect ( hlUni ( '-- comment 1 "comment" /* still */ comment 2\nSELECT `not comment`; -- comment 3' ) )
121
+ . toBe ( '[comment]-- comment 1 "comment" /* still */ comment 2[clear]\n[keyword]SELECT[clear] [string]`not comment`[clear][special];[clear] [comment]-- comment 3[clear]' )
122
+ } )
123
+
124
+ it ( 'comment mysql' , ( ) => {
125
+ expect ( hlUni ( '# comment 1 "comment" /* still */ comment 2\nSELECT `not comment`; # comment 3' ) )
126
+ . toBe ( '[comment]# comment 1 "comment" /* still */ comment 2[clear]\n[keyword]SELECT[clear] [string]`not comment`[clear][special];[clear] [comment]# comment 3[clear]' )
127
+ } )
128
+
129
+ it ( 'comment multiline' , ( ) => {
130
+ expect ( hlUni ( 'SELECT /* this is, a "comment" */ "not /*comment*/" /***also*comment***/' ) )
131
+ . toBe ( '[keyword]SELECT[clear] [comment]/* this is, a "comment" */[clear] [string]"not /*comment*/"[clear] [comment]/***also*comment***/[clear]' )
132
+ } )
133
+
134
+ it ( 'not a comment' , ( ) => {
135
+ expect ( hlUni ( '"id -- not comment /* still */ not"' ) )
136
+ . toBe ( '[string]"id -- not comment /* still */ not"[clear]' )
137
+ } )
117
138
} )
118
139
119
140
describe ( 'html' , ( ) => {
@@ -211,6 +232,26 @@ describe('html', () => {
211
232
expect ( hlHtml ( "select * from a where b = 'array<map<string,string>>';" ) )
212
233
. toBe ( '<span class="sql-hl-keyword">select</span> <span class="sql-hl-special">*</span> <span class="sql-hl-keyword">from</span> a <span class="sql-hl-keyword">where</span> b <span class="sql-hl-special">=</span> <span class="sql-hl-string">'array<map<string,string>>'</span><span class="sql-hl-special">;</span>' )
213
234
} )
235
+
236
+ it ( 'comment single line' , ( ) => {
237
+ expect ( hlHtml ( '-- comment 1 "comment" /* still */ comment 2\nSELECT `not comment`; -- comment 3' ) )
238
+ . toBe ( '<span class="sql-hl-comment">-- comment 1 "comment" /* still */ comment 2</span>\n<span class="sql-hl-keyword">SELECT</span> <span class="sql-hl-string">`not comment`</span><span class="sql-hl-special">;</span> <span class="sql-hl-comment">-- comment 3</span>' )
239
+ } )
240
+
241
+ it ( 'comment mysql' , ( ) => {
242
+ expect ( hlHtml ( '# comment 1 "comment" /* still */ comment 2\nSELECT `not comment`; # comment 3' ) )
243
+ . toBe ( '<span class="sql-hl-comment"># comment 1 "comment" /* still */ comment 2</span>\n<span class="sql-hl-keyword">SELECT</span> <span class="sql-hl-string">`not comment`</span><span class="sql-hl-special">;</span> <span class="sql-hl-comment"># comment 3</span>' )
244
+ } )
245
+
246
+ it ( 'comment multiline' , ( ) => {
247
+ expect ( hlHtml ( 'SELECT /* this is, a "comment" */ "not /*comment*/" /***also*comment***/' ) )
248
+ . toBe ( '<span class="sql-hl-keyword">SELECT</span> <span class="sql-hl-comment">/* this is, a "comment" */</span> <span class="sql-hl-string">"not /*comment*/"</span> <span class="sql-hl-comment">/***also*comment***/</span>' )
249
+ } )
250
+
251
+ it ( 'not a comment' , ( ) => {
252
+ expect ( hlHtml ( '"id -- not comment /* still */ not"' ) )
253
+ . toBe ( '<span class="sql-hl-string">"id -- not comment /* still */ not"</span>' )
254
+ } )
214
255
} )
215
256
216
257
describe ( 'getSegments' , ( ) => {
0 commit comments