discard """ outputsub: "" """ # tests for rstgen module. import ../../lib/packages/docutils/rstgen import ../../lib/packages/docutils/rst import unittest, strutils, strtabs suite "YAML syntax highlighting": test "Basics": let input = """.. code-block:: yaml %YAML 1.2 --- a string: string a list: - item 1 - item 2 a map: ? key : value ...""" let output = rstTohtml(input, {}, defaultConfig()) assert output == """
%YAML 1.2
---
a string: string
a list:
  - item 1
  - item 2
a map:
? key
: value
...
""" test "Block scalars": let input = """.. code-block:: yaml a literal block scalar: | some text # not a comment # a comment, since less indented # another comment a folded block scalar: >2 some text # not a comment since indented as specified # a comment another literal block scalar: |+ # comment after header allowed, since more indented than parent""" let output = rstToHtml(input, {}, defaultConfig()) assert output == """
a literal block scalar: |
  some text
  # not a comment
 # a comment, since less indented
  # another comment
a folded block scalar: >2
   some text
  # not a comment since indented as specified
 # a comment
another literal block scalar:
  |+ # comment after header
 allowed, since more indented than parent
""" test "Directives": let input = """.. code-block:: yaml %YAML 1.2 --- %not a directive ... %a directive ... a string % not a directive ... %TAG ! !foo:""" let output = rstToHtml(input, {}, defaultConfig()) assert output == """
%YAML 1.2
---
%not a directive
...
%a directive
...
a string
% not a directive
...
%TAG ! !foo:
""" test "Flow Style and Numbers": let input = """.. code-block:: yaml { "quoted string": 42, 'single quoted string': false, [ list, "with", 'entries' ]: 73.32e-73, more numbers: [-783, 11e78], not numbers: [ 42e, 0023, +32.37, 8 ball] }""" let output = rstToHtml(input, {}, defaultConfig()) assert output == """
{
  "quoted string": 42,
  'single quoted string': false,
  [ list, "with", 'entries' ]: 73.32e-73,
  more numbers: [-783, 11e78],
  not numbers: [ 42e, 0023, +32.37, 8 ball]
}
""" test "Anchors, Aliases, Tags": let input = """.. code-block:: yaml --- !!map !!str string: ! 42 ? &anchor !!seq []: : !localtag foo alias: *anchor """ let output = rstToHtml(input, {}, defaultConfig()) assert output == """
--- !!map
!!str string: !<tag:yaml.org,2002:int> 42
? &anchor !!seq []:
: !localtag foo
alias: *anchor
""" test "Edge cases": let input = """.. code-block:: yaml ... %a string: a:string:not:a:map ... not a list: -2 -3 -4 example.com/not/a#comment: ?not a map key """ let output = rstToHtml(input, {}, defaultConfig()) assert output == """
...
 %a string:
  a:string:not:a:map
...
not a list:
  -2
  -3
  -4
example.com/not/a#comment:
  ?not a map key
""" suite "RST/Markdown general": test "RST emphasis": assert rstToHtml("*Hello* **world**!", {}, newStringTable(modeStyleInsensitive)) == "Hello world!" test "Markdown links": let a = rstToHtml("(( [Nim](https://nim-lang.org/) ))", {roSupportMarkdown}, defaultConfig()) b = rstToHtml("(([Nim](https://nim-lang.org/)))", {roSupportMarkdown}, defaultConfig()) c = rstToHtml("[[Nim](https://nim-lang.org/)]", {roSupportMarkdown}, defaultConfig()) assert a == """(( Nim ))""" assert b == """((Nim))""" assert c == """[Nim]""" test "Markdown tables": let input1 = """ | A1 header | A2 \| not fooled | :--- | ----: | | C1 | C2 **bold** | ignored | | D1 `code \|` | D2 | also ignored | E1 \| text | | | F2 without pipe not in table""" let output1 = rstToHtml(input1, {roSupportMarkdown}, defaultConfig()) assert output1 == """
A1 headerA2 | not fooled
C1C2 bold
D1 code |D2
E1 | text
F2 without pipe

not in table

""" let input2 = """ | A1 header | A2 | | --- | --- |""" let output2 = rstToHtml(input2, {roSupportMarkdown}, defaultConfig()) assert output2 == """
A1 headerA2
""" test "RST tables": let input1 = """ Test 2 column/4 rows table: ==== === H0 H1 ==== === A0 A1 ==== === A2 A3 ==== === A4 A5 ==== === """ let output1 = rstToLatex(input1, {}) assert "{|X|X|}" in output1 # 2 columns assert count(output1, "\\\\") == 4 # 4 rows for cell in ["H0", "H1", "A0", "A1", "A2", "A3", "A4", "A5"]: assert cell in output1 let input2 = """ Now test 3 columns / 2 rows, and also borders containing 4 =, 3 =, 1 = signs: ==== === = H0 H1 H ==== === = A0 A1 X Ax Y ==== === = """ let output2 = rstToLatex(input2, {}) assert "{|X|X|X|}" in output2 # 3 columns assert count(output2, "\\\\") == 2 # 2 rows for cell in ["H0", "H1", "H", "A0", "A1", "X", "Ax", "Y"]: assert cell in output2 test "RST adornments": let input1 = """ Check that a few punctuation symbols are not parsed as adornments: :word1: word2 .... word3 """ let output1 = rstToHtml(input1, {roSupportMarkdown}, defaultConfig()) discard output1 test "RST sections": let input1 = """ Long chapter name ''''''''''''''''''' """ let output1 = rstToHtml(input1, {roSupportMarkdown}, defaultConfig()) assert "Long chapter name" in output1 and "" in output1 test "Markdown code block": let input1 = """ ``` let x = 1 ``` """ let output1 = rstToHtml(input1, {roSupportMarkdown}, defaultConfig()) assert "" in output1 assert "other line
" in output1 let output1l = rstToLatex(input1, {}) assert "line block\\\\" in output1l assert "other line\\\\" in output1l suite "RST/Code highlight": test "Basic Python code highlight": let pythonCode = """ .. code-block:: python def f_name(arg=42): print(f"{arg}") """ let expected = """

def f_name(arg=42): print(f"{arg}")

""" check strip(rstToHtml(pythonCode, {}, newStringTable(modeCaseSensitive))) == strip(expected)