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)
示例#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]
示例#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]
示例#4
0
import re
import argparse
import sys
import platform
from cmark import CMark

if __name__ == "__main__":
    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)

pathological = {
    "nested strong emph":
                (("*a **a " * 100000) + "b" + (" a** a*" * 100000),
                 "<p>" + ("<em>a <strong>a " * 100000) + "b" +
                   (" 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
示例#5
0

if __name__ == "__main__":
    if args.debug_normalization:
        out(normalize_html(sys.stdin.read()))
        exit(0)

    all_tests = get_tests(args.spec)
    if args.pattern:
        pattern_re = re.compile(args.pattern, re.IGNORECASE)
    else:
        pattern_re = re.compile('.')
    tests = [
        test for test in all_tests
        if re.search(pattern_re, test['section']) and (
            not args.number or test['example'] == args.number)
    ]
    if args.dump_tests:
        out(json.dumps(tests, ensure_ascii=False, indent=2))
        exit(0)
    else:
        skipped = len(all_tests) - len(tests)
        converter = CMark(prog=args.program,
                          library_dir=args.library_dir).to_html
        result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': skipped}
        for test in tests:
            do_test(converter, test, args.normalize, result_counts)
        out("{pass} passed, {fail} failed, {error} errored, {skip} skipped\n".
            format(**result_counts))
        exit(result_counts['fail'] + result_counts['error'])
示例#6
0
        code = f.read()
    entities = []
    for entity, utf8 in re.findall(regex, code, re.MULTILINE):
        utf8 = bytes(map(int, utf8.split(", ")[:-1])).decode('utf-8')
        entities.append((entity, utf8))
    return entities

if __name__ == "__main__":
    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)

entities = get_entities()

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;⃒',
}
示例#7
0
        if re.search(pattern_re, test['section']):
            result = do_test(test, normalize)
            if result == 'pass':
                passed += 1
            elif result == 'fail':
                failed += 1
            else:
                errored += 1
        else:
            skipped += 1
    print "%d passed, %d failed, %d errored, %d skipped" % (passed, failed,
                                                            errored, skipped)
    return (failed == 0 and errored == 0)


if __name__ == "__main__":
    if args.debug_normalization:
        print normalize_html(sys.stdin.read())
        exit(0)

    tests = get_tests(args.spec)
    if args.dump_tests:
        print json.dumps(tests, ensure_ascii=False, indent=2)
        exit(0)
    else:
        cmark = CMark(prog=args.program, library_dir=args.library_dir)
        if do_tests(cmark, tests, args.pattern, args.normalize):
            exit(0)
        else:
            exit(1)
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Run cmark tests.')
    parser.add_argument('-p',
                        '--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)

# list of pairs consisting of input and a regex that must match the output.
pathological = {
    # note - some pythons have limit of 65535 for {num-matches} in re.
    "U+0000": ("abc\u0000de\u0000", re.compile("abc\ufffd?de\ufffd?")),
    "U+FEFF (Unicode BOM)": ("\ufefffoo", re.compile("<p>foo</p>")),
    "nested strong emph":
    (("*a **a " * 65000) + "b" + (" a** a*" * 65000),
     re.compile("(<em>a <strong>a ){65000}b( a</strong> a</em>){65000}")),
    "many emph closers with no openers": (("a_ " * 65000),
                                          re.compile("(a[_] ){64999}a_")),
    "many emph openers with no closers": (("_a " * 65000),
                                          re.compile("(_a ){64999}_a")),
    "many 3-emph openers with no closers":
    (("a***" * 65000), re.compile("(a<em><strong>a</strong></em>){32500}")),
示例#9
0
                    start_line = line_number - 1
                markdown_lines.append(line)
            elif state == 2:
                html_lines.append(line)
            elif state == 0 and re.match(header_re, line):
                headertext = header_re.sub('', line).strip()
    return tests

if __name__ == "__main__":
    if args.debug_normalization:
        out(normalize_html(sys.stdin.read()))
        exit(0)

    all_tests = get_tests(args.spec)
    if args.pattern:
        pattern_re = re.compile(args.pattern, re.IGNORECASE)
    else:
        pattern_re = re.compile('.')
    tests = [ test for test in all_tests if re.search(pattern_re, test['section']) and (not args.number or test['example'] == args.number) ]
    if args.dump_tests:
        out(json.dumps(tests, indent=2))
        exit(0)
    else:
        skipped = len(all_tests) - len(tests)
        converter = CMark(prog=args.program, library_dir=args.library_dir, extensions=args.extensions).to_html
        result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': skipped}
        for test in tests:
            do_test(converter, test, args.normalize, result_counts)
        out("{pass} passed, {fail} failed, {error} errored, {skip} skipped\n".format(**result_counts))
        exit(result_counts['fail'] + result_counts['error'])
示例#10
0

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)

entities = get_entities()

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;⃒',
}