aboutsummaryrefslogtreecommitdiff
path: root/test/pathological_tests.py
blob: 3cf1662c8803115ce19fbe4ac257296ae0d560d6 (plain)
  1. #!/usr/bin/env python
  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. pathological = {
  17. "nested strong emph":
  18. (("*a **a " * 100000) + "b" + (" a** a*" * 100000),
  19. "<p>" + ("<em>a <strong>a " * 100000) + "b" +
  20. (" a</strong> a</em>" * 100000) + "</p>"),
  21. "nested brackets":
  22. (("[" * 50000) + "a" + ("]" * 50000),
  23. "<p>" + ("[" * 50000) + "a" + ("]" * 50000) + "</p>")
  24. }
  25. whitespace_re = re.compile('/s+/')
  26. passed = 0
  27. errored = 0
  28. failed = 0
  29. print "Testing pathological cases:"
  30. for description in pathological:
  31. print description
  32. (inp, expected) = pathological[description]
  33. [rc, actual, err] = cmark.to_html(inp)
  34. if rc != 0:
  35. errored += 1
  36. print description
  37. print "program returned error code %d" % rc
  38. print(err)
  39. elif whitespace_re.sub(' ', actual.rstrip()) == expected.rstrip():
  40. passed += 1
  41. else:
  42. print description, 'failed'
  43. print(actual)
  44. failed += 1
  45. print "%d passed, %d failed, %d errored" % (passed, failed, errored)
  46. if (failed == 0 and errored == 0):
  47. exit(0)
  48. else:
  49. exit(1)