def testWriteFunctionCall(self): self.expectedResults += [ 'ds_map_create()', 'BarrelRoll(times)', 'DoWhatever(foo, bar, baz)', 'abs(angle1 + angle2)', 'fun(this - that, which + watch)', ] self.fixtures += [ gmcode.FunctionCall('ds_map_create'), gmcode.FunctionCall('BarrelRoll', [gmcode.Expression('times')]), gmcode.FunctionCall('DoWhatever', [ gmcode.Expression('foo'), gmcode.Expression('bar'), gmcode.Expression('baz'), ]), gmcode.FunctionCall('abs', [ gmcode.BinaryOperation(gmcode.Expression('angle1'), '+', gmcode.Expression('angle2')), ]), gmcode.FunctionCall('fun', [ gmcode.BinaryOperation(gmcode.Expression('this'), '-', gmcode.Expression('that')), gmcode.BinaryOperation(gmcode.Expression('which'), '+', gmcode.Expression('watch')), ]), ]
def testWriteManyStatements(self): self.expectedResults += [ 'Foo();\nBar();\nBaz();\n', ] self.fixtures += [ gmcode.Statements([ gmcode.Statement(gmcode.FunctionCall('Foo')), gmcode.Statement(gmcode.FunctionCall('Bar')), gmcode.Statement(gmcode.FunctionCall('Baz')) ]), ]
def testWriteVariableAssignment(self): self.expectedResults += [ 'var i = 0', 'i = ds_list_create()', 'var foo = Bar(Baz())', ] self.fixtures += [ gmcode.VariableAssignment('i', gmcode.Expression('0')), gmcode.VariableAssignment('i', gmcode.FunctionCall('ds_list_create'), False), gmcode.VariableAssignment( 'foo', gmcode.FunctionCall('Bar', [gmcode.FunctionCall('Baz')])), ]
def testWriteForLoop(self): self.expectedResults += [ 'for (var i = 0; i < ds_list_size(list); i++) {' + '\n var item = ds_list_find_value(list, i);' + '\n Item_doThing(item);\n}\n', 'for (var item = Begin(list); item != undefined; item = Next()) {' + '\n Item_doThing(item);\n}\n', ] self.fixtures += [ gmcode.ForLoop( gmcode.VariableAssignment('i', gmcode.Expression('0')), gmcode.Expression('i < ds_list_size(list)'), gmcode.Expression('i++'), gmcode.Statements([ gmcode.Statement( gmcode.VariableAssignment( 'item', gmcode.FunctionCall('ds_list_find_value', [ gmcode.Expression('list'), gmcode.Expression('i'), ]))), gmcode.Statement( gmcode.FunctionCall('Item_doThing', [gmcode.Expression('item')])) ])), gmcode.ForLoop( gmcode.VariableAssignment( 'item', gmcode.FunctionCall('Begin', [gmcode.Expression('list')])), gmcode.Expression('item != undefined'), gmcode.VariableAssignment('item', gmcode.FunctionCall('Next'), False), gmcode.Statements([ gmcode.Statement( gmcode.FunctionCall('Item_doThing', [gmcode.Expression('item')])) ])), ]
def testWriteIfStatement(self): self.expectedResults += [ 'if (varName) {\n show_message("hi");\n}\n', 'if (i > 0) {\n gotofail();\n dothings();\n}\n', 'if (true) {\n a();\n} else {\n b();\n}\n', 'if (false) {\n a();\n} else if (true) {\n b();\n}\n', 'if (n) {\n a();\n} ' + 'else if (m) {\n b();\n} else {\n c();\n}\n', ] self.fixtures += [ gmcode.IfStatement( gmcode.IfClause( gmcode.Expression('varName'), gmcode.Statement( gmcode.Expression('show_message("hi")')))), gmcode.IfStatement( gmcode.IfClause( gmcode.Expression('i > 0'), gmcode.Statements([ gmcode.Statement(gmcode.FunctionCall('gotofail')), gmcode.Statement(gmcode.FunctionCall('dothings')), ]))), gmcode.IfStatement( gmcode.IfClause(gmcode.Expression('true'), gmcode.Statement(gmcode.FunctionCall('a'))), gmcode.Statement(gmcode.FunctionCall('b'))), gmcode.IfStatement( gmcode.IfClause(gmcode.Expression('false'), gmcode.Statement(gmcode.FunctionCall('a'))), gmcode.ElseIfClause(gmcode.Expression('true'), gmcode.Statement( gmcode.FunctionCall('b')))), gmcode.IfStatement( gmcode.IfClause(gmcode.Expression('n'), gmcode.Statement(gmcode.FunctionCall('a'))), gmcode.ElseIfClause(gmcode.Expression('m'), gmcode.Statement( gmcode.FunctionCall('b'))), gmcode.Statement(gmcode.FunctionCall('c'))), ]
def testWriteStatement(self): self.expectedResults += [ 'DoABarrelRoll();\n', 'GetObjectRef().varName;\n', 'outerfunction(innerfunction());\n', 'one(two(), three(four()));\n', ] self.fixtures += [ gmcode.Statement(gmcode.FunctionCall('DoABarrelRoll')), gmcode.Statement(gmcode.Expression('GetObjectRef().varName')), gmcode.Statement( gmcode.FunctionCall('outerfunction', [ gmcode.FunctionCall('innerfunction'), ])), gmcode.Statement( gmcode.FunctionCall('one', [ gmcode.FunctionCall('two'), gmcode.FunctionCall('three', [ gmcode.Expression('four()'), ]), ])), ]