comments-basic.js 803 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. test("regular comments", () => {
  2. const source = `
  3. var i = 0;
  4. // i++;
  5. /* i++; */
  6. /*
  7. i++;
  8. */
  9. /**/ i++;
  10. i;`;
  11. expect(source).toEvalTo(1);
  12. });
  13. test("html comments", () => {
  14. const source = `
  15. var i = 0;
  16. var j = 0;
  17. <!-- i++; --> i++;
  18. <!-- i++;
  19. i++;
  20. --> i++;
  21. /**/ --> i++;
  22. j --> i++;
  23. i;`;
  24. expect(source).toEvalTo(2);
  25. });
  26. test("unterminated multi-line comment", () => {
  27. expect("/*").not.toEval();
  28. expect("/**").not.toEval();
  29. expect("/*/").not.toEval();
  30. expect("/* foo").not.toEval();
  31. expect("foo /*").not.toEval();
  32. });
  33. test("hashbang comments", () => {
  34. expect("#!").toEvalTo(undefined);
  35. expect("#!/bin/js").toEvalTo(undefined);
  36. expect("#!\n1").toEvalTo(1);
  37. expect(" #!").not.toEval();
  38. expect("\n#!").not.toEval();
  39. expect("#!\n#!").not.toEval();
  40. });