Example #1
0
def test_newline_in_link_text():
    """http://code.pediapress.com/wiki/ticket/906"""
    s = "[[Albert Einstein | Albert\nEinstein]]"
    r = core.parse_txt(s)
    core.show(r)
    links = core.walknodel(r, lambda x: x.type == T.t_complex_link)
    assert links, "no links found"
Example #2
0
def test_no_row_modifier():
    s = "{|\n|foo||bar\n|}"
    r = core.parse_txt(s)
    core.show(r)
    cells = list(core.walknode(r, lambda x: x.type == core.T.t_complex_table_cell))
    print "CELLS:", cells
    assert len(cells) == 2, "expected 2 cells"
Example #3
0
def test_newline_in_link_text():
    """http://code.pediapress.com/wiki/ticket/906"""
    s = "[[Albert Einstein | Albert\nEinstein]]"
    r = core.parse_txt(s)
    core.show(r)
    links = core.walknodel(r, lambda x: x.type == T.t_complex_link)
    assert links, "no links found"
Example #4
0
def parse_txt(env, raw, **kwargs):
    sub = core.parse_txt(raw, **kwargs)

    article = T(type=T.t_complex_article, start=0, len=0, children=sub)
    compat._change_classes(article)
    rec_deb(article)

    return article
Example #5
0
def test_div_vs_section():
    r = core.parse_txt(
        """== foo <div style="background-color:#ff0000"> bar ==
baz
"""
    )
    core.show(r)
    assert r[0].level == 2, "expected a section"
Example #6
0
def test_span_vs_lines():
    r = core.parse_txt("""* foo <span> bar
* baz
""")
    core.show(r)

    ul = core.walknodel(r, lambda x: x.tagname == "ul")
    assert len(ul) == 1, "expected one list"
Example #7
0
def test_references_with_paragraphs():
    s = "<references>\n\n<ref>bla</ref>\n\n</references>"
    r = core.parse_txt(s)
    core.show(r)
    references = core.walknodel(r, lambda x: x.tagname == "references")
    assert len(references) == 1, "expected exactly one references node, got %s" % len(references)
    refs = core.walknodel(references, lambda x: x.tagname == "ref")
    assert len(refs) == 1, "expected exactly one ref node inside the references node, got %s" % len(refs)
Example #8
0
def test_span_vs_lines():
    r = core.parse_txt("""* foo <span> bar
* baz
""")
    core.show(r)

    ul = core.walknodel(r, lambda x: x.tagname == "ul")
    assert len(ul) == 1, "expected one list"
Example #9
0
def test_no_row_modifier():
    s = "{|\n|foo||bar\n|}"
    r = core.parse_txt(s)
    core.show(r)
    cells = list(
        core.walknode(r, lambda x: x.type == core.T.t_complex_table_cell))
    print "CELLS:", cells
    assert len(cells) == 2, "expected 2 cells"
Example #10
0
def test_style_tag_closes_same():
    r = core.parse_txt("foo<u>bar<u>baz")
    core.show(r)
    utags = core.walknodel(r, lambda x: x.tagname == "u")

    print "utags:", utags
    txt = "".join([T.join_as_text(x.children) for x in utags])
    print "txt:", txt
    assert txt == u"bar"
Example #11
0
def test_style_tag_closes_same():
    r = core.parse_txt("foo<u>bar<u>baz")
    core.show(r)
    utags = core.walknodel(r, lambda x: x.tagname == "u")

    print "utags:", utags
    txt = "".join([T.join_as_text(x.children) for x in utags])
    print "txt:", txt
    assert txt == u"bar"
Example #12
0
def test_parse_para_vs_preformatted():
    s = ' foo\n\nbar\n'
    r = core.parse_txt(s)
    core.show(r)
    pre = list(core.walknode(r, lambda x: x.type == core.T.t_complex_preformatted))[0]
    core.show(pre)
    textnodes = list(core.walknode(pre, lambda x: x.type == core.T.t_text))
    txt = ''.join([x.text for x in textnodes])
    assert u'bar' not in txt
