Ejemplo n.º 1
0
def test_plain_text(markdown):
    text = "Simple example"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    expected = [ast.Paragraph([ast.Text(text)])]
    assert_tree(parser.tree, expected, markdown)
Ejemplo n.º 2
0
def test_bold_italic():
    text = "***Bold Italics***"
    assert tokenize(text) == [
        Token("BOLD_ITALIC", value="***", line=1, column=0),
        Token("TEXT", value="Bold Italics", line=1, column=3),
        Token("BOLD_ITALIC", value="***", line=1, column=15),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 3
0
def test_strikethrough():
    text = "~~Strikethrough~~"
    assert tokenize(text) == [
        Token("STRIKETHROUGH", value="~~", line=1, column=0),
        Token("TEXT", value="Strikethrough", line=1, column=2),
        Token("STRIKETHROUGH", value="~~", line=1, column=15),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 4
0
def test_underline():
    text = "__Underline__"
    assert tokenize(text) == [
        Token("UNDERLINE", value="__", line=1, column=0),
        Token("TEXT", value="Underline", line=1, column=2),
        Token("UNDERLINE", value="__", line=1, column=11),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 5
0
def test_italic_alt():
    text = "*Italic*"
    assert tokenize(text) == [
        Token("ITALIC", value="*", line=1, column=0),
        Token("TEXT", value="Italic", line=1, column=1),
        Token("ITALIC", value="*", line=1, column=7),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 6
0
def test_bold():
    text = "**Bold**"
    assert tokenize(text) == [
        Token("BOLD", value="**", line=1, column=0),
        Token("TEXT", value="Bold", line=1, column=2),
        Token("BOLD", value="**", line=1, column=6),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 7
0
def test_inline_code():
    text = "`**test_`"
    assert tokenize(text) == [
        Token("INLINE_CODE", value="`", line=1, column=0),
        Token("TEXT", value="**test_", line=1, column=1),
        Token("INLINE_CODE", value="`", line=1, column=8),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 8
0
def test_multiline_quote():
    text = ">>> This should all\n be part of it"
    assert tokenize(text) == [
        Token("BLOCK_QUOTE", value=">>>", line=1, column=0),
        Token("TEXT", value=" This should all", line=1, column=3),
        Token("NEWLINE", value="\n", line=2, column=19),
        Token("TEXT", value=" be part of it", line=2, column=0),
        Token("EOF", value="", line=2, column=len(text)),
    ]
Ejemplo n.º 9
0
def test_inline_quote():
    text = "> this is part of it\nThis should not be"
    assert tokenize(text) == [
        Token("INLINE_QUOTE", value=">", line=1, column=0),
        Token("TEXT", value=" this is part of it", line=1, column=1),
        Token("NEWLINE", value="\n", line=2, column=20),
        Token("TEXT", value="This should not be", line=2, column=0),
        Token("EOF", value="", line=2, column=len(text)),
    ]
Ejemplo n.º 10
0
def test_spoiler():
    text = "this is a ||spoiler||"
    assert tokenize(text) == [
        Token("TEXT", value="this is a ", line=1, column=0),
        Token("SPOILER", value="||", line=1, column=10),
        Token("TEXT", value="spoiler", line=1, column=12),
        Token("SPOILER", value="||", line=1, column=19),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 11
0
def test_bold_inline():
    text = "Is this **Bold**"
    assert tokenize(text) == [
        Token("TEXT", value="Is this ", line=1, column=0),
        Token("BOLD", value="**", line=1, column=8),
        Token("TEXT", value="Bold", line=1, column=10),
        Token("BOLD", value="**", line=1, column=14),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 12
0
def test_bold_alt_text(markdown):
    text = "**formatted**"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [ast.Paragraph([ast.BoldText(ast.Text("formatted"))])],
        markdown=markdown,
    )
Ejemplo n.º 13
0
def test_underline_bold_italics():
    text = "__***underline bold italics***__"
    assert tokenize(text) == [
        Token("UNDERLINE", value="__", line=1, column=0),
        Token("BOLD_ITALIC", value="***", line=1, column=2),
        Token("TEXT", value="underline bold italics", line=1, column=5),
        Token("BOLD_ITALIC", value="***", line=1, column=27),
        Token("UNDERLINE", value="__", line=1, column=30),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 14
0
def test_underline_bold():
    text = "__**underline bold**__"
    assert tokenize(text) == [
        Token("UNDERLINE", value="__", line=1, column=0),
        Token("BOLD", value="**", line=1, column=2),
        Token("TEXT", value="underline bold", line=1, column=4),
        Token("BOLD", value="**", line=1, column=18),
        Token("UNDERLINE", value="__", line=1, column=20),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 15
0
def test_underline_italic():
    text = "__*underline italics*__"
    assert tokenize(text) == [
        Token("UNDERLINE", value="__", line=1, column=0),
        Token("ITALIC", value="*", line=1, column=2),
        Token("TEXT", value="underline italics", line=1, column=3),
        Token("ITALIC", value="*", line=1, column=20),
        Token("UNDERLINE", value="__", line=1, column=21),
        Token("EOF", value="", line=1, column=len(text)),
    ]
Ejemplo n.º 16
0
def test_italic_text(text):
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph(
                [ast.Text("This is "),
                 ast.ItalicText(ast.Text("formatted"))])
        ],
    )
Ejemplo n.º 17
0
def test_inline_quote(markdown):
    text = "> This is a quote.\nThis isn't part of it."
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([ast.InlineQuote(ast.Text(" This is a quote."))]),
            ast.Paragraph([ast.Text("This isn't part of it.")]),
        ],
        markdown=markdown,
    )
Ejemplo n.º 18
0
def test_code_block():
    text = """```markdown
    This is **meta** and should be ignored```"""
    assert tokenize(text) == [
        Token("CODE_BLOCK", value="```markdown", line=1, column=0),
        Token(
            "TEXT",
            value="\n    This is **meta** and should be ignored",
            line=2,
            column=11,
        ),
        Token("CODE_BLOCK", value="```", line=2, column=42),
        Token("TEXT", value="", line=2, column=45),
        Token("EOF", value="", line=2, column=len(text)),
    ]
Ejemplo n.º 19
0
def test_block_quote(markdown):
    text = ">>> This is a quote.\nThis should be part of it."
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.BlockQuote(
                    ast.Text(" This is a quote.\nThis should be part of it."))
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 20
0
def test_spoiler_text(markdown):
    text = "The FBI says ||redacted here||."
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("The FBI says "),
                ast.SpoilerText(ast.Text("redacted here")),
                ast.Text("."),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 21
0
def test_paragraph_text(markdown):
    text = (
        "This is the first paragraph.\nThis is the second one.\nThis is the third one."
    )
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([ast.Text("This is the first paragraph.")]),
            ast.Paragraph([ast.Text("This is the second one.")]),
            ast.Paragraph([ast.Text("This is the third one.")]),
        ],
        markdown=markdown,
    )
Ejemplo n.º 22
0
def test_inline_code(markdown):
    text = "Run this command `echo hello`."
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("Run this command "),
                ast.InlineCode(ast.Text("echo hello")),
                ast.Text("."),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 23
0
def test_strikethrough_text(markdown):
    text = "A ~~strikethrough~~ example"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("A "),
                ast.StrikethroughText(ast.Text("strikethrough")),
                ast.Text(" example"),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 24
0
def test_underline_bold_text(markdown):
    text = "An __**underline bold**__ example"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("An "),
                ast.UnderlineText(ast.BoldText(ast.Text("underline bold"))),
                ast.Text(" example"),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 25
0
def test_underline_italics_text(markdown):
    text = "An __*underline italics*__ example"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("An "),
                ast.UnderlineText(ast.ItalicText(
                    ast.Text("underline italics"))),
                ast.Text(" example"),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 26
0
def test_code_block(markdown):
    text = """```markdown
    This **is** _meta_
    ```"""
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.CodeBlock(ast.Text("\n    This **is** _meta_\n    "),
                              md_tag="```markdown"),
                ast.Text(""),
            ])
        ],
        markdown=markdown,
    )
