mirror of
https://github.com/kanaka/mal.git
synced 2024-09-11 13:55:55 +03:00
I just introduced a bug in the BBC BASIC implementation meaning that 'load-file' was broken on files over 255 bytes long, and it was only caught by the optional test of 'time-ms' in step A. This change brings forward the relevant part of that test so the failure can be detected earlier and more obviously, at the same time as the other tests of 'load-file'.
144 lines
1.9 KiB
Plaintext
144 lines
1.9 KiB
Plaintext
;;; TODO: really a step5 test
|
|
;;
|
|
;; Testing that (do (do)) not broken by TCO
|
|
(do (do 1 2))
|
|
;=>2
|
|
|
|
;;
|
|
;; Testing read-string, eval and slurp
|
|
(read-string "(1 2 (3 4) nil)")
|
|
;=>(1 2 (3 4) nil)
|
|
|
|
(read-string "(+ 2 3)")
|
|
;=>(+ 2 3)
|
|
|
|
(read-string "7 ;; comment")
|
|
;=>7
|
|
|
|
;;; Differing output, but make sure no fatal error
|
|
(read-string ";; comment")
|
|
|
|
|
|
(eval (read-string "(+ 2 3)"))
|
|
;=>5
|
|
|
|
(slurp "../tests/test.txt")
|
|
;=>"A line of text\n"
|
|
|
|
;; Testing load-file
|
|
|
|
(load-file "../tests/inc.mal")
|
|
(inc1 7)
|
|
;=>8
|
|
(inc2 7)
|
|
;=>9
|
|
(inc3 9)
|
|
;=>12
|
|
|
|
;;
|
|
;; Testing atoms
|
|
|
|
(def! inc3 (fn* (a) (+ 3 a)))
|
|
|
|
(def! a (atom 2))
|
|
;=>(atom 2)
|
|
|
|
(atom? a)
|
|
;=>true
|
|
|
|
(atom? 1)
|
|
;=>false
|
|
|
|
(deref a)
|
|
;=>2
|
|
|
|
(reset! a 3)
|
|
;=>3
|
|
|
|
(deref a)
|
|
;=>3
|
|
|
|
(swap! a inc3)
|
|
;=>6
|
|
|
|
(deref a)
|
|
;=>6
|
|
|
|
(swap! a (fn* (a) a))
|
|
;=>6
|
|
|
|
(swap! a (fn* (a) (* 2 a)))
|
|
;=>12
|
|
|
|
(swap! a (fn* (a b) (* a b)) 10)
|
|
;=>120
|
|
|
|
(swap! a + 3)
|
|
;=>123
|
|
|
|
;; Testing swap!/closure interaction
|
|
(def! inc-it (fn* (a) (+ 1 a)))
|
|
(def! atm (atom 7))
|
|
(def! f (fn* () (swap! atm inc-it)))
|
|
(f)
|
|
;=>8
|
|
(f)
|
|
;=>9
|
|
|
|
;>>> deferrable=True
|
|
;;
|
|
;; -------- Deferrable Functionality --------
|
|
|
|
;; Testing reading of large files
|
|
(load-file "../tests/computations.mal")
|
|
;=>nil
|
|
(sumdown 2)
|
|
;=>3
|
|
(fib 2)
|
|
;=>1
|
|
|
|
;>>> optional=True
|
|
;;
|
|
;; -------- Optional Functionality --------
|
|
|
|
;; Testing comments in a file
|
|
(load-file "../tests/incB.mal")
|
|
;/"incB.mal finished"
|
|
;=>"incB.mal return string"
|
|
(inc4 7)
|
|
;=>11
|
|
(inc5 7)
|
|
;=>12
|
|
|
|
;; Testing map literal across multiple lines in a file
|
|
(load-file "../tests/incC.mal")
|
|
mymap
|
|
;=>{"a" 1}
|
|
|
|
;; Testing `@` reader macro (short for `deref`)
|
|
(def! atm (atom 9))
|
|
@atm
|
|
;=>9
|
|
|
|
;;; TODO: really a step5 test
|
|
;; Testing that vector params not broken by TCO
|
|
(def! g (fn* [] 78))
|
|
(g)
|
|
;=>78
|
|
(def! g (fn* [a] (+ a 78)))
|
|
(g 3)
|
|
;=>81
|
|
|
|
;; Checking that eval does not use local environments.
|
|
(def! a 1)
|
|
;=>1
|
|
(let* (a 2) (eval (read-string "a")))
|
|
;=>1
|
|
|
|
;;
|
|
;; Testing that *ARGV* exists and is an empty list
|
|
(list? *ARGV*)
|
|
;=>true
|
|
*ARGV*
|
|
;=>()
|