Exemplo n.º 1
0
def test_2(compiler: TextCompiler):
    compiler.load_tags('''[defines:
        [define[test, [], []]:
            [defcode :function (text)
                return text
            end]
        ]
        [define[test_inherit1, [c=1], [extends=test]]:
            [defcode :function (text)
                return string.reverse(text)
            end]
            [text :[code[c]:{text}]]
        ]
    ]''')
    assert 'test' in compiler.base_tag.tags
    codes_test = compiler.base_tag.tags['test'].codes
    assert len(codes_test) == 2
    text = compiler.compile('''[defines:
        [define[test_inherit, [code=2], [extends=test]]:
            [defcode :function (text)
                return string.reverse(text)
            end]
            [text :[code[code]:{text}]]
        ]
    ]
    [test_inherit :test_string]''')
    assert len(codes_test) == 2
    assert compiler.compile('[test_inherit1[c=2] :test_string]') == \
        'test_string'[::-1]
    assert text == 'test_string'[::-1]
Exemplo n.º 2
0
def test_4(u_compiler: TextCompiler):
    u_compiler.load_tags('''[defines:
    [define[test, [q=1]]:
        [defcode :` function (text) return string.reverse(text) end`]
        [text :example [code[q] :{text} end]]
    ]
]''')
    assert u_compiler.compile('[test:begin]') == 'example dne nigeb'
Exemplo n.º 3
0
def test_9(u_compiler: TextCompiler):
    u_compiler.load_tags('''[defines:
    [define[test]:
        [replace['t'='a', ''='b', 'c'='']]
    ]
]''')
    replace = u_compiler.base_tag.tags['test'].compiler.blocks[-1].replace
    assert len(replace) == 1
    assert ('t', 'a') in replace
Exemplo n.º 4
0
def test_8(u_compiler: TextCompiler):
    u_compiler.load_tags('''[defines:
    [define[test]:
        [regex:test]
        [regex[]:test]
        [regex[[]]:test]
        [regex[test1]]
        [regex[test2]:[test:test]]
        [regex[test3]:`test`]
        [text :{text}]
    ]
]''')
    assert u_compiler.base_tag.tags['test'].lua_scope.regex.test1 is None
    assert u_compiler.base_tag.tags['test'].lua_scope.regex.test2 is None
    assert u_compiler.base_tag.tags['test'].lua_scope.regex.test3 is not None
Exemplo n.º 5
0
def test_2(u_compiler: TextCompiler):
    text = '''[defines:
    [defcode:1]
    [defcode[]:1]
    [defcode[[]]:1]
    [defcode[a]]
    [defcode[b]:[test]]
    [defcode[c] :` function (text) return "1. " .. text end`]
    [defcode[d] :` function (text) return "2. " .. text end`]
    [defcode[c] :` function (text) return "3. " .. text end`]
]'''
    u_compiler.load_tags(text)
    result = u_compiler.compile('''[defines:
    [defcode[c] :` function (text) return "4. " .. text end`]
    [defcode[e] :` function (text) return "5. " .. text end`]
    [define[test, [q=0], []]:
        [defcode: c]
        [defcode: d]
        [defcode: _my.c]
        [defcode: _my.e]
        [text:[code[q]:{text}]]
    ]
    [define[test1, [], []]: [defcode: c] [text :[code[a]:{text}]]]
    [define[test2, [a], []]: [defcode: c] [text :[code[a]:{text}]]]
]
[test:test]
[test[q=1]:test]
[test[q=2]:test]
[test[q=3]:test]
[test[q=4]:test]
a: [test1:test]
b: [test2[a="test"]:test]
''')
    assert len(u_compiler.base_tag.lua_scope._my) == 0
    assert u_compiler.base_tag.lua_scope.c
    assert u_compiler.base_tag.lua_scope.d
    assert '3. test' in result
    assert '2. test' in result
    assert '4. test' in result
    assert '5. test' in result
    assert 'a: test' in result
    assert 'b: test' in result
Exemplo n.º 6
0
def test_5(u_compiler: TextCompiler):
    text = '''[defines:
    [define[test]: [text:test]]
    [define[test1, []]]
    [macro[]]
    [macro[unknown]]
    [macro[unknown1=unknown]]
    [macro[test=test1]]
    [macro[l1=test, l2=test1]]
]'''
    u_compiler.load_tags(text)
    tags = u_compiler.base_tag.tags
    assert len(tags) == 4
    assert tags['test'] is not tags['test1']
    assert tags['l1'] is tags['test']
    assert tags['l2'] is tags['l2']

    t = u_compiler.compile('''[defines:
    [macro[l3=test, l4=l3]]
][l3] [l4]''')
    assert t == 'test test'
Exemplo n.º 7
0
def test_3(u_compiler: TextCompiler):
    with pytest.raises(Exception):
        u_compiler.compile('''[defines:
        [define[test, [a=1], []]:
            [defcode :` function (text)
                1 + "a"
                return text
            end`]]
            [text :[code[a]]]
            ][test:text]''')
    # with pytest.raises(LuaError):
    u_compiler.load_tags('''[defines:
        [define[test, [a=1], []]:
            [defcode :` function (text)
                t = text / 0
                return text .. " test"
            end`]
            [text :[code[a]:{text}]]
        ]
    ]''')
    with pytest.raises(LuaError, match="attempt to perform arithmetic"):
        u_compiler.compile('[test:text]')
Exemplo n.º 8
0
def test_1(compiler: TextCompiler):
    text = compiler.compile(
        '[[NANNASPRITE: Ponad [under :Medium], za [under :Siedmioma Bramami]')
    assert text == (
        '<span class="nannasprite">NANNASPRITE: Ponad <u>Medium</u>, za '
        '<u>Siedmioma Bramami</u></span>')
Exemplo n.º 9
0
def test_10(u_compiler: TextCompiler):
    with pytest.raises(Exception, match='Compilation error'):
        u_compiler.load_tags('''[defines:
        [defcode[test] :`gfdfgn[p;]`]
    ]''')
Exemplo n.º 10
0
def test_7(u_compiler: TextCompiler):
    u_compiler.load_tags('''[defines:
    [define[]]
]''')
    assert len(u_compiler.base_tag.tags) == 0
Exemplo n.º 11
0
def test_6(u_compiler: TextCompiler, text, result):
    t = u_compiler.compile(text)
    assert t == result
Exemplo n.º 12
0
def test_4(compiler: TextCompiler):
    results = compiler.compile_css()
    for i in css_text.splitlines():
        assert i in results
Exemplo n.º 13
0
def test_3(text, result, compiler: TextCompiler):
    t = compiler.compile(text)
    assert t == result