Ejemplo n.º 27
0
def test_bold_italics_text(markdown):
    text = "Here I _am_ in the **light** of ***day***\nLet the storm rage on"
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("Here I "),
                ast.ItalicText(ast.Text("am"), md_tag="_"),
                ast.Text(" in the "),
                ast.BoldText(ast.Text("light")),
                ast.Text(" of "),
                ast.BoldText(ast.ItalicText(ast.Text("day"))),
            ]),
            ast.Paragraph([ast.Text("Let the storm rage on")]),
        ],
        markdown=markdown,
    )
Ejemplo n.º 28
0
def test_multiple_formatted_text(markdown):
    text = "An __*underline italics*__ example.\nI **am** depressed."
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("An "),
                ast.UnderlineText(ast.ItalicText(
                    ast.Text("underline italics"))),
                ast.Text(" example."),
            ]),
            ast.Paragraph([
                ast.Text("I "),
                ast.BoldText(ast.Text("am")),
                ast.Text(" depressed.")
            ]),
        ],
        markdown=markdown,
    )
Ejemplo n.º 29
0
def test_complex_markup(markdown):
    text = load_file("discord.md")
    tokens = tokenize(text)
    parser = Parser(tokens)
    parser.parse()
    assert_tree(
        parser.tree,
        [
            ast.Paragraph([
                ast.Text("["),
                ast.ItalicText(
                    ast.Text("Tiger looks at Kalahan contemplatively"),
                    md_tag="_"),
                ast.Text("]"),
            ]),
            ast.Paragraph([
                ast.Text("Tiger: ["),
                ast.ItalicText(ast.Text("quietly"), md_tag="_"),
                ast.Text("] "),
                ast.CodeBlock(
                    ast.Text("\n= Had only Bull not gotten to you first... ="),
                    md_tag="```asciidoc",
                ),
            ]),
            ast.Paragraph([
                ast.Text("Tiger: "),
                ast.CodeBlock(
                    ast.Text(
                        "\n= You may do so. I simply wish her safe in her den. But I cannot and will not force you to do anything. And my power in the physical plane is greatly limited without one to call me mentor. ="  # noqa
                    ),
                    md_tag="```asciidoc",
                ),
            ]),
        ],
        markdown=markdown,
    )