def test_compile_if(self): engine = CompilationEngine("if (key = 81) { return; } else {}", "fakeOutputFile", True) engine.compile_if() self.assertEqual(engine.output, [ '<ifStatement>', '<keyword> if </keyword>', '<symbol> ( </symbol>', '<expression>', '<term>', '<identifier> key </identifier>', '</term>', '<symbol> = </symbol>', '<term>', '<integerConstant> 81 </integerConstant>', '</term>', '</expression>', '<symbol> ) </symbol>', '<symbol> { </symbol>', '<statements>', '<returnStatement>', '<keyword> return </keyword>', '<symbol> ; </symbol>', '</returnStatement>', '</statements>', '<symbol> } </symbol>', '<keyword> else </keyword>', '<symbol> { </symbol>', '<statements>', '</statements>', '<symbol> } </symbol>', '</ifStatement>' ])
def test_compile_if(self): engine = CompilationEngine("var int key; if (key = 81) { return; } else {}", "fakeOutputFile", True) engine.compile_var_dec() engine.compile_if() self.assertEqual(engine.xml_output, [ '<varDec>', '<keyword> var </keyword>', '<keyword> int </keyword>', '<identifier> key, category: local, definedOrUsed: defined, index: 0 </identifier>', '<symbol> ; </symbol>', '</varDec>', '<ifStatement>', '<keyword> if </keyword>', '<symbol> ( </symbol>', '<expression>', '<term>', '<identifier> key, category: local, definedOrUsed: used, index: 0 </identifier>', '</term>', '<symbol> = </symbol>', '<term>', '<integerConstant> 81 </integerConstant>', '</term>', '</expression>', '<symbol> ) </symbol>', '<symbol> { </symbol>', '<statements>', '<returnStatement>', '<keyword> return </keyword>', '<symbol> ; </symbol>', '</returnStatement>', '</statements>', '<symbol> } </symbol>', '<keyword> else </keyword>', '<symbol> { </symbol>', '<statements>', '</statements>', '<symbol> } </symbol>', '</ifStatement>'])