def test_inline_multiline(self): input = """\ foo = Foo Bar """ output = """\ foo = Foo Bar """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(output))
def test_select_expression_nested(self): input = """\ foo = { $a -> *[a] { $b -> *[b] Foo } } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
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)
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)
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))
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))
def test_comment_section(self): input = """\ foo = Foo // A multiline // section comment. [[ Section Header ]] bar = Bar """ self.assertEqual(pretty_ftl(input), dedent_ftl(input))
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))
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))
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')
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))
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, })
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))
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)
def pretty_expr(text): parser = FluentParser() entry = parser.parse_entry(dedent_ftl(text)) expr = entry.value.elements[0].expression return serialize_expression(expr)
def test_escaped_unicode_sequence(self): input = """\ foo = { "\\u0065" } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_escaped_special_in_string_literal(self): input = """\ foo = { "Escaped \\" quote" } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_backslash_in_text(self): input = """\ foo = \\{ placeable } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_nested_placeables(self): input = """\ foo = {{ FOO() }} """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_macro_call(self): input = """\ foo = { -term() } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
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))
def pretty_ftl(text): parser = FluentParser() serializer = FluentSerializer(with_junk=False) res = parser.parse(dedent_ftl(text)) return serializer.serialize(res)
def test_number_element(self): input = """\ foo = Foo { 1 } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_term_reference(self): input = """\ foo = Foo { -bar } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_variable_reference(self): input = """\ foo = Foo { $bar } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_call_expression_with_number_expression(self): input = """\ foo = { FOO(1) } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_string_element(self): input = """\ foo = Foo { "bar" } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_call_expression_with_variable_reference(self): input = """\ foo = { FOO($bar) } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_attribute_expression(self): input = """\ foo = Foo { bar.baz } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))
def test_call_expression_with_named_argument_string(self): input = """\ foo = { FOO(bar: "bar") } """ self.assertEqual(self.pretty_ftl(input), dedent_ftl(input))