Carp/test/regression.carp
2020-06-23 12:26:53 +02:00

79 lines
2.2 KiB
Plaintext

(relative-include "fixture_foo.h")
(load "Test.carp")
(load "Vector.carp")
; this is a test-only module to test module resolution (see #288)
(defmodule Foo
(register init (Fn [] Int) "fooInit")
)
; test whether sumtypes with single cases get classified correctly
(deftype (SumT x)
(SingleC [x]))
; make sure nested lambdas don't break again (issue #342)
(defn nested-lambdas []
(let [f (fn [x] ((fn [y] (+ x y))
1))]
(f 1)))
; make sure let bindings get updated in the right scope
(defmacro let-and-set []
(let-do [x 1]
(let [] (set! x 2))
(= x 2)))
; make sure that match-ref doesn't delete references (issue #843)
(deftype StrangeThings
(Piff [String])
(Puff [String]))
(defn match-ref-1 []
(let [xs [(StrangeThings.Puff @"ABCD")]]
(match-ref (Array.unsafe-nth &xs 0)
(StrangeThings.Piff x) false
_ true)))
(use-all Test Vector2 Foo)
(defn test-unreachable []
(match (the (Maybe Int) (Maybe.Nothing))
(Maybe.Nothing) true
_ (unreachable "test unreachable")))
(deftest test
(assert-equal test
1
(init)
"test that the right module gets resolved")
(assert-equal test
\\
(String.char-at "\\" 0)
"test that strings get escaped correctly")
(assert-equal test
Int.MAX
@&Int.MAX
"test that the address of Int.MAX can be taken")
(assert-equal test
&(Result.Error System.ENOENT)
&(IO.read->EOF "foobar")
"test that reading from an undefined file works")
(assert-equal test
"(SingleC 1)"
&(str &(SumT.SingleC 1))
"test that sumtypes with single cases work")
(assert-equal test
2
(nested-lambdas)
"test that nested lambdas can use captured values")
(assert-true test
(let-and-set)
"test that nested let bindings and set! interplay nicely")
(assert-true test
(match-ref-1)
"test that match-ref doesn't delete references")
(assert-true test
(test-unreachable)
"test that unreachable works (as best possible)")
)