示例#1
0
def test_interpolate():
    src = 'foo "before {a} {b.c} after"'
    node = interpolate(parse_raw(src))
    check_eq(
        node,
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([
                        String('before '),
                        Symbol('a'),
                        String(' '),
                        Symbol('b.c'),
                        String(' after'),
                    ])
                ]),
            ])
        ]),
    )
    items = node.values[0].values[1].values[1].values
    check_location(src, items[0], '"before ')
    check_location(src, items[1], 'a')
    check_location(src, items[2], ' ')
    check_location(src, items[3], 'b.c')
    check_location(src, items[4], ' after"')
示例#2
0
def test_indent():
    check_parse(
        """
        foo
          "bar"
        """,
        List([
            Tuple([Symbol('foo'), String('bar')]),
        ]),
    )
    check_parse(
        """
        foo
          "bar"
          5
          "baz"
        """,
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([String('bar'),
                          Number(5), String('baz')])
                ])
            ]),
        ]),
    )
示例#3
0
def test_interpolate_invalid():
    check_eq(
        interpolate(
            parse_raw('foo "before {.a} {b.} {a..b} {.} '
                      '{..} after"')),
        List([
            Tuple([
                Symbol('foo'),
                String('before {.a} {b.} {a..b} {.} {..} after'),
            ])
        ]),
    )
    check_eq(
        interpolate(
            parse_raw('foo "before {.a} {b.} {c} {a..b} '
                      '{.} {..} after"')),
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([
                        String('before {.a} {b.} '),
                        Symbol('c'),
                        String(' {a..b} {.} {..} after'),
                    ])
                ]),
            ])
        ]),
    )
示例#4
0
def test_html_tags():
    check_expr_type(
        """
        div :foo "bar"
          span "Some Text"
        """,
        Tuple.typed(Markup, [
            Symbol.typed(HTML_TAG_TYPE, 'div'),
            Keyword('foo'),
            String.typed(StringType, 'bar'),
            Tuple.typed(Markup, [
                Symbol.typed(HTML_TAG_TYPE, 'span'),
                String.typed(StringType, 'Some Text'),
            ]),
        ]),
    )
示例#5
0
def test_list():
    foo_type = Func[[ListType[Union[IntType, StringType]]], IntType]
    check_expr_type(
        """
        foo [1 2 3]
        """,
        Tuple.typed(IntType, [
            Symbol.typed(foo_type, 'foo'),
            List.typed(ListType[Union[IntType, ]], [
                Number.typed(IntType, 1),
                Number.typed(IntType, 2),
                Number.typed(IntType, 3),
            ]),
        ]),
        {'foo': foo_type},
    )
    check_expr_type(
        """
        foo [1 2 "3"]
        """,
        Tuple.typed(IntType, [
            Symbol.typed(foo_type, 'foo'),
            List.typed(ListType[Union[IntType, StringType]], [
                Number.typed(IntType, 1),
                Number.typed(IntType, 2),
                String.typed(StringType, '3'),
            ]),
        ]),
        {'foo': foo_type},
    )
    with py.test.raises(TypeCheckError):
        check_expr('foo [1 2 "3"]',
                   {'foo': Func[[ListType[IntType]], IntType]})
示例#6
0
 def testSimple(self):
     self.assertPrints(
         Tuple([Symbol('html'),
                Keyword('foo'), String('bar'), Symbol('baz')]),
         """
         html :foo "bar" baz
         """,
     )
示例#7
0
 def testNested(self):
     self.assertPrints(
         Tuple([Symbol('html'),
                Keyword('foo'), String('bar'),
                Tuple([Symbol('head')])]),
         """
         html :foo "bar"
           head
         """,
     )
示例#8
0
def test_implicit_tuple():
    check_parse(
        'foo :bar 5 "baz"',
        List([
            Tuple([Symbol('foo'),
                   Keyword('bar'),
                   Number(5),
                   String('baz')]),
        ]),
    )
示例#9
0
 def test(self):
     node = self.parse(
         """
         div "Some {var} text"
         """
     )
     self.assertEqual(
         Translator(self.translations).visit(node),
         List([Tuple([Symbol('div'), String('Какой-то {var} текст')])]),
     )
示例#10
0
def test_explicit_tuple():
    check_parse(
        'foo (bar 5) "baz"',
        List([
            Tuple([
                Symbol('foo'),
                Tuple([Symbol('bar'), Number(5)]),
                String('baz')
            ]),
        ]),
    )
示例#11
0
def test_interpolate_empty_string():
    src = 'foo ""'
    node = interpolate(parse_raw(src))
    check_eq(
        node,
        List([Tuple([
            Symbol('foo'),
            String(''),
        ])]),
    )
    check_location(src, node.values[0].values[1], '""')
示例#12
0
def test_parser_interpolate():
    node = parse("""
    foo
      "bar {value} baz"
    """)
    check_eq(
        node,
        List([
            Tuple([
                Symbol('foo'),
                Tuple([
                    Symbol('join'),
                    List([
                        String('bar '),
                        Symbol('value'),
                        String(' baz'),
                    ])
                ]),
            ]),
        ]),
    )
示例#13
0
 def testJoin(self):
     self.assertPrints(
         Tuple([Symbol('html'),
                Keyword('foo'), String('bar'),
                Tuple([Symbol('join'), List([
                    Tuple([Symbol('head')]),
                    Tuple([Symbol('body')]),
                ])])]),
         """
         html :foo "bar"
           head
           body
         """,
     )
示例#14
0
def test_interpolate_first():
    src = 'foo "{a} after"'
    node = interpolate(parse_raw(src))
    check_eq(
        node,
        List([
            Tuple([
                Symbol('foo'),
                Tuple(
                    [Symbol('join'),
                     List([
                         Symbol('a'),
                         String(' after'),
                     ])]),
            ])
        ]),
    )
    items = node.values[0].values[1].values[1].values
    check_location(src, items[0], 'a')
    check_location(src, items[1], ' after"')