aboutsummaryrefslogtreecommitdiff
path: root/test/pathological_tests.py
blob: 0e991f91dc85bb3f141982630ad8ba2b211e7918 (plain)
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import re
  4. import argparse
  5. import sys
  6. import platform
  7. from cmark import CMark
  8. if __name__ == "__main__":
  9. parser = argparse.ArgumentParser(description='Run cmark tests.')
  10. parser.add_argument('--program', dest='program', nargs='?', default=None,
  11. help='program to test')
  12. parser.add_argument('--library-dir', dest='library_dir', nargs='?',
  13. default=None, help='directory containing dynamic library')
  14. args = parser.parse_args(sys.argv[1:])
  15. cmark = CMark(prog=args.program, library_dir=args.library_dir)
  16. # list of pairs consisting of input and a regex that must match the output.
  17. pathological = {
  18. # note - some pythons have limit of 65535 for {num-matches} in re.
  19. "nested strong emph":
  20. (("*a **a " * 65000) + "b" + (" a** a*" * 65000),
  21. re.compile("(<em>a <strong>a ){65000}b( a</strong> a</em>){65000}")),
  22. "nested brackets":
  23. (("[" * 50000) + "a" + ("]" * 50000),
  24. re.compile("\[{50000}a\]{50000}")),
  25. "nested block quotes":
  26. ((("> " * 50000) + "a"),
  27. re.compile("(<blockquote>\n){50000}")),
  28. "U+0000 in input":
  29. ("abc\u0000de\u0000",
  30. re.compile("abc\ufffd?de\ufffd?"))
  31. }
  32. whitespace_re = re.compile('/s+/')
  33. passed = 0
  34. errored = 0
  35. failed = 0
  36. print("Testing pathological cases:")
  37. for description in pathological:
  38. print(description)
  39. (inp, regex) = pathological[description]
  40. [rc, actual, err] = cmark.to_html(inp)
  41. if rc != 0:
  42. errored += 1
  43. print(description)
  44. print("program returned error code %d" % rc)
  45. print(err)
  46. elif regex.search(actual):
  47. passed += 1
  48. else:
  49. print(description, 'failed')
  50. print(repr(actual))
  51. failed += 1
  52. print("%d passed, %d failed, %d errored" % (passed, failed, errored))
  53. if (failed == 0 and errored == 0):
  54. exit(0)
  55. else:
  56. exit(1)