2 ;;; See IMPL/tests/stepA_mal.mal for implementation specific
9 (readline "mal-user> ")
14 ;; Testing *host-language*
15 ;;; each impl is different, but this should return false
16 ;;; rather than throwing an exception
17 (= "something bogus" *host-language*)
23 ;; ------- Deferrable Functionality ----------
24 ;; ------- (Needed for self-hosting) -------
28 ;; Testing hash-map evaluation and atoms (i.e. an env)
29 (def! e (atom {"+" +}))
35 (swap! e assoc "foo" (list))
38 (swap! e assoc "bar" '(1 2 3))
42 ;; Testing for presence of optional functions
43 (do (list time-ms string? number? seq conj meta with-meta fn?) nil)
46 ;; ------------------------------------------------------------------
51 ;; ------- Optional Functionality --------------
52 ;; ------- (Not needed for self-hosting) -------
54 ;; Testing metadata on functions
57 ;; Testing metadata on mal functions
62 (meta (with-meta (fn* (a) a) {"b" 1}))
65 (meta (with-meta (fn* (a) a) "abc"))
68 (def! l-wm (with-meta (fn* (a) a) {"b" 2}))
72 (meta (with-meta l-wm {"new_meta" 123}))
77 (def! f-wm (with-meta (fn* [a] (+ 1 a)) {"abc" 1}))
81 (meta (with-meta f-wm {"new_meta" 123}))
86 (def! f-wm2 ^{"abc" 1} (fn* [a] (+ 1 a)))
90 ;; Meta of native functions should return nil (not fail)
95 ;; Make sure closures and metadata co-exist
96 (def! gen-plusX (fn* (x) (with-meta (fn* (b) (+ x b)) {"meta" 1})))
97 (def! plus7 (gen-plusX 7))
98 (def! plus8 (gen-plusX 8))
105 (meta (with-meta plus7 {"meta" 2}))
111 ;; Testing string? function
120 (string? (keyword "abc"))
127 ;; Testing number? function
139 (def! add1 (fn* (x) (+ x 1)))
141 ;; Testing fn? function
152 (fn? ^{"ismacro" true} (fn* () 0))
155 ;; Testing macro? function
171 ;; Testing conj function
178 (conj (list 2 3) 4 5 6)
180 (conj (list 1) (list 2 3))
195 ;; Testing seq function
198 (apply str (seq "this is a test"))
215 ;; Testing metadata on collections
220 (with-meta [1 2 3] {"a" 1})
223 (meta (with-meta [1 2 3] {"a" 1}))
226 (vector? (with-meta [1 2 3] {"a" 1}))
229 (meta (with-meta [1 2 3] "abc"))
235 (meta (with-meta (list 1 2 3) {"a" 1}))
238 (list? (with-meta (list 1 2 3) {"a" 1}))
241 (with-meta (list) {"a" 1})
244 (empty? (with-meta (list) {"a" 1}))
247 (meta (with-meta {"abc" 123} {"a" 1}))
250 (map? (with-meta {"abc" 123} {"a" 1}))
253 (with-meta {} {"a" 1})
256 (def! l-wm (with-meta [4 5 6] {"b" 2}))
261 (meta (with-meta l-wm {"new_meta" 123}))
267 ;; Testing metadata on builtin functions
270 (def! f-wm3 ^{"def" 2} +)
276 ;; Loading sumdown from computations.mal
277 (load-file "../tests/computations.mal")
281 ;; Testing time-ms function
282 (def! start-time (time-ms))
285 (sumdown 10) ; Waste some time
287 (> (time-ms) start-time)
291 ;; Test that defining a macro does not mutate an existing function.
292 (def! f (fn* [x] (number? x)))