def test_escaping():
    """Check if escaping works properly."""
    tree = parse("\\__bar\\__")
    assert tree == nodes.Document([nodes.Text("__bar__")])

    tree = parse("'bar'")
    assert tree == nodes.Document([nodes.Text("'bar'")])
def test_external_links():
    """Test all kind of external links."""
    tree = parse('[http://example.org :blub:][?action=edit]')
    assert tree == nodes.Document([
        nodes.Link('http://example.org', [nodes.Text(':blub:')]),
        nodes.Link('?action=edit')
    ])
def test_autoclosing():
    """Check if the automatic closing works."""
    tree = parse("''foo __bar")
    assert tree == nodes.Document([
        nodes.Emphasized(
            [nodes.Text('foo '),
             nodes.Underline([nodes.Text('bar')])])
    ])
def test_default_itransformer():
    """Test that the default ITransformer implementation returns
    the tree unchanged"""
    transformer = ITransformer()
    tree = nodes.Document(
        [nodes.Text('\nYea'),
         nodes.Strong([nodes.Text('foo')])])
    transformed = transformer.transform(tree)
    eq_(render(transformed, None, 'html'), '\nYea<strong>foo</strong>')
def test_automatic_paragraphs_transformer():
    transformer = AutomaticParagraphs()
    tree = nodes.Document([
        nodes.Text('\nYea'),
        nodes.Strong([nodes.Text('foo')]),
        nodes.Text('\n\nfaz')
    ])
    transformed = transformer.transform(tree)
    eq_(render(transformed, None, 'html'),
        '<p>\nYea<strong>foo</strong></p><p>faz</p>')

    # test paragraph with block tags
    tree = nodes.Document(
        [nodes.Text('\nYea'),
         nodes.Ruler(),
         nodes.Text('\n\nfaz')])
    transformed = transformer.transform(tree)
    eq_(render(transformed, None, 'html'), '<p>\nYea</p><hr><p>faz</p>')
def test_simple_lists():
    """Check if simple lists work."""
    tree = parse(' * foo\n * ^^(bar)^^\n * ,,(baz),,')
    assert tree == nodes.Document([
        nodes.List('unordered', [
            nodes.ListItem([nodes.Text('foo')]),
            nodes.ListItem([nodes.Sup([nodes.Text('bar')])]),
            nodes.ListItem([nodes.Sub([nodes.Text('baz')])])
        ])
    ])
def test_inline_formattings():
    """Simple test for some inline formattings."""
    tree = parse("''baz'' but '''foo''' and __bar__.")
    assert tree == nodes.Document([
        nodes.Emphasized([nodes.Text('baz')]),
        nodes.Text(' but '),
        nodes.Strong([nodes.Text('foo')]),
        nodes.Text(' and '),
        nodes.Underline([nodes.Text('bar')]),
        nodes.Text('.')
    ])
def test_table_cell_classes():
    """Test the table cell classes."""
    tree = parse('||<cellclass=foo>1||<bar>2||')
    assert tree == nodes.Document([
        nodes.Table([
            nodes.TableRow([
                nodes.TableCell([nodes.Text('1')], class_='foo'),
                nodes.TableCell([nodes.Text('2')], class_='bar')
            ])
        ])
    ])
def test_headline_processor_transformer():
    transformer = HeadlineProcessor()
    tree = nodes.Document([
        nodes.Headline(1, [nodes.Text('foo')], 'foo'),
        nodes.Paragraph([nodes.Text('some text')]),
        nodes.Headline(2, [nodes.Text('faz')], ''),
        nodes.Paragraph([nodes.Text('other text')]),
        nodes.Headline(1, [nodes.Text('foo')], 'foo')
    ])

    expected = nodes.Document([
        nodes.Headline(1, [nodes.Text('foo')], 'foo'),
        nodes.Paragraph([nodes.Text('some text')]),
        nodes.Headline(2, [nodes.Text('faz')], 'empty-headline'),
        nodes.Paragraph([nodes.Text('other text')]),
        nodes.Headline(1, [nodes.Text('foo')], 'foo-2')
    ])

    transformed = transformer.transform(tree)
    eq_(transformed, expected)
