From a982f351d71aa655491a1089046b0a40d809755d Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Wed, 20 Feb 2019 12:07:20 -0500 Subject: [PATCH] Address #50 Issues with range when called with 3 arguments. --- src/core/core.janet | 4 ++-- test/suite4.janet | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/core.janet b/src/core/core.janet index 9185512c..0194dbc0 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -702,8 +702,8 @@ arr) 3 (do (def [n m s] args) - (def arr (array/new n)) - (loop [i :range [n m s]] (put arr (- i n) i)) + (def arr (array/new (math/ceil (/ n s)))) + (loop [i :range [n m s]] (array/push arr i)) arr) (error "expected 1 to 3 arguments to range"))) diff --git a/test/suite4.janet b/test/suite4.janet index b89d963a..5fbb9055 100644 --- a/test/suite4.janet +++ b/test/suite4.janet @@ -38,5 +38,10 @@ (assert (= (string/format "π = %.8g" math/pi) "π = 3.1415927") "π") (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)