aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test
diff options
context:
space:
mode:
authorEduardo Julian2017-09-05 19:43:22 -0400
committerEduardo Julian2017-09-05 19:43:22 -0400
commit223ce32a52276f9a85fdd7918a46b58b4223738c (patch)
tree58914a548a62a1322b678aed74bf16c3fb0daad4 /new-luxc/test
parentb3e5ca5f28e4bc54613dbfd6d6df1ef51d724707 (diff)
- Added alternative syntax for Frac numbers, based on traditional ratio/fraction syntax.
Diffstat (limited to 'new-luxc/test')
-rw-r--r--new-luxc/test/test/luxc/parser.lux22
1 files changed, 22 insertions, 0 deletions
diff --git a/new-luxc/test/test/luxc/parser.lux b/new-luxc/test/test/luxc/parser.lux
index 7a0b2c278..4c1b65584 100644
--- a/new-luxc/test/test/luxc/parser.lux
+++ b/new-luxc/test/test/luxc/parser.lux
@@ -84,6 +84,28 @@
(:: code;Eq<Code> = parsed sample))
))
+(def: nat-to-frac
+ (-> Nat Frac)
+ (|>. nat-to-int int-to-frac))
+
+(context: "Frac special syntax."
+ [numerator (|> r;nat (:: @ map (|>. (n.% +100) nat-to-frac)))
+ denominator (|> r;nat (:: @ map (|>. (n.% +100) (n.max +1) nat-to-frac)))
+ signed? r;bool
+ #let [expected (|> numerator (f./ denominator) (f.* (if signed? -1.0 1.0)))]]
+ (test "Can parse frac ratio syntax."
+ (case (&;parse [default-cursor
+ (format (if signed? "-" "")
+ (%i (frac-to-int numerator))
+ "/"
+ (%i (frac-to-int denominator)))])
+ (#R;Success [_ [_ (#;Frac actual)]])
+ (f.= expected actual)
+
+ _
+ false)
+ ))
+
(def: comment-text^
(r;Random Text)
(let [char-gen (|> r;nat (r;filter (function [value]