Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
def test_funccall_generates_with_parameters(self):
h = HaxeTransformer()
output = h.funccall(['copyInstance', Tree("arguments", ['Sprite', 'self'])])
self.assertEqual("copyInstance(Sprite, self)", output)
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)
def test_funccall_has_brackets_when_no_parameters(self):
h = HaxeTransformer()
output = h.funccall(['super', Tree("arguments", [])])
self.assertEqual("super()", output)
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)
def test_arguments_returns_arguments(self):
h = HaxeTransformer()
args = [124, Tree("test", [])]
output = h.arguments(args)
self.assertEqual(args, output)
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)
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)
def test_haxe_turns_list_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)