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))
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))
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))
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))
def test_set(self): self.assertEvalsTo(u"(set! x 1) x", Integer.fromint(1))
def test_join(self): self.assertEvalsTo( u"(set! x (list 1)) (join! x (list 2)) x", List([Integer.fromint(1), Integer.fromint(2)]))
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)]) )
def test_case_second_match(self): self.assertEvalsTo(u"(case (#false 1) (#true 2))", Integer.fromint(2))
def test_case_true(self): self.assertEvalsTo(u"(case (#true 1))", Integer.fromint(1))
def test_when_true(self): self.assertEvalsTo(u"(when #true 1)", Integer.fromint(1))
def test_second(self): self.assertEvalsTo(u"(second (list 1 2 3 4 5))", Integer.fromint(2))
def test_first(self): self.assertEvalsTo(u"(first (list 1 2 3 4 5))", Integer.fromint(1))
def test_filter(self): self.assertEvalsTo(u"(filter (lambda (x) (equal? x 2)) (list 1 2 3))", List([Integer.fromint(2)]))
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)
def test_list(self): expected = List([Integer.fromint(1), Integer.fromint(2), Integer.fromint(3)]) self.assertEvalsTo(u"(list 1 2 3)", expected)
def test_third(self): self.assertEvalsTo(u"(third (list 1 2 3 4 5))", Integer.fromint(3))
def test_rest(self): self.assertEvalsTo(u"(rest (list 1 2 3))", List([Integer.fromint(2), Integer.fromint(3)]))
def test_fifth(self): self.assertEvalsTo(u"(fifth (list 1 2 3 4 5))", Integer.fromint(5))
def test_when_not_false(self): self.assertEvalsTo(u"(when-not #false 1 2)", Integer.fromint(2))
def test_fifth_bytestring(self): self.assertEqual( evaluate_with_prelude(parse_one(lex(u'(fifth #bytes("abcde"))'))), Integer.fromint(101))
def test_case_first_match(self): self.assertEvalsTo(u"(case (#true 1) (#true 2))", Integer.fromint(1))
def test_last(self): self.assertEvalsTo(u"(last (list 1 2 3 4 5))", Integer.fromint(5))
def test_clause_body_in_correct_scope(self): self.assertEvalsTo(u"(let (x 2) (case (#false 1) (#true x)))", Integer.fromint(2))
def test_last_bytestring(self): self.assertEqual( evaluate_with_prelude(parse_one(lex(u'(last #bytes("abc"))'))), Integer.fromint(99))
def test_copy_equal(self): self.assertEvalsTo(u"(copy (list 1 2))", List([Integer.fromint(1), Integer.fromint(2)]))
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)
def test_join(self): self.assertEvalsTo( u"(join (list 1) (list) (list 2 3))", List([Integer.fromint(1), Integer.fromint(2), Integer.fromint(3)]))
def test_push_list(self): expected = List([Integer.fromint(1)]) self.assertEvalsTo(u"(set-symbol! (quote x) (quote ())) (push! x 1) x", expected)
def test_function(self): self.assertEvalsTo(u"(function x () 1) (x)", Integer.fromint(1))
def test_dec_macro(self): self.assertEvalsTo(u"(set! x 2) (dec! x) x", Integer.fromint(1))