thighlite.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import unittest, strutils
  2. import ../../lib/packages/docutils/highlite
  3. import std/objectdollar
  4. block: # Nim tokenizing
  5. test "string literals and escape seq":
  6. check("\"ok1\\nok2\\nok3\"".tokenize(langNim) ==
  7. @[("\"ok1", gtStringLit), ("\\n", gtEscapeSequence), ("ok2", gtStringLit),
  8. ("\\n", gtEscapeSequence), ("ok3\"", gtStringLit)
  9. ])
  10. check("\"\"\"ok1\\nok2\\nok3\"\"\"".tokenize(langNim) ==
  11. @[("\"\"\"ok1\\nok2\\nok3\"\"\"", gtLongStringLit)
  12. ])
  13. test "whitespace at beginning of line is preserved":
  14. check(" discard 1".tokenize(langNim) ==
  15. @[(" ", gtWhitespace), ("discard", gtKeyword), (" ", gtWhitespace),
  16. ("1", gtDecNumber)
  17. ])
  18. block: # Cmd (shell) tokenizing
  19. test "cmd with dollar and output":
  20. check(
  21. dedent"""
  22. $ nim c file.nim
  23. out: file [SuccessX]"""
  24. .tokenize(langConsole) ==
  25. @[("$ ", gtPrompt), ("nim", gtProgram),
  26. (" ", gtWhitespace), ("c", gtOption), (" ", gtWhitespace),
  27. ("file.nim", gtIdentifier), ("\n", gtWhitespace),
  28. ("out: file [SuccessX]", gtProgramOutput)
  29. ])
  30. block: # bug #21232
  31. let code = "/"
  32. var toknizr: GeneralTokenizer
  33. initGeneralTokenizer(toknizr, code)
  34. getNextToken(toknizr, langC)
  35. check $toknizr == """(kind: gtOperator, start: 0, length: 1, buf: "/", pos: 1, state: gtEof, lang: langC)"""