示例#1
0
 def test_haxe_turns_node_into_haxe_code(self):
     h = HaxeTransformer()
     haxe_code = '@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))'
     metadata = '@haxe: {}'.format(haxe_code)
     data = Token("LONG_STRING", metadata)
     output = h.haxe(data)
     self.assertEqual(haxe_code, output)
示例#2
0
 def test_funccall_specifies_target(self):
     h = HaxeTransformer()
     node = [
         Tree("getattr", ['super', Token("NAME", 'update')]), ['elapsed']
     ]
     output = h.funccall(node)
     self.assertEqual("super.update(elapsed)", output)
示例#3
0
    def test_var_returns_variable_name(self):
        variable_names = ["Sprite", "some_variable", "out_of_100_monkeys"]
        h = HaxeTransformer()

        for token in variable_names:
            node = [Token("NAME", token)]
            output = h.var(node)
            self.assertEqual(token, output)
示例#4
0
 def test_classdef_removes_semicolon_superclass(self):
     # Semicolon is probably a result of our semicolon-adding elsewhere
     # We should fix that first!
     h = HaxeTransformer()
     data = [Token("NAME", 'AssetPaths'), ';']
     output = h.classdef(data)
     self.assertIn("class AssetPaths", output)
     self.assertNotIn(";", output)
示例#5
0
 def test_funcdef_transforms_header(self):
     h = HaxeTransformer()
     data = [
         Token("NAME", 'update'), ["elapsed"], 'super().update(elapsed)'
     ]
     output = h.funcdef(data)
     self.assertIn("function update(elapsed)", output)
     self.assertIn("super().update(elapsed)", output)
示例#6
0
    def test_classdef_creates_non_base_class(self):
        h = HaxeTransformer()
        data = [Token("NAME", 'Monster'), [''], 'function new() { super() }']
        output = h.classdef(data)

        self.assertIn("class Monster", output)
        self.assertIn("()", output)
        self.assertIn("{", output)
        self.assertIn("}", output)
示例#7
0
 def test_funcdef_transforms_init_to_new(self):
     h = HaxeTransformer()
     data = [
         Token("NAME", '__init__'), [],
         'super().__init__()\nself.addChild(new FlxGame(0, 0, PlayState))'
     ]
     output = h.funcdef(data)
     self.assertIn("function new()", output)
     self.assertIn("addChild", output)
示例#8
0
 def test_parameters_removes_first_self_param_and_returns_values_as_list(
         self):
     h = HaxeTransformer()
     data = [
         Token("NAME", 'self'),
         Token("NAME", 'elapsed'),
         Token("NAME", 'mode')
     ]
     output = h.parameters(data)
     self.assertEqual(output, ["elapsed", "mode"])
示例#9
0
    def test_classdef_creates_subclass(self):
        h = HaxeTransformer()
        data = [
            Token("NAME", 'Main'), ['Sprite'],
            'function new() { super().__init__()\nself.addChild(new FlxGame(0, 0, PlayState)) }'
        ]
        output = h.classdef(data)

        self.assertIn("class Main extends Sprite", output)
        self.assertIn("{", output)
        self.assertIn("}", output)
        self.assertIn("addChild", output)
示例#10
0
    def test_import_stmt_transforms_dot_path_imports(self):
        h = HaxeTransformer()

        node = [
            Tree("import_from", [
                Tree("dotted_name", [Token("NAME", 'flixel')]),
                Tree("import_as_names",
                     [Tree("import_as_name", [Token("NAME", 'FlxGame')])])
            ])
        ]

        output = h.import_stmt(node)
        self.assertEqual("import flixel.FlxGame;", output)
示例#11
0
    def test_import_stmt_transforms_simple_imports(self):
        h = HaxeTransformer()

        node = [
            Tree("import_name", [
                Tree("dotted_as_names", [
                    Tree("dotted_as_name",
                         [Tree("dotted_name", [Token("NAME", 'PlayState')])])
                ])
            ])
        ]

        output = h.import_stmt(node)
        self.assertEqual("import PlayState;", output)
