Beispiel #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']]
    ]
Beispiel #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]]
Beispiel #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']]]]
Beispiel #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']]]
Beispiel #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']]]
Beispiel #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']]
                   ]
Beispiel #7
0
def test_tooltip():
    assert unwind(
        parse(Registry(NoopBlock, Tooltip), 'T[text](tooltip)',
              NoopBlock)) == [
                  'div',
                  ['span.tooltip', 'text', ['div.tooltip-text', 'tooltip']]
              ]
Beispiel #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]]
              ]
Beispiel #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']]
            ]
        ]
Beispiel #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']
    ]
Beispiel #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']]]
Beispiel #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]]
Beispiel #13
0
def test_parseblock_empty():
  assert unwind(parseblock(sample, Paragraphs, '')) == ['div']
Beispiel #14
0
def test_parsemacros(name: str, text: str):
  assert unwind(parsemacros('{} = {}'.format(name, text))) == [[name, text]]
Beispiel #15
0
def test_regex_clash(s: str):
  assert unwind(parse(Standard, '__'+s+'__')) == [
    'div', ['p', ['span', {'style': 'text-decoration:underline;'}, s]]]
Beispiel #16
0
def test_parseinline_empty():
    assert parseinline(sample, Paragraphs, '') == ['']
    assert parseinline(Standard, Paragraphs,
                       '**') == [(Bold, ['strong', {}, ''])]
    assert unwind(parse(Standard, '')) == ['div']
Beispiel #17
0
def test_parseblock_empty():
    assert unwind(parseblock(sample, Paragraphs, '')) == ['div']
Beispiel #18
0
def test_criticsub():
    assert unwind(
        parse(Registry(Paragraphs, CriticSub), '{~~a~>b~~}',
              Paragraphs)) == ['div', ['p', [['del', 'a'], ['ins', 'b']]]]
Beispiel #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']]
    ]
Beispiel #20
0
def test_regex_clash(s: str):
    assert unwind(parse(Standard, '__' + s + '__')) == [
        'div', ['p', ['span', {
            'style': 'text-decoration:underline;'
        }, s]]
    ]
Beispiel #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]]
Beispiel #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']]
                   ]
Beispiel #23
0
def test_parseinline_empty():
  assert parseinline(sample, Paragraphs, '') == ['']
  assert parseinline(Standard, Paragraphs, '**') == [(Bold, ['strong', {}, ''])]
  assert unwind(parse(Standard, '')) == ['div']
Beispiel #24
0
def test_parsemacros(name: str, text: str):
    assert unwind(parsemacros('{} = {}'.format(
        name, text))) == [[name.strip(), text.strip()]]