aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorThe Lux Programming Language2017-09-19 20:31:06 -0400
committerGitHub2017-09-19 20:31:06 -0400
commit61b92fcab969231092f1bb41ef9a6021a498dc8f (patch)
tree56b0d83be9a92205f18a35286dec4cb93a336d98 /stdlib
parent3744a2212a89d4ab0f176350d2d2f90696235a40 (diff)
parentccc065035fd06496ece9c7ddb0ef20f436265723 (diff)
Merge pull request #34 from mccraigmccraig/fix-duration-tests
fix duration frame and encoding tests
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/time/duration.lux2
-rw-r--r--stdlib/test/test/lux/time/duration.lux38
2 files changed, 23 insertions, 17 deletions
diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux
index 61f2452a6..2adc023a2 100644
--- a/stdlib/source/lux/time/duration.lux
+++ b/stdlib/source/lux/time/duration.lux
@@ -102,7 +102,7 @@
(def: (lex-section suffix)
(-> Text (l;Lexer Int))
(|> (p;codec number;Codec<Text,Int> (l;many l;decimal))
- (p;before (l;this suffix))
+ (p;before (p;seq (l;this suffix) (p;not l;alpha)))
(p;default 0)))
(def: lex-duration
diff --git a/stdlib/test/test/lux/time/duration.lux b/stdlib/test/test/lux/time/duration.lux
index 020c198e6..d10b9b57c 100644
--- a/stdlib/test/test/lux/time/duration.lux
+++ b/stdlib/test/test/lux/time/duration.lux
@@ -49,26 +49,32 @@
(test "Merging a duration with it's opposite yields an empty duration."
(|> sample (@;merge (@;scale -1 sample)) (@/= @;empty)))
(test "Can frame a duration in terms of another."
- (if (or (and (@;positive? frame) (@;positive? sample))
- (and (@;negative? frame) (@;negative? sample)))
- (|> sample (@;frame frame) (@/< frame))
- (or (or (@;neutral? frame) (@;neutral? sample))
- (|> sample (@;frame frame) (@;scale -1) (@/< (if (@;negative? frame)
- (@;scale -1 frame)
- frame))))))
- ))
+ (cond (and (@;positive? frame) (@;positive? sample))
+ (|> sample (@;frame frame) (@/< frame))
+
+ (and (@;negative? frame) (@;negative? sample))
+ (|> sample (@;frame frame) (@/> frame))
+
+ (or (or (@;neutral? frame) (@;neutral? sample))
+ (|> sample
+ (@;frame frame)
+ (@;scale -1)
+ (@/< (if (@;negative? frame)
+ (@;scale -1 frame)
+ frame))))))))
(context: "Codec"
#seed +9664448049824422386
[sample duration
#let [(^open "@/") @;Eq<Duration>
(^open "@/") @;Codec<Text,Duration>]]
- (test "Can encode/decode durations."
- (|> sample
- @/encode
- @/decode
- (pipe;case> (#R;Success decoded)
- (@/= sample decoded)
+ (exec
+ (test "Can encode/decode durations."
+ (|> sample
+ @/encode
+ @/decode
+ (pipe;case> (#R;Success decoded)
+ (@/= sample decoded)
- (#R;Error error)
- false))))
+ (#R;Error error)
+ false)))))