示例#10
0
def test_table_row_classes():
    """Test the table row class assignments."""
    tree = parse('||<foo>1||2||3')
    assert tree == nodes.Document([
        nodes.Table([
            nodes.TableRow([
                nodes.TableCell([nodes.Text('1')]),
                nodes.TableCell([nodes.Text('2')]),
                nodes.TableCell([nodes.Text('3')])
            ],
                           class_='foo')
        ])
    ])
示例#11
0
def test_span_table():
    """Test tables with col/rowspans."""
    tree = parse('||<-2>1||<|2>2||\n||3||4||')
    assert tree == nodes.Document([
        nodes.Table([
            nodes.TableRow([
                nodes.TableCell([nodes.Text('1')], colspan=2),
                nodes.TableCell([nodes.Text('2')], rowspan=2)
            ]),
            nodes.TableRow([
                nodes.TableCell([nodes.Text('3')]),
                nodes.TableCell([nodes.Text('4')])
            ])
        ])
    ])
示例#12
0
 def parse(self):
     """
     Starts the parsing process.  This sets the dirty flag which means that
     you have to create a new parser after the parsing.
     """
     if self.is_dirty:
         raise RuntimeError('the parser is dirty. reinstanciate it.')
     self.is_dirty = True
     stream = self.lexer.tokenize(self.string)
     result = nodes.Document()
     while not stream.eof:
         result.children.append(self.parse_node(stream))
     for transformer in self.transformers:
         result = transformer.transform(result)
     return result
示例#13
0
def test_table_alignment():
    """Check if table alignment parameters work."""
    tree = parse('||<:~>1||<(v>2||<)^>3||')
    assert tree == nodes.Document([
        nodes.Table([
            nodes.TableRow([
                nodes.TableCell([nodes.Text('1')],
                                align='center',
                                valign='middle'),
                nodes.TableCell([nodes.Text('2')],
                                align='left',
                                valign='bottom'),
                nodes.TableCell([nodes.Text('3')], align='right', valign='top')
            ])
        ])
    ])
示例#14
0
def test_simple_table():
    """Test the simple table markup."""
    tree = parse('||1||2||3||\n||4||5||6||')
    assert tree == nodes.Document([
        nodes.Table([
            nodes.TableRow([
                nodes.TableCell([nodes.Text('1')]),
                nodes.TableCell([nodes.Text('2')]),
                nodes.TableCell([nodes.Text('3')])
            ]),
            nodes.TableRow([
                nodes.TableCell([nodes.Text('4')]),
                nodes.TableCell([nodes.Text('5')]),
                nodes.TableCell([nodes.Text('6')])
            ])
        ])
    ])
示例#15
0
def test_nested_lists():
    """Check if nested lists work."""
    tree = parse(' * foo\n  1. bar\n   a. baz\n * blub')
    assert tree == nodes.Document([
        nodes.List('unordered', [
            nodes.ListItem([
                nodes.Text('foo'),
                nodes.List('arabic', [
                    nodes.ListItem([
                        nodes.Text('bar'),
                        nodes.List('alphalower',
                                   [nodes.ListItem([nodes.Text('baz')])])
                    ])
                ])
            ]),
            nodes.ListItem([nodes.Text('blub')])
        ])
    ])
示例#16
0
def test_pre():
    """Test normal pre blocks."""
    tree = parse('{{{\nfoo\n}}}')
    assert tree == nodes.Document([nodes.Preformatted([nodes.Text('foo')])])
示例#17
0
def test_breakers():
    """Test the ruler."""
    tree = parse('foo\n-----------------')
    assert tree == nodes.Document([nodes.Text('foo\n'), nodes.Ruler()])