Example #1
0
 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(),
     )
Example #2
0
 def test_step8_is_macro(self):
     self.assertEqual(False,
                      MalFunctionCompiled(lambda a: MalInt(1)).is_macro())
     self.assertEqual(
         False,
         MalFunctionRaw(core.ns["+"], MalInt(1), MalList([]),
                        Env(None)).is_macro(),
     )
Example #3
0
 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())
Example #4
0
 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)),
     )
Example #5
0
 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(),
     )
Example #6
0
 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(),
     )
Example #7
0
 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(),
     )
Example #8
0
 def test_mallist_native(self):
     x = MalInt(1)
     self.assertEqual([x], MalList([x]).native())
Example #9
0
 def test_eval_invalid(self):
     with self.assertRaises(MalInvalidArgumentException):
         step3_env.EVAL(MalList([MalInt(1), MalInt(2)]), Env(None))