aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/data/name.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/test/lux/data/name.lux')
-rw-r--r--stdlib/source/test/lux/data/name.lux73
1 files changed, 73 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/data/name.lux b/stdlib/source/test/lux/data/name.lux
new file mode 100644
index 000000000..3855fe221
--- /dev/null
+++ b/stdlib/source/test/lux/data/name.lux
@@ -0,0 +1,73 @@
+(.module:
+ [lux #*
+ [control
+ [monad (#+ do Monad)]
+ pipe]
+ [data
+ ["&" name]
+ ["." text ("text/." equivalence)
+ format]]
+ [math
+ ["r" random]]]
+ lux/test)
+
+(def: (gen-part size)
+ (-> Nat (r.Random Text))
+ (|> (r.unicode size) (r.filter (|>> (text.contains? ".") not))))
+
+(context: "Names"
+ (<| (times 100)
+ (do @
+ [## First Name
+ sizeM1 (|> r.nat (:: @ map (n/% 100)))
+ sizeN1 (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1))))
+ module1 (gen-part sizeM1)
+ short1 (gen-part sizeN1)
+ #let [name1 [module1 short1]]
+ ## Second Name
+ sizeM2 (|> r.nat (:: @ map (n/% 100)))
+ sizeN2 (|> r.nat (:: @ map (|>> (n/% 100) (n/max 1))))
+ module2 (gen-part sizeM2)
+ short2 (gen-part sizeN2)
+ #let [name2 [module2 short2]]
+ #let [(^open "&/.") &.equivalence
+ (^open "&/.") &.codec]]
+ ($_ seq
+ (test "Can get the module & short parts of an name."
+ (and (is? module1 (&.module name1))
+ (is? short1 (&.short name1))))
+
+ (test "Can compare names for equivalence."
+ (and (&/= name1 name1)
+ (if (&/= name1 name2)
+ (and (text/= module1 module2)
+ (text/= short1 short2))
+ (or (not (text/= module1 module2))
+ (not (text/= short1 short2))))))
+
+ (test "Can encode names as text."
+ (|> name1
+ &/encode &/decode
+ (case> (#.Right dec-name) (&/= name1 dec-name)
+ _ #0)))
+
+ (test "Encoding an name without a module component results in text equal to the short of the name."
+ (if (text.empty? module1)
+ (text/= short1 (&/encode name1))
+ #1))
+ ))))
+
+(context: "Name-related macros."
+ (let [(^open "&/.") &.equivalence]
+ ($_ seq
+ (test "Can obtain Name from identifier."
+ (and (&/= ["lux" "yolo"] (name-of .yolo))
+ (&/= ["test/lux/data/name" "yolo"] (name-of ..yolo))
+ (&/= ["" "yolo"] (name-of yolo))
+ (&/= ["lux/test" "yolo"] (name-of lux/test.yolo))))
+
+ (test "Can obtain Name from tag."
+ (and (&/= ["lux" "yolo"] (name-of #.yolo))
+ (&/= ["test/lux/data/name" "yolo"] (name-of #..yolo))
+ (&/= ["" "yolo"] (name-of #yolo))
+ (&/= ["lux/test" "yolo"] (name-of #lux/test.yolo)))))))