Example #13
0
def test_parse_para_vs_preformatted():
    s = ' foo\n\nbar\n'
    r = core.parse_txt(s)
    core.show(r)
    pre = list(
        core.walknode(r, lambda x: x.type == core.T.t_complex_preformatted))[0]
    core.show(pre)
    textnodes = list(core.walknode(pre, lambda x: x.type == core.T.t_text))
    txt = ''.join([x.text for x in textnodes])
    assert u'bar' not in txt
Example #14
0
def test_comment_in_gallery():
    """http://code.pediapress.com/wiki/ticket/741"""
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif|capshun<!--comment-->
</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "comment" not in txt, "comment not stripped"
Example #15
0
def test_duplicate_nesting():
    s = u"""<b>
[[foo|bar]] between
</b>"""
    r = core.parse_txt(s)
    bolds = list(core.walknode(r, lambda x: x.tagname == "b"))
    core.show(bolds)

    for x in bolds:
        for y in x.children or []:
            assert y.tagname != "b"
Example #16
0
def test_duplicate_nesting():
    s = u"""<b>
[[foo|bar]] between
</b>"""
    r = core.parse_txt(s)
    bolds = list(core.walknode(r, lambda x: x.tagname == "b"))
    core.show(bolds)

    for x in bolds:
        for y in x.children or []:
            assert y.tagname != "b"
Example #17
0
def test_parserfun_in_gallery():
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif| capshun {{#if: 1|yes}}

</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "capshun yes" in txt, "#if failed to expand"
Example #18
0
def test_comment_in_gallery():
    """http://code.pediapress.com/wiki/ticket/741"""
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif|capshun<!--comment-->
</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "comment" not in txt, "comment not stripped"
Example #19
0
def test_parserfun_in_gallery():
    r = core.parse_txt("""<gallery>
Image:ACDC_logo.gif| capshun {{#if: 1|yes}}

</gallery>
""")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r[0].children, lambda x: True))
    print "TXT:", repr(txt)
    assert "capshun" in txt, "bad text??"
    assert "capshun yes" in txt, "#if failed to expand"
Example #20
0
def test_span_vs_paragraph():
    """http://code.pediapress.com/wiki/ticket/751"""
    r = core.parse_txt("foo<span>\n\nbar</span>\n\n")
    core.show(r)
    p = [x for x in r if x.tagname == "p"]
    print "PARAS:", p
    assert len(p) == 2, "expected two paragraphs"

    txts = [T.join_as_text(x.children) for x in p]
    print txts
    assert "foo" in txts[0]
    assert "bar" in txts[1]
Example #21
0
def test_named_url_in_double_brackets():
    """http://code.pediapress.com/wiki/ticket/556"""
    r = core.parse_txt("[[http://foo.com baz]]")
    core.show(r)
    named = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(named) == 1, "expected a named url"
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)
    assert "[" in txt, "missing ["
    assert "]" in txt, "missing ]"
    assert "[[" not in txt, "bad text"
    assert "]]" not in txt, "bad text"
Example #22
0
def test_span_vs_paragraph():
    """http://code.pediapress.com/wiki/ticket/751"""
    r = core.parse_txt("foo<span>\n\nbar</span>\n\n")
    core.show(r)
    p = [x for x in r if x.tagname == "p"]
    print "PARAS:", p
    assert len(p) == 2, "expected two paragraphs"

    txts = [T.join_as_text(x.children) for x in p]
    print txts
    assert "foo" in txts[0]
    assert "bar" in txts[1]
Example #23
0
def test_named_url_in_double_brackets():
    """http://code.pediapress.com/wiki/ticket/556"""
    r = core.parse_txt("[[http://foo.com baz]]")
    core.show(r)
    named = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(named) == 1, "expected a named url"
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)
    assert "[" in txt, "missing ["
    assert "]" in txt, "missing ]"
    assert "[[" not in txt, "bad text"
    assert "]]" not in txt, "bad text"
Example #24
0
def test_link_vs_namedurl():
    r = core.parse_txt("[[acdc [http://web.de bla]]")
    core.show(r)
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)

    assert "[[acdc " in txt, "wrong text"
    assert txt.endswith("]"), "wrong text"

    assert r[0].type != T.t_complex_link, "should not be an article link"

    urls = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(urls) == 1, "no named url found"
