index.js 732 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. var test = require('tap').test
  2. var tok = require('../')
  3. test('tokenize', function (t) {
  4. function e (input, output, invalid) {
  5. t.deepEqual(tok(input, true), output)
  6. if(invalid)
  7. t.throws(function () {
  8. tok(input)
  9. })
  10. }
  11. e('function () { }',
  12. ['function', ' ', '(', ')', ' ', '{', ' ', '}'])
  13. e('"hello"',
  14. ['"hello"'])
  15. e("'hello'",
  16. ["'hello'"])
  17. e('" "',
  18. ['" "'])
  19. e('" \\" "',
  20. ['" \\" "'])
  21. e('" \\\n "',
  22. ['" \\\n "'])
  23. //regrettably, js doesn't have multiline strings.
  24. e('" \n "',
  25. ['"',' \n ', '"'], true)
  26. e("' '",
  27. ["' '"])
  28. e("' \\' '",
  29. ["' \\' '"])
  30. e("' \n '",
  31. ["'"," \n ", "'"], true)
  32. t.end()
  33. })