예제 #1
0
 def test_or_evaluation(self):
     """Statements should not be evaluated more than once."""
     self.assertEvalsTo(
         (u"(set! x 0)"
          u"(or (do (inc! x) #true))"
          u"x"),
         Integer.fromint(1))
예제 #2
0
 def test_for_each_eval_list_once(self):
     self.assertEqual(
         self.eval(
             u"(set! x 0)"
             u"(for-each y (do (inc! x) (list 1 2)) y)"
             u"x"
         ),
         Integer.fromint(1))
예제 #3
0
 def test_loop(self):
     self.assertEqual(
         self.eval(
             u"(set! x 0)"
             u"(try"
             u'  (loop (if (< x 5) (inc! x) (throw error "done!")))'
             u"  :catch error e"
             u"  x"
             u")"
         ),
         Integer.fromint(5))
예제 #4
0
 def test_for_each(self):
     self.assertEqual(
         evaluate_with_prelude(parse_one(lex(u"""(let (total 0 numbers (list 1 2 3 4))
         (for-each number numbers (set! total (+ total number)))
         total)"""))),
         Integer.fromint(10))
예제 #5
0
 def test_set(self):
     self.assertEvalsTo(u"(set! x 1) x", Integer.fromint(1))
예제 #6
0
 def test_join(self):
     self.assertEvalsTo(
         u"(set! x (list 1)) (join! x (list 2)) x",
         List([Integer.fromint(1), Integer.fromint(2)]))
예제 #7
0
 def test_sort_list(self):
     self.assertEvalsTo(u"(sort (list 5 4 3 2 1))",
         List([Integer.fromint(1), Integer.fromint(2), Integer.fromint(3), Integer.fromint(4), Integer.fromint(5)])
     )
예제 #8
0
 def test_case_second_match(self):
     self.assertEvalsTo(u"(case (#false 1) (#true 2))", Integer.fromint(2))
예제 #9
0
 def test_case_true(self):
     self.assertEvalsTo(u"(case (#true 1))", Integer.fromint(1))
예제 #10
0
 def test_when_true(self):
     self.assertEvalsTo(u"(when #true 1)", Integer.fromint(1))
예제 #11
0
 def test_second(self):
     self.assertEvalsTo(u"(second (list 1 2 3 4 5))", Integer.fromint(2))
예제 #12
0
 def test_first(self):
     self.assertEvalsTo(u"(first (list 1 2 3 4 5))", Integer.fromint(1))
예제 #13
0
 def test_filter(self):
     self.assertEvalsTo(u"(filter (lambda (x) (equal? x 2)) (list 1 2 3))",
                        List([Integer.fromint(2)]))
예제 #14
0
 def test_map(self):
     expected = List([Integer.fromint(2), Integer.fromint(3), Integer.fromint(4)])
     self.assertEvalsTo(u"(map (lambda (x) (+ x 1)) (list 1 2 3))", expected)
예제 #15
0
 def test_list(self):
     expected = List([Integer.fromint(1), Integer.fromint(2), Integer.fromint(3)])
     self.assertEvalsTo(u"(list 1 2 3)", expected)
예제 #16
0
 def test_third(self):
     self.assertEvalsTo(u"(third (list 1 2 3 4 5))", Integer.fromint(3))
예제 #17
0
 def test_rest(self):
     self.assertEvalsTo(u"(rest (list 1 2 3))", List([Integer.fromint(2), Integer.fromint(3)]))
예제 #18
0
 def test_fifth(self):
     self.assertEvalsTo(u"(fifth (list 1 2 3 4 5))", Integer.fromint(5))
예제 #19
0
 def test_when_not_false(self):
     self.assertEvalsTo(u"(when-not #false 1 2)", Integer.fromint(2))
예제 #20
0
 def test_fifth_bytestring(self):
     self.assertEqual(
         evaluate_with_prelude(parse_one(lex(u'(fifth #bytes("abcde"))'))),
         Integer.fromint(101))
예제 #21
0
 def test_case_first_match(self):
     self.assertEvalsTo(u"(case (#true 1) (#true 2))", Integer.fromint(1))
예제 #22
0
 def test_last(self):
     self.assertEvalsTo(u"(last (list 1 2 3 4 5))", Integer.fromint(5))
예제 #23
0
 def test_clause_body_in_correct_scope(self):
     self.assertEvalsTo(u"(let (x 2) (case (#false 1) (#true x)))", Integer.fromint(2))
예제 #24
0
 def test_last_bytestring(self):
     self.assertEqual(
         evaluate_with_prelude(parse_one(lex(u'(last #bytes("abc"))'))),
         Integer.fromint(99))
예제 #25
0
 def test_copy_equal(self):
     self.assertEvalsTo(u"(copy (list 1 2))", List([Integer.fromint(1), Integer.fromint(2)]))
예제 #26
0
    def test_append(self):
        expected = List([Integer.fromint(1), Integer.fromint(2)])

        self.assertEvalsTo(
            u"(set-symbol! (quote x) (quote (1))) (append! x 2) x",
            expected)
예제 #27
0
 def test_join(self):
     self.assertEvalsTo(
         u"(join (list 1) (list) (list 2 3))",
         List([Integer.fromint(1), Integer.fromint(2), Integer.fromint(3)]))
예제 #28
0
 def test_push_list(self):
     expected = List([Integer.fromint(1)])
     self.assertEvalsTo(u"(set-symbol! (quote x) (quote ())) (push! x 1) x", expected)
예제 #29
0
 def test_function(self):
     self.assertEvalsTo(u"(function x () 1) (x)", Integer.fromint(1))
예제 #30
0
 def test_dec_macro(self):
     self.assertEvalsTo(u"(set! x 2) (dec! x) x", Integer.fromint(1))