From 75dc08ff21219254e7efa0108c2c2af5cb221cba Mon Sep 17 00:00:00 2001 From: Quan Nguyen Date: Sun, 10 Mar 2019 13:50:28 +0700 Subject: [PATCH] Fix nil error on drop-until fn --- src/core/core.janet | 4 +++- test/suite5.janet | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core/core.janet b/src/core/core.janet index 6c61558d..08359188 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -703,7 +703,9 @@ the predicate, and abort on first failure. Returns a new array." [pred ind] (def i (find-index pred ind)) - (array/slice ind i)) + (if i + (array/slice ind i) + @[])) (defn drop-while "Same as (drop-until (complement pred) ind)." diff --git a/test/suite5.janet b/test/suite5.janet index e0fcbb47..cf24b654 100644 --- a/test/suite5.janet +++ b/test/suite5.janet @@ -80,4 +80,12 @@ (assert-no-error "break 3" (for i 0 10 (if (> i 8) (break i)))) (assert-no-error "break 4" ((fn [i] (if (> i 8) (break i))) 100)) +# drop-until + +(assert (deep= (drop-until pos? @[]) @[]) "drop-until 1") +(assert (deep= (drop-until pos? @[1 2 3]) @[1 2 3]) "drop-until 2") +(assert (deep= (drop-until pos? @[-1 -2 -3]) @[]) "drop-until 3") +(assert (deep= (drop-until pos? @[-1 -2 3]) @[3]) "drop-until 4") +(assert (deep= (drop-until pos? @[-1 1 -2]) @[1 -2]) "drop-until 5") + (end-suite)