Serenity Operating System
at master 53 lines 1.0 kB view raw
1test("regular comments", () => { 2 const source = ` 3var i = 0; 4// i++; 5/* i++; */ 6/* 7i++; 8*/ 9/**/ i++; 10i;`; 11 12 expect(source).toEvalTo(1); 13}); 14 15test("html comments", () => { 16 const source = ` 17var i = 0; 18var j = 0; 19<!-- i++; --> i++; 20<!-- i++; 21i++; 22--> i++; 23/**/ --> i++; 24j --> i++; 25i;`; 26 expect(source).toEvalTo(2); 27}); 28 29test("html comments directly after block comment", () => { 30 expect("0 /* */-->i").not.toEval(); 31 expect(`0 /* 32 */-->i`).toEval(); 33 expect(`0 /* 34 */-->i 35 'a'`).toEvalTo("a"); 36}); 37 38test("unterminated multi-line comment", () => { 39 expect("/*").not.toEval(); 40 expect("/**").not.toEval(); 41 expect("/*/").not.toEval(); 42 expect("/* foo").not.toEval(); 43 expect("foo /*").not.toEval(); 44}); 45 46test("hashbang comments", () => { 47 expect("#!").toEvalTo(undefined); 48 expect("#!/bin/js").toEvalTo(undefined); 49 expect("#!\n1").toEvalTo(1); 50 expect(" #!").not.toEval(); 51 expect("\n#!").not.toEval(); 52 expect("#!\n#!").not.toEval(); 53});