Exemplo n.º 1
0
def test_parse_header():
    assert unwind(parse(Standard, '# Header ![img](imgurl)')) == [
        'div',
        [
            'h1',
            [
                'a.anchor', {
                    'id': 'header-imgimgurl'
                }, 'Header ',
                [
                    'img.full-image', {
                        'alt': 'img',
                        'src': 'imgurl',
                        'style': {
                            'margin': '0 auto',
                            'display': 'block',
                            'max-width': '100%'
                        }
                    }
                ]
            ]
        ]
    ]
    assert unwind(parse(Standard, '# h1\n## h2\n### h3', Paragraphs)) == [
        'div', ['h1', ['a.anchor', {
            'id': 'h1'
        }, 'h1']], ['h2', ['a.anchor', {
            'id': 'h2'
        }, 'h2']], ['h3', ['a.anchor', {
            'id': 'h3'
        }, 'h3']]
    ]
Exemplo n.º 2
0
def test_singlegroups(s: str):
    assert unwind(parse(Registry(NoopBlock, Bold), '*' + s + '*',
                        NoopBlock)) == ['div', ['strong', {}, s]]
    assert unwind(parse(Registry(NoopBlock, Italic), '_' + s + '_',
                        NoopBlock)) == ['div', ['em', {}, s]]
    assert unwind(
        parse(Registry(NoopBlock, Monospace), '`' + s + '`',
              NoopBlock)) == ['div', ['code', {}, s]]
Exemplo n.º 3
0
def test_parseblock_nestingsub_multiple():
  assert unwind(parseblock(sample + [IdentityBlock], IdentityBlock,
                           '*hello*\n---paragraphs\nhello\n---paragraphs\nhello again\n...\n...\n')) == [
           'div', ['strong', {}, 'hello'], '\n', ['div', ['p', 'hello'], ['div', ['p', 'hello again']]]]

  assert unwind(parseblock(sample, Paragraphs,
                           ' *hello*\n---paragraphs\nhello\n---paragraphs\n*hello* again\n...\n...\n')) == [
           'div', ['p', ' ', ['strong', {}, 'hello']],
           ['div', ['p', 'hello'], ['div', ['p', ['strong', {}, 'hello'], ' again']]]]
Exemplo n.º 4
0
def test_parse_header():
  assert unwind(parse(Standard, '# Header ![img](imgurl)')) == [
    'div', ['h1', ['a', {'name': 'header-imgimgurl'},
                   'Header ', ['img', {'alt': 'img', 'src': 'imgurl',
    'style': {'margin': '0 auto', 'display': 'block', 'max-width': '100%'}}]]]]
  assert unwind(
    parse(Standard, '# h1\n## h2\n### h3', Paragraphs)) == [
           'div', ['h1', ['a', {'name': 'h1'}, 'h1']],
                  ['h2', ['a', {'name': 'h2'}, 'h2']],
                  ['h3', ['a', {'name': 'h3'}, 'h3']]]
Exemplo n.º 5
0
def test_parseblock_nestingpost():
  @block()
  def IdentityBlock(text):
    return ['div', text]

  assert unwind(parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock,
                           'hello\n---paragraphs\nhello\n...\n')) == ['div', 'hello\n', ['div', ['p', 'hello']]]
Exemplo n.º 6
0
def test_parseblock_nestingsub():
    # should consume paragraphs block
    assert unwind(
        parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock,
                   'hello\n---paragraphs\nhello\n...\n')) == [
                       'div', 'hello\n', ['div', ['p', 'hello']]
                   ]
Exemplo n.º 7
0
def test_tooltip():
    assert unwind(
        parse(Registry(NoopBlock, Tooltip), 'T[text](tooltip)',
              NoopBlock)) == [
                  'div',
                  ['span.tooltip', 'text', ['div.tooltip-text', 'tooltip']]
              ]
Exemplo n.º 8
0
def test_header(s: str, n: int):
    assert unwind(
        parse(Registry(Paragraphs, Header), '#' * n + ' ' + s,
              Paragraphs)) == [
                  'div', ['h' + str(n), ['a.anchor', {
                      'id': s.lower()
                  }, s]]
              ]
Exemplo n.º 9
0
def test_parseblock_nestingsub_multiple():
    assert unwind(
        parseblock(
            sample + [IdentityBlock], IdentityBlock,
            '*hello*\n---paragraphs\nhello\n---paragraphs\nhello again\n...\n...\n'
        )) == [
            'div', ['strong', {}, 'hello'], '\n',
            ['div', ['p', 'hello'], ['div', ['p', 'hello again']]]
        ]

    assert unwind(
        parseblock(
            sample, Paragraphs,
            ' *hello*\n---paragraphs\nhello\n---paragraphs\n*hello* again\n...\n...\n'
        )) == [
            'div', ['p', ' ', ['strong', {}, 'hello']],
            [
                'div', ['p', 'hello'],
                ['div', ['p', ['strong', {}, 'hello'], ' again']]
            ]
        ]
