aboutsummaryrefslogtreecommitdiff
path: root/test/pathological_tests.py
blob: 8b25137d56a61014aa7658674fc249efb8312c93 (plain)
  1. #!/usr/bin/env python2
  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. "nested strong emph":
  19. (("*a **a " * 100000) + "b" + (" a** a*" * 100000),
  20. re.compile("(<em>a <strong>a ){100000}b( a</strong> a</em>){100000}")),
  21. "nested brackets":
  22. (("[" * 50000) + "a" + ("]" * 50000),
  23. re.compile("\[{50000}a\]{50000}")),
  24. "nested block quotes":
  25. ((("> " * 50000) + "a"),
  26. re.compile("(<blockquote>\n){50000}")),
  27. "U+0000 in input":
  28. ("abc\0de\0",
  29. re.compile("abc(�)?de(�)?"))
  30. }
  31. whitespace_re = re.compile('/s+/')
  32. passed = 0
  33. errored = 0
  34. failed = 0
  35. print "Testing pathological cases:"
  36. for description in pathological:
  37. print description
  38. (inp, regex) = pathological[description]
  39. [rc, actual, err] = cmark.to_html(inp)
  40. if rc != 0:
  41. errored += 1
  42. print description
  43. print "program returned error code %d" % rc
  44. print(err)
  45. elif regex.search(actual):
  46. passed += 1
  47. else:
  48. print description, 'failed'
  49. print(actual)
  50. failed += 1
  51. print "%d passed, %d failed, %d errored" % (passed, failed, errored)
  52. if (failed == 0 and errored == 0):
  53. exit(0)
  54. else:
  55. exit(1)