Example #25
0
def test_ref_inside_caption():
    s = """
{|
|+ table capshun <ref>references fun</ref>
| hey || ho
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)
    refs = core.walknodel(cap, lambda x: x.tagname == "ref")
    assert refs
Example #26
0
def test_references_with_paragraphs():
    s = "<references>\n\n<ref>bla</ref>\n\n</references>"
    r = core.parse_txt(s)
    core.show(r)
    references = core.walknodel(r, lambda x: x.tagname == "references")
    assert len(
        references
    ) == 1, "expected exactly one references node, got %s" % len(references)
    refs = core.walknodel(references, lambda x: x.tagname == "ref")
    assert len(
        refs
    ) == 1, "expected exactly one ref node inside the references node, got %s" % len(
        refs)
Example #27
0
def test_ref_inside_caption():
    s = """
{|
|+ table capshun <ref>references fun</ref>
| hey || ho
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)
    refs = core.walknodel(cap, lambda x: x.tagname == "ref")
    assert refs
Example #28
0
def test_link_vs_namedurl():
    r = core.parse_txt("[[acdc [http://web.de bla]]")
    core.show(r)
    txt = T.join_as_text(r)
    print "TXT:", repr(txt)

    assert "[[acdc " in txt, "wrong text"
    assert txt.endswith("]"), "wrong text"

    assert r[0].type != T.t_complex_link, "should not be an article link"

    urls = core.walknodel(r, lambda x: x.type == T.t_complex_named_url)
    assert len(urls) == 1, "no named url found"
Example #29
0
def test_ul_inside_star():
    """http://code.pediapress.com/wiki/ticket/735"""
    r=core.parse_txt("""
* foo
* bar </ul> baz
""")
    core.show(r)
    ul = core.walknodel(r, lambda x: x.tagname=="ul")
    def baz(x):
        if x.text and "baz" in x.text:
            return True
        
    b1 = core.walknodel(ul, baz)
    b2 = core.walknodel(r, baz)
    
    assert not b1, "baz should not be inside ul"
    assert b2,  "baz missing"
Example #30
0
def test_ul_inside_star():
    """http://code.pediapress.com/wiki/ticket/735"""
    r = core.parse_txt("""
* foo
* bar </ul> baz
""")
    core.show(r)
    ul = core.walknodel(r, lambda x: x.tagname == "ul")

    def baz(x):
        if x.text and "baz" in x.text:
            return True

    b1 = core.walknodel(ul, baz)
    b2 = core.walknodel(r, baz)

    assert not b1, "baz should not be inside ul"
    assert b2, "baz missing"
Example #31
0
def test_tr_inside_caption():
    """http://code.pediapress.com/wiki/ticket/709"""
    s = """
{|
|+ table capshun <tr><td>bla</td></tr>
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)

    rows = core.walknodel(r, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 1, "no rows found"

    rows = core.walknodel(cap, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 0, "row in table caption found"
Example #32
0
def test_tr_inside_caption():
    """http://code.pediapress.com/wiki/ticket/709"""
    s = """
{|
|+ table capshun <tr><td>bla</td></tr>
|}"""
    r = core.parse_txt(s)
    core.show(r)
    cap = core.walknodel(r, lambda x: x.type == T.t_complex_caption)[0]
    print "caption:"
    core.show(cap)

    rows = core.walknodel(r, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 1, "no rows found"

    rows = core.walknodel(cap, lambda x: x.type == T.t_complex_table_row)
    print "ROWS:", rows
    assert len(rows) == 0, "row in table caption found"
Example #33
0
def test_tab_table():
    s = """
\t{|
|-
\t| cell1
| cell2
\t|}after
"""
    r = core.parse_txt(s)
    core.show(r)
    tables = []

    def allowed(node):
        retval = bool(tables)
        if node.type == T.t_complex_table:
            tables.append(node)
        return retval
    nodes = [x for x in r if allowed(x)]
    assert nodes, "bad  or no table"

    cells = core.walknodel(r, lambda x: x.type == T.t_complex_table_cell)
    assert len(cells) == 2, "expected two cells"
Example #34
0
def test_tab_table():
    s = """
\t{|
|-
\t| cell1
| cell2
\t|}after
"""
    r = core.parse_txt(s)
    core.show(r)
    tables = []

    def allowed(node):
        retval = bool(tables)
        if node.type == T.t_complex_table:
            tables.append(node)
        return retval

    nodes = [x for x in r if allowed(x)]
    assert nodes, "bad  or no table"

    cells = core.walknodel(r, lambda x: x.type == T.t_complex_table_cell)
    assert len(cells) == 2, "expected two cells"
Example #35
0
def test_inputbox():
    s = "</inputbox>"

    r = core.parse_txt(s)
    core.show(r)
Example #36
0
def test_div_vs_link():
    r = core.parse_txt(
        """[[File:ACDC_logo.gif|thumb| <div style="background-color:#fee8ab"> foo ]]""")
    core.show(r)
    assert r[0].type == T.t_complex_link, "expected an image link"
Example #37
0
def test_link_vs_section():
    r = core.parse_txt("[[acdc\n== foo ]] ==\n")
    core.show(r)
    assert r[0].type != T.t_complex_link, "should not parse a link here"
Example #38
0
def test_div_vs_section():
    r = core.parse_txt("""== foo <div style="background-color:#ff0000"> bar ==
baz
""")
    core.show(r)
    assert r[0].level == 2, "expected a section"
Example #39
0
def parse_txt(raw, **kwargs):
    sub = core.parse_txt(raw, **kwargs)
    article = T(type=T.t_complex_article, start=0, len=0, children=sub)
    _change_classes(article)
    return article
Example #40
0
def test_ref_drop_text_newlines():
    """http://code.pediapress.com/wiki/ticket/812"""
    r = core.parse_txt("<ref>bar\n\n</ref>")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r, lambda x: 1))
    assert "bar" in txt, "text dropped"
