From 2413d436ed98866e9a70fbd4070a5da52dd97cd5 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 8 Jan 2016 12:15:31 -0800 Subject: New format for spec tests, new lua formatter for specs. The format for the spec examples has changed from . markdown . html . to ```````````````````````````````` example markdown . html ```````````````````````````````` One advantage of this is that `spec.txt` becomes a valid Markdown file. `tests/spec_test.py` has been changed to use the new format. The old `tools/makespec.py` has been replaced by a lua program, `tools/make_spec.lua`, which uses the `lcmark` rock (and indirectly libcmark). It can generate html, latex, and commonmark versions of the spec. Pandoc is no longer needed for the latex/PDF version. And, since the new program uses the cmark API and operates directly on the parse tree, we avoid certain bad results we got with the regex replacements done by the python script. --- test/spec_tests.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/spec_tests.py b/test/spec_tests.py index c6950fb..d5b4d05 100755 --- a/test/spec_tests.py +++ b/test/spec_tests.py @@ -90,29 +90,33 @@ def get_tests(specfile): with open(specfile, 'r', encoding='utf-8') as specf: for line in specf: line_number = line_number + 1 - if state == 0 and re.match(header_re, line): - headertext = header_re.sub('', line).strip() - if line.strip() == ".": - state = (state + 1) % 3 - if state == 0: - example_number = example_number + 1 - end_line = line_number - tests.append({ - "markdown":''.join(markdown_lines).replace('→',"\t"), - "html":''.join(html_lines).replace('→',"\t"), - "example": example_number, - "start_line": start_line, - "end_line": end_line, - "section": headertext}) - start_line = 0 - markdown_lines = [] - html_lines = [] + l = line.strip() + if l == "`" * 32 + " example": + state = 1 + elif l == "`" * 32: + state = 0 + example_number = example_number + 1 + end_line = line_number + tests.append({ + "markdown":''.join(markdown_lines).replace('→',"\t"), + "html":''.join(html_lines).replace('→',"\t"), + "example": example_number, + "start_line": start_line, + "end_line": end_line, + "section": headertext}) + start_line = 0 + markdown_lines = [] + html_lines = [] + elif l == ".": + state = 2 elif state == 1: if start_line == 0: start_line = line_number - 1 markdown_lines.append(line) elif state == 2: html_lines.append(line) + elif state == 0 and re.match(header_re, line): + headertext = header_re.sub('', line).strip() return tests if __name__ == "__main__": -- cgit v1.2.3