💾 Archived View for gmi.noulin.net › gitRepositories › md4c › file › test › pathological_tests.py.gm… captured on 2023-01-29 at 13:23:48. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
pathological_tests.py (3479B)
1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 4 import re 5 import argparse 6 import sys 7 import platform 8 from cmark import CMark 9 10 if __name__ == "__main__": 11 parser = argparse.ArgumentParser(description='Run cmark tests.') 12 parser.add_argument('-p', '--program', dest='program', nargs='?', default=None, 13 help='program to test') 14 parser.add_argument('--library-dir', dest='library_dir', nargs='?', 15 default=None, help='directory containing dynamic library') 16 args = parser.parse_args(sys.argv[1:]) 17 18 cmark = CMark(prog=args.program, library_dir=args.library_dir) 19 20 # list of pairs consisting of input and a regex that must match the output. 21 pathological = { 22 # note - some pythons have limit of 65535 for {num-matches} in re. 23 "nested strong emph": 24 (("*a **a " * 65000) + "b" + (" a** a*" * 65000), 25 re.compile("(<em>a <strong>a ){65000}b( a</strong> a</em>){65000}")), 26 "many emph closers with no openers": 27 (("a_ " * 65000), 28 re.compile("(a[_] ){64999}a_")), 29 "many emph openers with no closers": 30 (("_a " * 65000), 31 re.compile("(_a ){64999}_a")), 32 "many link closers with no openers": 33 (("a]" * 65000), 34 re.compile("(a\]){65000}")), 35 "many link openers with no closers": 36 (("[a" * 65000), 37 re.compile("(\[a){65000}")), 38 "mismatched openers and closers": 39 (("*a_ " * 50000), 40 re.compile("([*]a[_] ){49999}[*]a_")), 41 "openers and closers multiple of 3": 42 (("a**b" + ("c* " * 50000)), 43 re.compile("a[*][*]b(c[*] ){49999}c[*]")), 44 "link openers and emph closers": 45 (("[ a_" * 50000), 46 re.compile("(\[ a_){50000}")), 47 "hard link/emph case": 48 ("**x [a*b**c*](d)", 49 re.compile("\\*\\*x <a href=\"d\">a<em>b\\*\\*c</em></a>")), 50 "nested brackets": 51 (("[" * 50000) + "a" + ("]" * 50000), 52 re.compile("\[{50000}a\]{50000}")), 53 "nested block quotes": 54 ((("> " * 50000) + "a"), 55 re.compile("(<blockquote>\r?\n){50000}")), 56 "U+0000 in input": 57 ("abc\u0000de\u0000", 58 re.compile("abc\ufffd?de\ufffd?")), 59 "backticks": 60 ("".join(map(lambda x: ("e" + "`" * x), range(1,10000))), 61 re.compile("^<p>[e`]*</p>\r?\n$")), 62 "many links": 63 ("[t](/u) " * 50000, 64 re.compile("(<a href=\"/u\">t</a> ?){50000}")), 65 "many references": 66 ("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,50000 * 16))) + "[0] " * 50000, 67 re.compile("(\[0\] ){49999}")) 68 } 69 70 whitespace_re = re.compile('/s+/') 71 passed = 0 72 errored = 0 73 failed = 0 74 75 #print("Testing pathological cases:") 76 for description in pathological: 77 (inp, regex) = pathological[description] 78 [rc, actual, err] = cmark.to_html(inp) 79 if rc != 0: 80 errored += 1 81 print(description, '[ERRORED (return code %d)]' %rc) 82 print(err) 83 elif regex.search(actual): 84 #print(description, '[PASSED]') 85 passed += 1 86 else: 87 print(description, '[FAILED]') 88 print(repr(actual)) 89 failed += 1 90 91 print("%d passed, %d failed, %d errored" % (passed, failed, errored)) 92 if (failed == 0 and errored == 0): 93 exit(0) 94 else: 95 exit(1)