Exemplo n.º 10
0
def test_standard_registry():
    t1 = """
# Placeholder

* bold *

new paragraph
  """
    assert unwind(parse(Standard, t1)) == [
        'div', ['h1', ['a.anchor', {
            'id': 'placeholder'
        }, 'Placeholder']], ['p', ['strong', {}, ' bold ']],
        ['p', 'new paragraph']
    ]
Exemplo n.º 11
0
def test_parseblock_nestingsub():
  # should consume paragraphs block
  assert unwind(parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock,
                    'hello\n---paragraphs\nhello\n...\n')) == ['div', 'hello\n', ['div', ['p', 'hello']]]
Exemplo n.º 12
0
def test_parseblock_nosub():
  examples = ['test', 'k', 'a;lkjfksdfnqwenqw;eriouZN<ZMXz;lkj;sldakfjsf']
  for e in examples:
    assert unwind(parseblock(sample, Paragraphs, e)) == ['div', ['p', e]]
Exemplo n.º 13
0
def test_parseblock_empty():
  assert unwind(parseblock(sample, Paragraphs, '')) == ['div']
Exemplo n.º 14
0
def test_parsemacros(name: str, text: str):
  assert unwind(parsemacros('{} = {}'.format(name, text))) == [[name, text]]
Exemplo n.º 15
0
def test_regex_clash(s: str):
  assert unwind(parse(Standard, '__'+s+'__')) == [
    'div', ['p', ['span', {'style': 'text-decoration:underline;'}, s]]]
Exemplo n.º 16
0
def test_parseinline_empty():
    assert parseinline(sample, Paragraphs, '') == ['']
    assert parseinline(Standard, Paragraphs,
                       '**') == [(Bold, ['strong', {}, ''])]
    assert unwind(parse(Standard, '')) == ['div']
Exemplo n.º 17
0
def test_parseblock_empty():
    assert unwind(parseblock(sample, Paragraphs, '')) == ['div']
Exemplo n.º 18
0
def test_criticsub():
    assert unwind(
        parse(Registry(Paragraphs, CriticSub), '{~~a~>b~~}',
              Paragraphs)) == ['div', ['p', [['del', 'a'], ['ins', 'b']]]]
Exemplo n.º 19
0
def test_matrix():
    assert unwind(Matrix('c | x')) == [
        'div.matrix.matrix-flex',
        [
            'div', {
                'style': {
                    'display': 'flex'
                }
            }, ['span', {
                'style': {
                    'flex': 1
                }
            }, 'c'], ['span', {
                'style': {
                    'flex': 1
                }
            }, 'x']
        ]
    ]

    assert unwind(Matrix('c|x')) == [
        'div.matrix.matrix-flex',
        [
            'div', {
                'style': {
                    'display': 'flex'
                }
            }, ['span', {
                'style': {
                    'flex': 1
                }
            }, 'c'], ['span', {
                'style': {
                    'flex': 1
                }
            }, 'x']
        ]
    ]

    assert unwind(Matrix('c| x')) == [
        'div.matrix.matrix-flex',
        [
            'div', {
                'style': {
                    'display': 'flex'
                }
            }, ['span', {
                'style': {
                    'flex': 1
                }
            }, 'c'], ['span', {
                'style': {
                    'flex': 1
                }
            }, 'x']
        ]
    ]

    assert unwind(Matrix('c |x')) == [
        'div.matrix.matrix-flex',
        [
            'div', {
                'style': {
                    'display': 'flex'
                }
            }, ['span', {
                'style': {
                    'flex': 1
                }
            }, 'c'], ['span', {
                'style': {
                    'flex': 1
                }
            }, 'x']
        ]
    ]

    assert unwind(Matrix('c | x', type='matrix')) == [
        'table.matrix.matrix-table',
        ['tr', {
            'style': {}
        }, ['td', {}, 'c'], ['td', {}, 'x']]
    ]
Exemplo n.º 20
0
def test_regex_clash(s: str):
    assert unwind(parse(Standard, '__' + s + '__')) == [
        'div', ['p', ['span', {
            'style': 'text-decoration:underline;'
        }, s]]
    ]
Exemplo n.º 21
0
def test_parseblock_nosub():
    examples = ['test', 'k', 'a;lkjfksdfnqwenqw;eriouZN<ZMXz;lkj;sldakfjsf']
    for e in examples:
        assert unwind(parseblock(sample, Paragraphs, e)) == ['div', ['p', e]]
Exemplo n.º 22
0
def test_parseblock_nestingpost():
    assert unwind(
        parseblock(Registry(IdentityBlock, Paragraphs), IdentityBlock,
                   'hello\n---paragraphs\nhello\n...\n')) == [
                       'div', 'hello\n', ['div', ['p', 'hello']]
                   ]
Exemplo n.º 23
0
def test_parseinline_empty():
  assert parseinline(sample, Paragraphs, '') == ['']
  assert parseinline(Standard, Paragraphs, '**') == [(Bold, ['strong', {}, ''])]
  assert unwind(parse(Standard, '')) == ['div']
Exemplo n.º 24
0
def test_parsemacros(name: str, text: str):
    assert unwind(parsemacros('{} = {}'.format(
        name, text))) == [[name.strip(), text.strip()]]