Example #41
0
def test_ref_no_newline():
    s = u"""<ref>* no item</ref>"""
    r = core.parse_txt(s)
    core.show(r)
    linodes = list(core.walknode(r, lambda x: x.tagname == "li"))
    assert not linodes
Example #42
0
def test_ebad_in_text():
    txt = T.join_as_text(core.parse_txt(u"foo\uebadbar"))
    assert txt=="foobar", "\uebad should be stripped"
Example #43
0
def test_inputbox():
    s = "</inputbox>"

    r = core.parse_txt(s)
    core.show(r)
Example #44
0
def test_ref_no_newline():
    s = u"""<ref>* no item</ref>"""
    r = core.parse_txt(s)
    core.show(r)
    linodes = list(core.walknode(r, lambda x: x.tagname == "li"))
    assert not linodes
Example #45
0
def test_last_unitialized():
    """last variable was not initialized in fix_urllink_inside_link"""
    core.parse_txt("]]]")
Example #46
0
def test_hashmark_link():
    r = core.parse_txt("[[#foo]]")
    core.show(r)
    assert r[0].type == T.t_complex_link, "not a link"
Example #47
0
def test_last_unitialized():
    """last variable was not initialized in fix_urllink_inside_link"""
    core.parse_txt("]]]")
Example #48
0
def test_div_vs_link():
    r = core.parse_txt(
        """[[File:ACDC_logo.gif|thumb| <div style="background-color:#fee8ab"> foo ]]"""
    )
    core.show(r)
    assert r[0].type == T.t_complex_link, "expected an image link"
Example #49
0
def test_hashmark_link():
    r = core.parse_txt("[[#foo]]")
    core.show(r)
    assert r[0].type == T.t_complex_link, "not a link"
Example #50
0
def test_link_vs_section():
    r = core.parse_txt("[[acdc\n== foo ]] ==\n")
    core.show(r)
    assert r[0].type != T.t_complex_link, "should not parse a link here"
Example #51
0
def parse_txt(*args, **kwargs):
    p = core.parse_txt(*args, **kwargs)
    core.show(p)
    return p
Example #52
0
def test_ref_drop_text_newlines():
    """http://code.pediapress.com/wiki/ticket/812"""
    r = core.parse_txt("<ref>bar\n\n</ref>")
    core.show(r)
    txt = T.join_as_text(core.walknodel(r, lambda x: 1))
    assert "bar" in txt, "text dropped"
Example #53
0
def test_ebad_in_text():
    txt = T.join_as_text(core.parse_txt(u"foo\uebadbar"))
    assert txt == "foobar", "\uebad should be stripped"
Example #54
0
def parse_txt(*args, **kwargs):
    p = core.parse_txt(*args, **kwargs)
    core.show(p)
    return p