thighlite.nim 1.4 KB

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