(range...)

This commit is contained in:
2020-12-07 19:12:22 -07:00
parent 6866c7133d
commit 74d070d7b3
4 changed files with 45 additions and 2 deletions

View File

@@ -246,6 +246,10 @@ class BasicTestCase extends Test {
function testMaps() {
_testMaps();
}
function testRange() {
_testRange();
}
}
class BasicObject {

View File

@@ -349,8 +349,22 @@
(doFor =>key value myMap
(Assert.isTrue (<= 0 (.indexOf ["hey" "found"] key)))
(Assert.isTrue (<= 0 (.indexOf ["you" "me"] value))))
// Map destructuring:
(let [[=>"hey" v1 =>"found" v2] myMap]
(Assert.equals "you" v1)
(Assert.equals "me" v2)))
(Assert.equals "me" v2)))
(defun _testRange []
// With just one arg, it's the max:
(deflocal &mut :kiss.List<Int> myList (for i (range 5) i))
(Assert.equals 4 (nth myList -1))
// with two args, they are min and max:
(set myList (for i (range 3 5) i))
(Assert.equals 3 (first myList))
(Assert.equals 4 (last myList))
// With three args, they are min, max, and step:
(set myList (for i (range 7 17 2) i))
(Assert.equals 7 (first myList))
(Assert.equals 9 (second myList))
(Assert.equals 15 (last myList)))