1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-12 16:40:27 +00:00
Issues with range when called with 3 arguments.
This commit is contained in:
Calvin Rose 2019-02-20 12:07:20 -05:00
parent 27a274b686
commit a982f351d7
2 changed files with 7 additions and 2 deletions

View File

@ -702,8 +702,8 @@
arr) arr)
3 (do 3 (do
(def [n m s] args) (def [n m s] args)
(def arr (array/new n)) (def arr (array/new (math/ceil (/ n s))))
(loop [i :range [n m s]] (put arr (- i n) i)) (loop [i :range [n m s]] (array/push arr i))
arr) arr)
(error "expected 1 to 3 arguments to range"))) (error "expected 1 to 3 arguments to range")))

View File

@ -38,5 +38,10 @@
(assert (= (string/format "π = %.8g" math/pi) "π = 3.1415927") "π") (assert (= (string/format "π = %.8g" math/pi) "π = 3.1415927") "π")
(assert (= (string/format "\xCF\x80 = %.8g" math/pi) "\xCF\x80 = 3.1415927") "\xCF\x80") (assert (= (string/format "\xCF\x80 = %.8g" math/pi) "\xCF\x80 = 3.1415927") "\xCF\x80")
# Range
(assert (deep= (range 10) @[0 1 2 3 4 5 6 7 8 9]) "range 1 argument")
(assert (deep= (range 5 10) @[5 6 7 8 9]) "range 2 arguments")
(assert (deep= (range 5 10 2) @[5 7 9]) "range 3 arguments")
(end-suite) (end-suite)