diff options
Diffstat (limited to 'stdlib/source/test/lux/data/sum.lux')
-rw-r--r-- | stdlib/source/test/lux/data/sum.lux | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/data/sum.lux b/stdlib/source/test/lux/data/sum.lux new file mode 100644 index 000000000..d47922304 --- /dev/null +++ b/stdlib/source/test/lux/data/sum.lux @@ -0,0 +1,37 @@ +(.module: + [lux #* + [control + pipe] + [data + sum + ["." text] + [collection + ["." list]]]] + lux/test) + +(context: "Sum operations" + (let [(^open "List/.") (list.equivalence text.equivalence)] + ($_ seq + (test "Can inject values into Either." + (and (|> (left "Hello") (case> (0 "Hello") #1 _ #0)) + (|> (right "World") (case> (1 "World") #1 _ #0)))) + + (test "Can discriminate eithers based on their cases." + (let [[_lefts _rights] (partition (: (List (| Text Text)) + (list (0 "+0") (1 "+1") (0 "+2"))))] + (and (List/= _lefts + (lefts (: (List (| Text Text)) + (list (0 "+0") (1 "+1") (0 "+2"))))) + + (List/= _rights + (rights (: (List (| Text Text)) + (list (0 "+0") (1 "+1") (0 "+2")))))))) + + (test "Can apply a function to an Either value depending on the case." + (and (i/= +10 (either (function (_ _) +10) + (function (_ _) +20) + (: (| Text Text) (0 "")))) + (i/= +20 (either (function (_ _) +10) + (function (_ _) +20) + (: (| Text Text) (1 "")))))) + ))) |