mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-12 12:49:13 +03:00
af1d0065e2
Indexing from zero is consistent with the rest of Carp's indexing behavior, so this should make the function more predictable. I've also added a note to the docs about this.
61 lines
1.3 KiB
Plaintext
61 lines
1.3 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)))
|
|
|
|
(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
|
|
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")
|
|
)
|