thighlite.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import unittest, strutils
  2. import ../../lib/packages/docutils/highlite
  3. block: # Nim tokenizing
  4. test "string literals and escape seq":
  5. check("\"ok1\\nok2\\nok3\"".tokenize(langNim) ==
  6. @[("\"ok1", gtStringLit), ("\\n", gtEscapeSequence), ("ok2", gtStringLit),
  7. ("\\n", gtEscapeSequence), ("ok3\"", gtStringLit)
  8. ])
  9. check("\"\"\"ok1\\nok2\\nok3\"\"\"".tokenize(langNim) ==
  10. @[("\"\"\"ok1\\nok2\\nok3\"\"\"", gtLongStringLit)
  11. ])
  12. test "whitespace at beginning of line is preserved":
  13. check(" discard 1".tokenize(langNim) ==
  14. @[(" ", gtWhitespace), ("discard", gtKeyword), (" ", gtWhitespace),
  15. ("1", gtDecNumber)
  16. ])
  17. block: # Cmd (shell) tokenizing
  18. test "cmd with dollar and output":
  19. check(
  20. dedent"""
  21. $ nim c file.nim
  22. out: file [SuccessX]"""
  23. .tokenize(langConsole) ==
  24. @[("$ ", gtPrompt), ("nim", gtProgram),
  25. (" ", gtWhitespace), ("c", gtOption), (" ", gtWhitespace),
  26. ("file.nim", gtIdentifier), ("\n", gtWhitespace),
  27. ("out: file [SuccessX]", gtProgramOutput)
  28. ])