Ejemplo n.º 1
0
    def test_complex_resource(self):
        input = """\
            ### A Resource comment

            # A comment about shared-photos
            shared-photos =
                { $user_name } { $photo_count ->
                    [0] hasn't added any photos yet
                    [one] added a new photo
                   *[other] added { $photo_count } new photos
                }.


            ## A Section comment

            // A Syntax 0.4 comment about liked-comment
            liked-comment =
                { $user_name } liked your comment on { $user_gender ->
                    [male] his
                    [female] her
                   *[other] their
                } post.
        """

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

        self.assertEqual(json1, json2)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
    def test_syntax_error(self):
        input = """\
            foo = Foo {
        """

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

        self.assertEqual(json1, json2)
Ejemplo n.º 4
0
    def test_simple_resource(self):
        input = """\
            foo = Foo
        """

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

        self.assertEqual(json1, json2)
Ejemplo n.º 5
0
def pretty_print(fileType, data):
    resource = ast.from_json(data)
    print(serialize(resource))