diff options
Diffstat (limited to 'stdlib/source/test')
-rw-r--r-- | stdlib/source/test/aedifex/artifact/snapshot.lux | 48 | ||||
-rw-r--r-- | stdlib/source/test/aedifex/artifact/snapshot/stamp.lux | 4 | ||||
-rw-r--r-- | stdlib/source/test/lux/meta.lux | 129 | ||||
-rw-r--r-- | stdlib/source/test/lux/type/dynamic.lux | 54 |
4 files changed, 212 insertions, 23 deletions
diff --git a/stdlib/source/test/aedifex/artifact/snapshot.lux b/stdlib/source/test/aedifex/artifact/snapshot.lux new file mode 100644 index 000000000..1bdb9ca2d --- /dev/null +++ b/stdlib/source/test/aedifex/artifact/snapshot.lux @@ -0,0 +1,48 @@ +(.module: + [lux #* + ["_" test (#+ Test)] + [abstract + [monad (#+ do)] + {[0 #spec] + [/ + ["$." equivalence]]}] + [control + ["." try ("#\." functor)] + [parser + ["<.>" xml]]] + [math + ["." random (#+ Random) ("#\." monad)]]] + ["$." / #_ + ["#." build] + ["#." time] + ["#." stamp]] + {#program + ["." /]}) + +(def: #export random + (Random /.Snapshot) + (random.or (random\wrap []) + $/stamp.random)) + +(def: #export test + Test + (<| (_.covering /._) + (_.for [/.Snapshot] + ($_ _.and + (_.for [/.equivalence] + ($equivalence.spec /.equivalence ..random)) + + (do random.monad + [expected ..random] + (_.cover [/.format /.parser] + (|> expected + /.format + list + (<xml>.run /.parser) + (try\map (\ /.equivalence = expected)) + (try.default false)))) + + $/build.test + $/time.test + $/stamp.test + )))) diff --git a/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux index aab722cad..a36e5af9d 100644 --- a/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux +++ b/stdlib/source/test/aedifex/artifact/snapshot/stamp.lux @@ -41,8 +41,8 @@ (_.cover [/.format /.parser] (|> expected /.format - (<xml>.run' /.parser) - (try\map (\ instant.equivalence = expected)) + (<xml>.run /.parser) + (try\map (\ /.equivalence = expected)) (try.default false))) )) ))) diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index ec76184cd..c3d984854 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -3,6 +3,7 @@ ["_" test (#+ Test)] ["." type ("#\." equivalence)] [abstract + [equivalence (#+ Equivalence)] [monad (#+ do)] {[0 #spec] [/ @@ -742,6 +743,133 @@ correct_type!))))))))) ))) +(def: locals_related + Test + (do {! random.monad} + [current_module (random.ascii/upper 1) + [name_0 name_1 name_2 name_3 name_4] (|> (random.ascii/upper 1) + (random.set text.hash 5) + (\ ! map set.to_list) + (random.one (function (_ values) + (case values + (^ (list name_0 name_1 name_2 name_3 name_4)) + (#.Some [name_0 name_1 name_2 name_3 name_4]) + + _ + #.None)))) + #let [type_0 (#.Primitive name_0 (list)) + type_1 (#.Primitive name_1 (list)) + type_2 (#.Primitive name_2 (list)) + type_3 (#.Primitive name_3 (list)) + type_4 (#.Primitive name_4 (list)) + + globals (: (List [Text .Global]) + (list [name_4 + (#.Definition [false type_4 (' {}) []])])) + + scopes (list {#.name (list) + #.inner 0 + #.locals {#.counter 1 + #.mappings (list [name_3 [type_3 3]])} + #.captured {#.counter 0 + #.mappings (list)}} + {#.name (list) + #.inner 0 + #.locals {#.counter 2 + #.mappings (list [name_1 [type_1 1]] + [name_2 [type_2 2]])} + #.captured {#.counter 0 + #.mappings (list)}} + {#.name (list) + #.inner 0 + #.locals {#.counter 1 + #.mappings (list [name_0 [type_0 0]])} + #.captured {#.counter 0 + #.mappings (list)}})] + #let [expected_lux + (: Lux + {#.info {#.target "" + #.version "" + #.mode #.Build} + #.source [location.dummy 0 ""] + #.location location.dummy + #.current_module (#.Some current_module) + #.modules (list [current_module + {#.module_hash 0 + #.module_aliases (list) + #.definitions globals + #.imports (list) + #.tags (list) + #.types (list) + #.module_annotations #.None + #.module_state #.Active}]) + #.scopes scopes + #.type_context {#.ex_counter 0 + #.var_counter 0 + #.var_bindings (list)} + #.expected #.None + #.seed 0 + #.scope_type_vars (list) + #.extensions [] + #.host []})]] + ($_ _.and + (_.cover [/.locals] + (let [equivalence (: (Equivalence (List (List [Text Type]))) + (list.equivalence + (list.equivalence + (product.equivalence + text.equivalence + type.equivalence))))] + (|> /.locals + (/.run expected_lux) + (try\map (\ equivalence = (list (list [name_3 type_3]) + (list [name_1 type_1] + [name_2 type_2])))) + (try.default false)))) + (_.cover [/.find_var_type] + (and (|> (/.find_var_type name_0) + (/.run expected_lux) + (try\map (\ type.equivalence = type_0)) + (try.default false)) + (|> (/.find_var_type name_1) + (/.run expected_lux) + (try\map (\ type.equivalence = type_1)) + (try.default false)) + (|> (/.find_var_type name_2) + (/.run expected_lux) + (try\map (\ type.equivalence = type_2)) + (try.default false)) + (|> (/.find_var_type name_3) + (/.run expected_lux) + (try\map (\ type.equivalence = type_3)) + (try.default false)))) + (_.cover [/.find_type] + (and (|> (/.find_type ["" name_0]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_0)) + (try.default false)) + (|> (/.find_type ["" name_1]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_1)) + (try.default false)) + (|> (/.find_type ["" name_2]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_2)) + (try.default false)) + (|> (/.find_type ["" name_3]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_3)) + (try.default false)) + (|> (/.find_type [current_module name_4]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_4)) + (try.default false)) + (|> (/.find_type ["" name_4]) + (/.run expected_lux) + (try\map (\ type.equivalence = type_4)) + (try.default false)))) + ))) + (def: injection (Injection Meta) (\ /.monad wrap)) @@ -824,6 +952,7 @@ ..definition_related ..search_related ..tags_related + ..locals_related )) /annotation.test diff --git a/stdlib/source/test/lux/type/dynamic.lux b/stdlib/source/test/lux/type/dynamic.lux index fadc98ca7..533b7fad0 100644 --- a/stdlib/source/test/lux/type/dynamic.lux +++ b/stdlib/source/test/lux/type/dynamic.lux @@ -1,35 +1,47 @@ (.module: [lux #* - ["%" data/text/format (#+ format)] - [abstract/monad (#+ do)] ["_" test (#+ Test)] + [abstract + [monad (#+ do)]] [control - ["." try]] + ["." try] + ["." exception]] + [data + ["." text ("#\." equivalence) + ["%" format (#+ format)]]] [math ["." random (#+ Random)] [number ["n" nat]]]] {1 - ["." / (#+ Dynamic :dynamic :check)]}) + ["." /]}) (def: #export test Test - (<| (_.context (%.name (name_of /._))) + (<| (_.covering /._) + (_.for [/.Dynamic]) (do random.monad - [expected random.nat - #let [value (:dynamic expected)]] + [expected random.nat] ($_ _.and - (_.test "Can check dynamic values." - (case (:check Nat value) - (#try.Success actual) - (n.= expected actual) - - (#try.Failure _) - false)) - (_.test "Cannot confuse types." - (case (:check Text value) - (#try.Success actual) - false - - (#try.Failure _) - true)))))) + (_.cover [/.:dynamic /.:check] + (case (/.:check Nat (/.:dynamic expected)) + (#try.Success actual) + (n.= expected actual) + + (#try.Failure _) + false)) + (_.cover [/.wrong_type] + (case (/.:check Text (/.:dynamic expected)) + (#try.Success actual) + false + + (#try.Failure error) + (exception.match? /.wrong_type error))) + (_.cover [/.print] + (case (/.print (/.:dynamic expected)) + (#try.Success actual) + (text\= (%.nat expected) actual) + + (#try.Failure _) + false)) + )))) |