diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-27 18:28:23 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-27 18:29:23 -0700 |
| commit | 2e15c0fd5067318601e2f3b70ee6fc16ef58200d (patch) | |
| tree | 0006e0825b2680d457bb531c3d079661b16d6bc8 /tests | |
| parent | 6ce32bdd25694d71dc232c50a008f8824f8a75ce (diff) | |
Some tweaks/cleanup on the nomsu code as well as adding variable
mangling to 'parse % as %' to make almost hygienic macros.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/collections.nom | 6 | ||||
| -rw-r--r-- | tests/math.nom | 2 | ||||
| -rw-r--r-- | tests/metaprogramming.nom | 15 |
3 files changed, 19 insertions, 4 deletions
diff --git a/tests/collections.nom b/tests/collections.nom index 04b8a78..6329d00 100644 --- a/tests/collections.nom +++ b/tests/collections.nom @@ -31,15 +31,15 @@ assume ((values in {x:1}) = [1]) %x <- [3,1,2] sort %x assume (%x = [1,2,3]) -sort %x by (-%) +sort %x by % = (-%) assume (%x = [3,2,1]) %keys <- {1:999,2:0,3:50} -sort %x by (% in %keys) +sort %x by % = %keys.% assume (%x = [2,3,1]) assume ((unique [1,2,1,3,2,3]) = [1,2,3]) %c <- (new counter) for % in ["x","y","x","x","y"] - (% in %c) +<- 1 + %c.% +<- 1 assume (%c = {x:3,y:2}) say "Collections test passed." diff --git a/tests/math.nom b/tests/math.nom index 4232d81..8cfd0f4 100644 --- a/tests/math.nom +++ b/tests/math.nom @@ -15,5 +15,7 @@ assume ..or barf "math functions failed" assume ((463 to the nearest 100) = 500) or barf "rounding failed" assume ((2.6 to the nearest 0.25) = 2.5) or barf "rounding failed" +assume ((min of [3,-4,1,2] by % = (%*%)) = 1) +assume ((max of [3,-4,1,2] by % = (%*%)) = -4) say "Math test passed" diff --git a/tests/metaprogramming.nom b/tests/metaprogramming.nom index 9a4c9b2..26a750a 100644 --- a/tests/metaprogramming.nom +++ b/tests/metaprogramming.nom @@ -36,7 +36,20 @@ immediately parse [V] as: five assume ((V) = 5) or barf "Parse as compile action failed." -remove action "foo %" +immediately + parse [swap %x and %y] as + do + %tmp <- %x + %x <- %y + %y <- %tmp +<- {%1:1, %2:2} +swap %1 and %2 +assume ((%1 = 2) and (%2 = 1)) or barf "'parse % as %' failed on 'swap % and %'" +<- {%tmp:1, %tmp2:2} +swap %tmp and %tmp2 +assume ((%tmp = 2) and (%tmp2 = 1)) or barf "'parse % as %' variable mangling failed." + +remove action (foo %) try: foo 99 ..and if it succeeds: barf "Failed to delete action" |
