Add unit tests for lib.functions.range

This commit is contained in:
2025-02-21 13:58:58 +00:00
parent 53174000df
commit 4b4421c101
2 changed files with 10 additions and 1 deletions

View File

@@ -22,7 +22,7 @@
(fn range (start end &optional (step 1)) (-> (fixnum fixnum &optional fixnum) list)
"Make a list of numbers from START to END (exclusive). If STEP is given, then
each member is STEP distance apart."
(if (<= end start)
(if (< end start)
(error (format nil "~a < ~a" end start))
(loop :for i :from start :to (1- end) :by step
:collect i)))

View File

@@ -30,3 +30,12 @@
(is eq nil (parse-integer* "a2048abcdef"))
(is eq nil (parse-integer* "garbage"))
(fail (parse-integer* nil)))
(define-test (function-test range)
:compile-at :execute
(fail (range 1 0))
(fail (range nil nil))
(fail (range "a" "b"))
(true (null (range 1 1)))
(is equal '(1 2 3 4) (range 1 5))
(is equal '(-3 -2 -1 0) (range -3 1)))