mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
72 lines
1.6 KiB
Plaintext
72 lines
1.6 KiB
Plaintext
(load "Test.carp")
|
|
(use-all Test Introspect)
|
|
|
|
(defn foo [x] x)
|
|
(defn add [x y] (+ x y))
|
|
(def bar 2)
|
|
(deftype Foo [x Int])
|
|
(deftype Bar (Of [Int]))
|
|
(definterface baz (Fn [a] a))
|
|
(defmodule Qux (defn id [x] x))
|
|
|
|
(defmacro test-function? [x]
|
|
(eval (list 'Introspect.function? x)))
|
|
|
|
(defmacro test-variable? [x]
|
|
(eval (list 'Introspect.variable? x)))
|
|
|
|
(defmacro test-module? [x]
|
|
(eval (list 'Introspect.module? x)))
|
|
|
|
(defmacro test-struct? [x]
|
|
(eval (list 'Introspect.struct? x)))
|
|
|
|
(defmacro test-sumtype? [x]
|
|
(eval (list 'Introspect.sumtype? x)))
|
|
|
|
(defmacro test-interface? [x]
|
|
(eval (list 'Introspect.interface? x)))
|
|
|
|
(defmacro test-arity [x]
|
|
(eval (list 'Introspect.arity x)))
|
|
|
|
(defmacro test-arguments [x]
|
|
(collect-into
|
|
(map
|
|
(fn [arg] `(copy %(str arg)))
|
|
(eval `(Introspect.arguments %x)))
|
|
array))
|
|
|
|
(deftest test
|
|
(assert-true test
|
|
(test-function? foo)
|
|
"function? works as expected")
|
|
(assert-true test
|
|
(test-variable? bar)
|
|
"variable? works as expected")
|
|
(assert-true test
|
|
(test-struct? Foo)
|
|
"struct? works as expected")
|
|
(assert-true test
|
|
(test-sumtype? Bar)
|
|
"sumtype? works as expected")
|
|
(assert-true test
|
|
(test-interface? baz)
|
|
"interface? works as expected")
|
|
(assert-true test
|
|
(test-module? Qux)
|
|
"module? works as expected")
|
|
(assert-equal test
|
|
&[@"x"]
|
|
&(test-arguments foo)
|
|
"arguments works as expected")
|
|
(assert-equal test
|
|
1
|
|
(test-arity foo)
|
|
"arity works as expected")
|
|
(assert-equal test
|
|
6
|
|
(Array.reduce (Introspect.with-copy add 1) 0 &[1 2 3])
|
|
"with-copy works as expected")
|
|
)
|