예제 #1
0
def test_preprocessor_is_inline_expression(magic):
    """
    Check that inline_expressions are correctly detected
    """
    n = magic()
    assert not Lowering.is_inline_expression(n)
    n.data = 'foo'
    assert not Lowering.is_inline_expression(n)
    n.data = 'inline_expression'
    assert Lowering.is_inline_expression(n)
예제 #2
0
def test_compiler_generate(patch, magic):
    patch.init(Lowering)
    patch.object(Lowering, "process")
    patch.object(Semantics, "process")
    patch.many(JSONCompiler, ["compile"])
    tree = magic()
    storycontext = magic()
    result = Compiler.generate(tree, storycontext=storycontext, scope=None)
    Lowering.__init__.assert_called_with(parser=tree.parser,
                                         features=storycontext.features)
    Lowering.process.assert_called_with(tree)
    Semantics.process.assert_called_with(Lowering.process())
    assert result == (Lowering.process(), Semantics.process())
예제 #3
0
def test_objects_flatten_template_mixed(patch, tree):
    result = list(Lowering.flatten_template(tree, "a{hello}b"))
    assert result == [
        flatten_to_string("a"),
        {"$OBJECT": "code", "code": "hello"},
        flatten_to_string("b"),
    ]
예제 #4
0
def test_objects_flatten_template_escapes4(patch, tree):
    result = list(Lowering.flatten_template(tree, r'\\{\\}\\'))
    assert result == [
        flatten_to_string(r'\\'),
        {'$OBJECT': 'code', 'code': '\\'},
        flatten_to_string(r'\\')
    ]
예제 #5
0
def test_objects_flatten_template_mixed(patch, tree):
    result = list(Lowering.flatten_template(tree, 'a{hello}b'))
    assert result == [
        flatten_to_string('a'),
        {'$OBJECT': 'code', 'code': 'hello'},
        flatten_to_string('b')
    ]
예제 #6
0
def test_objects_flatten_template_escapes_uni3(patch, tree):
    result = list(
        Lowering.flatten_template(tree, r"\N{LATIN CAPITAL LETTER A}")
    )
    assert result == [
        flatten_to_string(r"\N{LATIN CAPITAL LETTER A}"),
    ]
예제 #7
0
def test_objects_flatten_template_escapes4(patch, tree):
    result = list(Lowering.flatten_template(tree, r"\\{\\}\\"))
    assert result == [
        flatten_to_string(r"\\"),
        {"$OBJECT": "code", "code": "\\"},
        flatten_to_string(r"\\"),
    ]
예제 #8
0
def test_compiler_generate(patch, magic):
    patch.init(Lowering)
    patch.object(Lowering, 'process')
    patch.object(Semantics, 'process')
    patch.many(JSONCompiler, ['compile'])
    tree = magic()
    result = Compiler.generate(tree, features=None)
    Lowering.__init__.assert_called_with(parser=tree.parser, features=None)
    Lowering.process.assert_called_with(tree)
    Semantics.process.assert_called_with(Lowering.process())
    assert result == Semantics.process()
예제 #9
0
def test_objects_flatten_template_escapes_uni(patch, tree):
    result = list(Lowering.flatten_template(tree, r'\x42\t\u1212'))
    assert result == [
        flatten_to_string(r'\x42\t\u1212'),
    ]
예제 #10
0
def test_objects_flatten_template_escapes_newlines(patch, tree):
    result = list(Lowering.flatten_template(tree, r'\n\n'))
    assert result == [
        flatten_to_string(r'\n\n'),
    ]
예제 #11
0
def test_objects_flatten_template_escapes2(patch, tree):
    result = list(Lowering.flatten_template(tree, r'\\.\'.\".\\'))
    assert result == [
        flatten_to_string(r"""\\.'.".\\"""),
    ]
예제 #12
0
def test_objects_flatten_template_only_templates(patch, tree):
    result = list(Lowering.flatten_template(tree, '{hello}'))
    assert result == [{'$OBJECT': 'code', 'code': 'hello'}]
예제 #13
0
def test_objects_flatten_template_no_templates(patch, tree):
    result = list(Lowering.flatten_template(tree, '.s.'))
    assert result == [flatten_to_string('.s.')]
예제 #14
0
def test_preprocessor_fake_tree(patch):
    patch.init(FakeTree)
    result = Lowering.fake_tree('block')
    FakeTree.__init__.assert_called_with('block')
    assert isinstance(result, FakeTree)
예제 #15
0
def test_objects_flatten_template_escapes3(patch, tree):
    result = list(Lowering.flatten_template(tree, r"\\\\\\"))
    assert result == [
        flatten_to_string(r"\\\\\\"),
    ]
예제 #16
0
def test_objects_flatten_template_escapes_uni2(patch, tree):
    result = list(Lowering.flatten_template(tree, r'\U0001F600'))
    assert result == [
        flatten_to_string(r'\U0001F600'),
    ]
예제 #17
0
def preprocessor(patch):
    patch.init(FakeTree)
    patch.object(Lowering, 'fake_tree', return_value=FakeTree(None))
    return Lowering(parser=None, features=None)
예제 #18
0
def test_objects_flatten_template_only_templates(patch, tree):
    result = list(Lowering.flatten_template(tree, "{hello}"))
    assert result == [{"$OBJECT": "code", "code": "hello"}]