diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/collections.nom | 6 | ||||
| -rw-r--r-- | tests/control_flow.nom | 27 |
2 files changed, 12 insertions, 21 deletions
diff --git a/tests/collections.nom b/tests/collections.nom index 60b2d25..04b8a78 100644 --- a/tests/collections.nom +++ b/tests/collections.nom @@ -19,10 +19,10 @@ pop from %list assume ((last in %list) = 5) remove index 1 from %list assume ((first in %list) = 2) -assume (((% * %) for all [1,2,3]) = [1,4,9]) +assume (((% * %) for % in [1,2,3]) = [1,4,9]) assume ((%k = (%v * %v) for %k = %v in {x:1,y:2,z:3}) = {x:1,y:4,z:9}) assume ((%k for %k = %v in {x:1}) = ["x"]) -assume ((% = (% * %) for all [1,2,3]) = {1:1,2:4,3:9}) +assume ((% = (% * %) for % in [1,2,3]) = {1:1,2:4,3:9}) assume (([[1,2],[3,4]] flattened) = [1,2,3,4]) assume ((entries in {x:1}) = [{key:"x",value:1}]) assume ((keys in {x:1}) = ["x"]) @@ -38,7 +38,7 @@ sort %x by (% in %keys) assume (%x = [2,3,1]) assume ((unique [1,2,1,3,2,3]) = [1,2,3]) %c <- (new counter) -for all ["x","y","x","x","y"] +for % in ["x","y","x","x","y"] (% in %c) +<- 1 assume (%c = {x:3,y:2}) diff --git a/tests/control_flow.nom b/tests/control_flow.nom index 899da22..40b344f 100644 --- a/tests/control_flow.nom +++ b/tests/control_flow.nom @@ -1,4 +1,4 @@ -#.. +# Tests for the stuff defined in lib/control_flow.nom use "core" @@ -40,11 +40,6 @@ for %x in [1,2,3] %tot +<- %x assume (%tot = 6) or barf "for-loop failed" -%tot <- 0 -for all [1,2,3] - %tot +<- % -assume (%tot = 6) or barf "for-all-loop failed" - %x <- 0 repeat %x +<- 1 @@ -58,7 +53,7 @@ repeat 5 times assume (%x = 5) or barf "Failed to repeat 5 times" <- {%x:0,%y:0} -for all [1,2,3] +for % in [1,2,3] repeat 5 times do next repeat %x +<- 1 @@ -66,7 +61,7 @@ for all [1,2,3] assume ([%x,%y] = [0,3]) or barf "Failed to continue repeat" <- {%x:0,%y:0} -for all [1,2,3] +for % in [1,2,3] repeat 5 times do next % %x +<- 1 @@ -74,7 +69,7 @@ for all [1,2,3] assume ([%x,%y] = [0,0]) or barf "Failed to continue for" <- {%x:0,%y:0} -for all [1,2,3] +for % in [1,2,3] repeat 5 times stop repeating %x +<- 1 @@ -82,7 +77,7 @@ for all [1,2,3] assume ([%x,%y] = [0,3]) or barf "Failed to stop repeat" <- {%x:0,%y:0} -for all [1,2,3] +for % in [1,2,3] repeat 5 times stop % %x +<- 1 @@ -100,17 +95,13 @@ repeat until: %x = 10 assume (%x = 10) or barf "repeat-until failed" %x <- 0 -for %i from 1 to 3: %x +<- %i +for %i in 1 to 3: %x +<- %i assume (%x = 6) or barf "Numeric for range failed" %x <- 0 -for %i from 3 to 1 via -1: %x +<- %i +for %i in 3 to 1 via -1: %x +<- %i assume (%x = 6) or barf "backwards numeric for range failed" -%x <- 0 -for all 1 to 3: %x +<- % -assume (%x = 6) or barf "terse numeric for range failed" - %result <- {} for %key = %value in {x:1,y:2} (%result's ("\%key\%key")) <- (%value * 11) @@ -197,12 +188,12 @@ assume (..) result of %n <- 0 - for all [1,2,3]: %n +<- % + for % in [1,2,3]: %n +<- % return %n ..= 6 %nums <- [] -for all +for % in values -> 4 -> 5 |
