summary refs log tree commit diff stats
path: root/tests/stdlib/thighlite.nim
blob: 0cd33425439e46544bc0ded98778abacf21e4464 (plain) (blame)
1
2
3
4
5
6
7
8
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Gener
discard """
  matrix: "--mm:refc; --mm:orc"
"""

import unittest, strutils
import ../../lib/packages/docutils/highlite
import std/objectdollar

block: # Nim tokenizing
  test "string literals and escape seq":
    check("\"ok1\\nok2\\nok3\"".tokenize(langNim) ==
       @[("\"ok1", gtStringLit), ("\\n", gtEscapeSequence), ("ok2", gtStringLit),
         ("\\n", gtEscapeSequence), ("ok3\"", gtStringLit)
      ])
    check("\"\"\"ok1\\nok2\\nok3\"\"\"".tokenize(langNim) ==
       @[("\"\"\"ok1\\nok2\\nok3\"\"\"", gtLongStringLit)
      ])

  test "whitespace at beginning of line is preserved":
    check("  discard 1".tokenize(langNim) ==
       @[("  ", gtWhitespace), ("discard", gtKeyword), (" ", gtWhitespace),
         ("1", gtDecNumber)
       ])

block: # Cmd (shell) tokenizing
  test "cmd with dollar and output":
    check(
      dedent"""
        $ nim c file.nim
        out: file [SuccessX]"""
        .tokenize(langConsole) ==
      @[("$ ", gtPrompt), ("nim", gtProgram),
        (" ", gtWhitespace), ("c", gtOption), (" ", gtWhitespace),
        ("file.nim", gtIdentifier), ("\n", gtWhitespace),
        ("out: file [SuccessX]", gtProgramOutput)
      ])

block: # bug #21232
  let code = "/"
  var toknizr: GeneralTokenizer

  initGeneralTokenizer(toknizr, code)

  getNextToken(toknizr, langC)
  check $toknizr == """(kind: gtOperator, start: 0, length: 1, buf: "/", pos: 1, state: gtEof, lang: langC)"""