1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-16 13:44:48 +00:00

Merge pull request #639 from leahneukirchen/or

Fix or with zero arguments
This commit is contained in:
Calvin Rose 2021-02-16 16:57:21 -06:00 committed by GitHub
commit 8320e25d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -277,7 +277,8 @@
[& forms] [& forms]
(def len (length forms)) (def len (length forms))
(var i (- len 1)) (var i (- len 1))
(var ret (in forms i)) (var ret (if (= 0 len) nil
(in forms i)))
(while (> i 0) (while (> i 0)
(-- i) (-- i)
(def fi (in forms i)) (def fi (in forms i))

View File

@ -294,4 +294,25 @@
(sort (mapcat (fn [[x y z]] [z y x]) (partition 3 (range 99))))) "sort 5") (sort (mapcat (fn [[x y z]] [z y x]) (partition 3 (range 99))))) "sort 5")
(assert (<= ;(sort (map (fn [x] (math/random)) (range 1000)))) "sort 6") (assert (<= ;(sort (map (fn [x] (math/random)) (range 1000)))) "sort 6")
# And and or
(assert (= (and true true) true) "and true true")
(assert (= (and true false) false) "and true false")
(assert (= (and false true) false) "and false true")
(assert (= (and true true true) true) "and true true true")
(assert (= (and 0 1 2) 2) "and 0 1 2")
(assert (= (and 0 1 nil) nil) "and 0 1 nil")
(assert (= (and 1) 1) "and 1")
(assert (= (and) true) "and with no arguments")
(assert (= (or true true) true) "or true true")
(assert (= (or true false) true) "or true false")
(assert (= (or false true) true) "or false true")
(assert (= (or false false) false) "or false true")
(assert (= (or true true false) true) "or true true false")
(assert (= (or 0 1 2) 0) "or 0 1 2")
(assert (= (or nil 1 2) 1) "or nil 1 2")
(assert (= (or 1) 1) "or 1")
(assert (= (or) nil) "or with no arguments")
(end-suite) (end-suite)