示例#1
0
 def test_inline_multiline(self):
     input = """\
         foo = Foo
             Bar
     """
     output = """\
         foo =
             Foo
             Bar
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(output))
示例#2
0
 def test_select_expression_nested(self):
     input = """\
         foo =
             { $a ->
                *[a]
                     { $b ->
                        *[b] Foo
                     }
             }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#3
0
    def test_syntax_error(self):
        input = """\
            foo = Foo {
        """

        ast1 = parse(dedent_ftl(input))
        json1 = ast1.to_json()
        ast2 = from_json(json1)
        json2 = ast2.to_json()

        self.assertEqual(json1, json2)
示例#4
0
    def test_simple_resource(self):
        input = """\
            foo = Foo
        """

        ast1 = parse(dedent_ftl(input))
        json1 = ast1.to_json()
        ast2 = from_json(json1)
        json2 = ast2.to_json()

        self.assertEqual(json1, json2)
示例#5
0
 def test_two_attributes_syntax_zero_four(self):
     input = """\
         foo
             .attr-a = Foo Attr A
             .attr-b = Foo Attr B
     """
     output = """\
         foo =
             .attr-a = Foo Attr A
             .attr-b = Foo Attr B
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(output))
示例#6
0
    def test_comment_group(self):
        input = """\
            foo = Foo

            ## Comment Header
            ##
            ## A multiline
            ## group comment.

            bar = Bar
        """
        self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#7
0
    def test_comment_section(self):
        input = """\
            foo = Foo


            // A multiline
            // section comment.
            [[ Section Header ]]

            bar = Bar
        """
        self.assertEqual(pretty_ftl(input), dedent_ftl(input))
示例#8
0
 def test_select_expression_in_inline_value(self):
     input = """\
         foo = Foo { $sel ->
                *[a] A
                 [b] B
             }
     """
     output = """\
         foo =
             Foo { $sel ->
                *[a] A
                 [b] B
             }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(output))
示例#9
0
 def test_select_expression_in_simple_multiline_current(self):
     input = """\
         foo =
             Foo { sel ->
                *[a] A
                 [b] B
             }
     """
     output = """\
         foo = Foo { sel ->
                *[a] A
                 [b] B
             }
     """
     self.assertEqual(pretty_ftl(input), dedent_ftl(output))
示例#10
0
 def test(self):
     resource = FluentParser().parse(
         dedent_ftl('''\
     one = Message
     two = Messages
     three = Has a
         .an = Message string in the Attribute
     '''))
     prior_res_id = id(resource)
     prior_msg_id = id(resource.body[1].value)
     backup = resource.clone()
     transformed = ReplaceTransformer('Message', 'Term').visit(resource)
     self.assertEqual(prior_res_id, id(transformed))
     self.assertEqual(prior_msg_id, id(transformed.body[1].value))
     self.assertFalse(transformed.equals(backup))
     self.assertEqual(transformed.body[1].value.elements[0].value, 'Terms')
示例#11
0
 def test_variant_multiline_first_inline(self):
     input = """\
         foo =
             { $sel ->
                *[a] AAA
                     BBB
             }
     """
     output = """\
         foo =
             { $sel ->
                *[a]
                     AAA
                     BBB
             }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(output))
示例#12
0
 def test_resource(self):
     resource = FluentParser().parse(
         dedent_ftl('''\
     one = Message
     # Comment
     two = Messages
     three = Messages with
         .an = Attribute
     '''))
     mv = MockVisitor()
     mv.visit(resource)
     self.assertEqual(mv.pattern_calls, 4)
     self.assertDictEqual(
         mv.calls, {
             'Resource': 1,
             'Comment': 1,
             'Message': 3,
             'Identifier': 4,
             'Attribute': 1,
             'Span': 10,
         })
示例#13
0
    def test_simple_message(self):
        input = {
            "comment": None,
            "value": {
                "elements": [{
                    "type": "TextElement",
                    "value": "Foo"
                }],
                "type": "Pattern"
            },
            "attributes": [],
            "type": "Message",
            "id": {
                "type": "Identifier",
                "name": "foo"
            }
        }
        output = """\
            foo = Foo
        """

        message = self.serializer.serialize_entry(from_json(input))
        self.assertEqual(message, dedent_ftl(output))
示例#14
0
 def pretty_variant_key(text, index):
     parser = FluentParser()
     entry = parser.parse_entry(dedent_ftl(text))
     variants = entry.value.elements[0].expression.variants
     return serialize_variant_key(variants[index].key)
示例#15
0
 def pretty_expr(text):
     parser = FluentParser()
     entry = parser.parse_entry(dedent_ftl(text))
     expr = entry.value.elements[0].expression
     return serialize_expression(expr)
示例#16
0
 def test_escaped_unicode_sequence(self):
     input = """\
         foo = { "\\u0065" }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#17
0
 def test_escaped_special_in_string_literal(self):
     input = """\
         foo = { "Escaped \\" quote" }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#18
0
 def test_backslash_in_text(self):
     input = """\
         foo = \\{ placeable }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#19
0
 def test_nested_placeables(self):
     input = """\
         foo = {{ FOO() }}
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#20
0
 def test_macro_call(self):
     input = """\
         foo = { -term() }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#21
0
 def test_call_expression_with_positional_and_named_arguments(self):
     input = """\
         foo = { FOO(bar, 1, baz: "baz") }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#22
0
 def pretty_ftl(text):
     parser = FluentParser()
     serializer = FluentSerializer(with_junk=False)
     res = parser.parse(dedent_ftl(text))
     return serializer.serialize(res)
示例#23
0
 def test_number_element(self):
     input = """\
         foo = Foo { 1 }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#24
0
 def test_term_reference(self):
     input = """\
         foo = Foo { -bar }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#25
0
 def test_variable_reference(self):
     input = """\
         foo = Foo { $bar }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#26
0
 def test_call_expression_with_number_expression(self):
     input = """\
         foo = { FOO(1) }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#27
0
 def test_string_element(self):
     input = """\
         foo = Foo { "bar" }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#28
0
 def test_call_expression_with_variable_reference(self):
     input = """\
         foo = { FOO($bar) }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#29
0
 def test_attribute_expression(self):
     input = """\
         foo = Foo { bar.baz }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
示例#30
0
 def test_call_expression_with_named_argument_string(self):
     input = """\
         foo = { FOO(bar: "bar") }
     """
     self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))