@@ -8,6 +8,7 @@ const OPTIONS = {
88 string : '[string]' ,
99 special : '[special]' ,
1010 bracket : '[bracket]' ,
11+ comment : '[comment]' ,
1112 clear : '[clear]'
1213 }
1314}
@@ -114,6 +115,26 @@ describe('unicode', () => {
114115 expect ( hlUni ( 'SELECT * FROM a;SELECT * FROM b;' ) )
115116 . toBe ( '[keyword]SELECT[clear] [special]*[clear] [keyword]FROM[clear] a[special];[clear][keyword]SELECT[clear] [special]*[clear] [keyword]FROM[clear] b[special];[clear]' )
116117 } )
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+ } )
117138} )
118139
119140describe ( 'html' , ( ) => {
@@ -211,6 +232,26 @@ describe('html', () => {
211232 expect ( hlHtml ( "select * from a where b = 'array<map<string,string>>';" ) )
212233 . 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>' )
213234 } )
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+ } )
214255} )
215256
216257describe ( 'getSegments' , ( ) => {
0 commit comments