From 223ce32a52276f9a85fdd7918a46b58b4223738c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 5 Sep 2017 19:43:22 -0400 Subject: - Added alternative syntax for Frac numbers, based on traditional ratio/fraction syntax. --- new-luxc/test/test/luxc/parser.lux | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'new-luxc/test') 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 = 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] -- cgit v1.2.3