def run_test(inp, regex):
    parser = argparse.ArgumentParser(description='Run cmark tests.')
    parser.add_argument('--program',
                        dest='program',
                        nargs='?',
                        default=None,
                        help='program to test')
    parser.add_argument('--library-dir',
                        dest='library_dir',
                        nargs='?',
                        default=None,
                        help='directory containing dynamic library')
    args = parser.parse_args(sys.argv[1:])
    cmark = CMark(prog=args.program, library_dir=args.library_dir)

    [rc, actual, err] = cmark.to_html(inp)
    if rc != 0:
        print('[ERRORED (return code %d)]' % rc)
        print(err)
        exit(1)
    elif regex.search(actual):
        print('[PASSED]')
    else:
        print('[FAILED (mismatch)]')
        print(repr(actual))
        exit(1)
Exemple #2
0
def converter(md):
    cmark = CMark(prog=args.program, library_dir=args.library_dir)
    [ec, result, err] = cmark.to_commonmark(md)
    if ec == 0:
        [ec, html, err] = cmark.to_html(result)
        if ec == 0:
            # In the commonmark writer we insert dummy HTML
            # comments between lists, and between lists and code
            # blocks.  Strip these out, since the spec uses
            # two blank lines instead:
            return [ec, re.sub('<!-- end list -->\n', '', html), '']
        else:
            return [ec, html, err]
    else:
        return [ec, result, err]
Exemple #3
0
def converter(md):
  cmark = CMark(prog=args.program, library_dir=args.library_dir)
  [ec, result, err] = cmark.to_commonmark(md)
  if ec == 0:
    [ec, html, err] = cmark.to_html(result)
    if ec == 0:
        # In the commonmark writer we insert dummy HTML
        # comments between lists, and between lists and code
        # blocks.  Strip these out, since the spec uses
        # two blank lines instead:
        return [ec, re.sub('<!-- end list -->\n', '', html), '']
    else:
        return [ec, html, err]
  else:
    return [ec, result, err]
Exemple #4
0
                   (" a</strong> a</em>" * 100000) + "</p>"),
    "nested brackets":
                 (("[" * 50000) + "a" + ("]" * 50000),
                  "<p>" + ("[" * 50000) + "a" + ("]" * 50000) + "</p>")
    }

whitespace_re = re.compile('/s+/')
passed = 0
errored = 0
failed = 0

print "Testing pathological cases:"
for description in pathological:
    print description
    (inp, expected) = pathological[description]
    [rc, actual, err] = cmark.to_html(inp)
    if rc != 0:
        errored += 1
        print description
        print "program returned error code %d" % rc
        print(err)
    elif whitespace_re.sub(' ', actual.rstrip()) == expected.rstrip():
        passed += 1
    else:
        print description, 'failed'
        print(actual)
        failed += 1

print "%d passed, %d failed, %d errored" % (passed, failed, errored)
if (failed == 0 and errored == 0):
    exit(0)
Exemple #5
0
passed = 0
errored = 0
failed = 0

exceptions = {
    'quot': '&quot;',
    'QUOT': '&quot;',

    # These are broken, but I'm not too worried about them.
    'nvlt': '&lt;⃒',
    'nvgt': '&gt;⃒',
}

print("Testing entities:")
for entity, utf8 in entities:
    [rc, actual, err] = cmark.to_html("&{};".format(entity))
    check = exceptions.get(entity, utf8)

    if rc != 0:
        errored += 1
        print(entity, '[ERRORED (return code {})]'.format(rc))
        print(err)
    elif check in actual:
        # print(entity, '[PASSED]') # omit noisy success output
        passed += 1
    else:
        print(entity, '[FAILED]')
        print(repr(actual))
        failed += 1

print("{} passed, {} failed, {} errored".format(passed, failed, errored))
    (("* " * 50000 + "a"),
     re.compile(
         "<ul>\r?\n(<li><ul>\r?\n){49999}<li>a</li>\r?\n</ul>\r?\n(</li>\r?\n</ul>\r?\n){49999}"
     ))
}

whitespace_re = re.compile('/s+/')
passed = 0
errored = 0
failed = 0

#print("Testing pathological cases:")
for description in pathological:
    (inp, regex) = pathological[description]
    start = timer()
    [rc, actual, err] = cmark.to_html(inp)
    end = timer()
    if rc != 0:
        errored += 1
        print('{:35} [ERRORED (return code %d)]'.format(description, rc))
        print(err)
    elif regex.search(actual):
        print('{:35} [PASSED] {:.3f} secs'.format(description, end - start))
        passed += 1
    else:
        print('{:35} [FAILED]'.format(description))
        print(repr(actual))
        failed += 1

print("%d passed, %d failed, %d errored" % (passed, failed, errored))
if (failed == 0 and errored == 0):
Exemple #7
0
passed = 0
errored = 0
failed = 0

exceptions = {
    'quot': '&quot;',
    'QUOT': '&quot;',

    # These are broken, but I'm not too worried about them.
    'nvlt': '&lt;⃒',
    'nvgt': '&gt;⃒',
}

print("Testing entities:")
for entity, utf8 in entities:
    [rc, actual, err] = cmark.to_html("&{};".format(entity))
    check = exceptions.get(entity, utf8)

    if rc != 0:
        errored += 1
        print(entity, '[ERRORED (return code {})]'.format(rc))
        print(err)
    elif check in actual:
        # print(entity, '[PASSED]') # omit noisy success output
        passed += 1
    else:
        print(entity, '[FAILED]')
        print(repr(actual))
        failed += 1

print("{} passed, {} failed, {} errored".format(passed, failed, errored))