示例#12
0
    def test_import_stmt_transforms_multilevel_dot_path_imports(self):
        h = HaxeTransformer()

        node = [
            Tree("import_from", [
                Tree("dotted_name",
                     [Token("NAME", 'openfl'),
                      Token("NAME", 'display')]),
                Tree("import_as_names",
                     [Tree("import_as_name", [Token("NAME", 'Sprite')])])
            ])
        ]

        output = h.import_stmt(node)
        self.assertEqual("import openfl.display.Sprite;", output)
示例#13
0
 def test_funccall_has_brackets_when_no_parameters(self):
     h = HaxeTransformer()
     output = h.funccall(['super', Tree("arguments", [])])
     self.assertEqual("super()", output)
示例#14
0
 def test_file_input_returns_data(self):
     h = HaxeTransformer()
     x = 38
     data = ["one", x, 172.1]
     output = h.file_input(data)
     self.assertEqual(data, output)
示例#15
0
 def test_compound_stmt_returns_newline_separated_text(self):
     h = HaxeTransformer()
     data = ["first line", "second line", "third line!"]
     output = h.compound_stmt(data)
     self.assertEqual("\n".join(data), output)
示例#16
0
 def test_haxe_turns_string_into_haxe_code(self):
     h = HaxeTransformer()
     haxe_code = '@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))'
     data = '@haxe: {}'.format(haxe_code)
     output = h.haxe(data)
     self.assertEqual(haxe_code, output)
示例#17
0
 def test_suite_returns_newline_separated_text_with_semicolons(self):
     h = HaxeTransformer()
     data = ["first line", "second line", "third line!"]
     output = h.suite(data)
     self.assertEqual("first line;\nsecond line;\nthird line!;", output)
示例#18
0
 def test_arguments_returns_arguments(self):
     h = HaxeTransformer()
     args = [124, Tree("test", [])]
     output = h.arguments(args)
     self.assertEqual(args, output)
示例#19
0
 def test_funccall_adds_new_to_constructor(self):
     h = HaxeTransformer()
     node = ['FlxGame', [0, 0, 'PlayState']]
     output = h.funccall(node)
     self.assertEqual("new FlxGame(0, 0, PlayState)", output)
示例#20
0
 def test_funccall_generates_with_parameters(self):
     h = HaxeTransformer()
     output = h.funccall(
         ['copyInstance',
          Tree("arguments", ['Sprite', 'self'])])
     self.assertEqual("copyInstance(Sprite, self)", output)
示例#21
0
 def test_number_transforms_integer_numbers_to_floats(self):
     h = HaxeTransformer()
     for num in (0, 9999, -19232):
         node = [Token("DEC_NUMBER", '{}'.format(num))]
         output = h.number(node)
         self.assertEqual(num, output)
示例#22
0
 def test_number_transforms_decimal_numbers_to_floats(self):
     for num in (0.0, 17.021, -183.123456):
         h = HaxeTransformer()
         node = [Token("DEC_NUMBER", '{}'.format(num))]
         output = h.number(node)
         self.assertEqual(num, output)
示例#23
0
 def test_string_turns_node_into_empty_string(self):
     h = HaxeTransformer()
     metadata = '@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))'
     data = Token("LONG_STRING", '"""{}"""'.format(metadata))
     output = h.string(data)
     self.assertEqual("", output)
示例#24
0
 def test_string_turns_string_into_empty_string(self):
     h = HaxeTransformer()
     data = '@:build(flixel.system.FlxAssets.buildFileReferences("assets", true))'
     output = h.string(data)
     self.assertIn("", data)
示例#25
0
 def test_funccall_removes_args_in_constructor_call_to_super(self):
     h = HaxeTransformer()
     data = ['super', ['Sprite', 'self']]
     output = h.funccall(data)
     self.assertEqual("super()", output)
示例#26
0
 def test_arithmetic_expression_adds_brackets(self, operand_one, operation,
                                              operand_two):
     h = HaxeTransformer()
     output = h.arith_expr([operand_one, operation, operand_two])
     self.assertEqual(
         "({} {} {})".format(operand_one, operation, operand_two), output)