def test_step6_standard_string(self): self.assertEqual( '"foo"', step6_file.EVAL(MalString('"foo"'), Env(None)).native()) self.assertEqual('"foo"', step6_file.rep('"foo"', self._repl_env).__str__()) self.assertEqual('"foo"', MalString('"foo"').native()) self.assertEqual('"\\"foo\\""', MalString('"foo"').__str__())
def test_def(self): env = Env(None) self.assertEqual( 1, step3_env.EVAL( MalList([MalSymbol("def!"), MalSymbol("a"), MalInt(1)]), env).native(), ) self.assertEqual(1, env.get("a").native())
def test_if_basic_false_no_fourth_arg(self): env = Env(None) self.assertEqual( "nil", str( step4_if_fn_do.EVAL( MalList([MalSymbol("if"), MalBoolean(False), MalInt(4321)]), env)), )
def test_let_basic(self): env = Env(None) self.assertEqual( 2, step3_env.EVAL( MalList([ MalSymbol("let*"), MalList([MalSymbol("c"), MalInt(2)]), MalSymbol("c"), ]), env, ).native(), )
def test_eval_1_plus_1(self): env = Env(None) env.set( "+", mal_types.MalFunctionCompiled( lambda a: MalInt(a[0].native() + a[1].native())), ) self.assertEqual( 2, step3_env.EVAL(MalList([MalSymbol("+"), MalInt(1), MalInt(1)]), env).native(), )
def test_if_basic_false(self): env = Env(None) self.assertEqual( 1234, step4_if_fn_do.EVAL( MalList([ MalSymbol("if"), MalBoolean(False), MalInt(4321), MalInt(1234) ]), env, ).native(), )
def test_let_advanced(self): env = Env(None) env.set( "+", mal_types.MalFunctionCompiled( lambda a: MalInt(a[0].native() + a[1].native())), ) self.assertEqual( 4, step3_env.EVAL( MalList([ MalSymbol("let*"), MalList([MalSymbol("c"), MalInt(2)]), MalList([MalSymbol("+"), MalSymbol("c"), MalInt(2)]), ]), env, ).native(), )
def test_eval_invalid(self): with self.assertRaises(MalInvalidArgumentException): step3_env.EVAL(MalList([MalInt(1), MalInt(2)]), Env(None))
def test_step6_read_atom(self): atom = step6_file.EVAL(step6_file.READ("(atom 1)"), self._repl_env) self.assertEqual(1, atom.native().native())
def test_step6_atom_type(self): atom = step6_file.EVAL(MalAtom(MalInt(1)), Env(None)) self.assertEqual(1, atom.native().native())