aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test
diff options
context:
space:
mode:
authorEduardo Julian2021-01-05 07:55:22 -0400
committerEduardo Julian2021-01-05 07:55:22 -0400
commit75102dcfa7c2c0afd32cb5bf5ac012df2db6a7a1 (patch)
tree643350e00eebc8682c5087a4cd73b5f9406d92fb /stdlib/source/test
parentc03bd9f9787fb9f383c57b4ebb0fa9d49abbfaa1 (diff)
Added lexically-scoped templates.
Diffstat (limited to 'stdlib/source/test')
-rw-r--r--stdlib/source/test/aedifex/artifact.lux4
-rw-r--r--stdlib/source/test/aedifex/artifact/time_stamp/time.lux31
-rw-r--r--stdlib/source/test/lux/macro.lux4
-rw-r--r--stdlib/source/test/lux/macro/poly/json.lux4
-rw-r--r--stdlib/source/test/lux/macro/syntax/annotations.lux (renamed from stdlib/source/test/lux/macro/syntax/common/annotations.lux)4
-rw-r--r--stdlib/source/test/lux/macro/syntax/check.lux (renamed from stdlib/source/test/lux/macro/syntax/common/check.lux)6
-rw-r--r--stdlib/source/test/lux/macro/syntax/common.lux71
-rw-r--r--stdlib/source/test/lux/macro/syntax/declaration.lux (renamed from stdlib/source/test/lux/macro/syntax/common/declaration.lux)0
-rw-r--r--stdlib/source/test/lux/macro/syntax/definition.lux (renamed from stdlib/source/test/lux/macro/syntax/common/definition.lux)8
-rw-r--r--stdlib/source/test/lux/macro/syntax/export.lux (renamed from stdlib/source/test/lux/macro/syntax/common/export.lux)0
-rw-r--r--stdlib/source/test/lux/macro/syntax/input.lux46
-rw-r--r--stdlib/source/test/lux/macro/syntax/type/variable.lux (renamed from stdlib/source/test/lux/macro/syntax/common/type/variable.lux)0
-rw-r--r--stdlib/source/test/lux/macro/template.lux38
-rw-r--r--stdlib/source/test/lux/time/date.lux94
14 files changed, 205 insertions, 105 deletions
diff --git a/stdlib/source/test/aedifex/artifact.lux b/stdlib/source/test/aedifex/artifact.lux
index 959b857dd..60619f78b 100644
--- a/stdlib/source/test/aedifex/artifact.lux
+++ b/stdlib/source/test/aedifex/artifact.lux
@@ -22,7 +22,8 @@
["#." type]
["#." extension]
["#." time_stamp #_
- ["#/." date]]]
+ ["#/." date]
+ ["#/." time]]]
{#program
["." /]})
@@ -45,4 +46,5 @@
/type.test
/extension.test
/time_stamp/date.test
+ /time_stamp/time.test
))))
diff --git a/stdlib/source/test/aedifex/artifact/time_stamp/time.lux b/stdlib/source/test/aedifex/artifact/time_stamp/time.lux
new file mode 100644
index 000000000..bd9bbe071
--- /dev/null
+++ b/stdlib/source/test/aedifex/artifact/time_stamp/time.lux
@@ -0,0 +1,31 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ ["." time (#+ Time)]
+ [abstract
+ [monad (#+ do)]]
+ [control
+ ["." try ("#\." functor)]
+ [parser
+ ["<.>" text]]]
+ [math
+ ["." random (#+ Random)]
+ [number
+ ["n" nat]
+ ["i" int]]]]
+ {#program
+ ["." /]})
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ ($_ _.and
+ (do random.monad
+ [expected random.time]
+ (_.cover [/.format /.parser]
+ (|> expected
+ /.format
+ (<text>.run /.parser)
+ (try\map (\ time.equivalence = expected))
+ (try.default false))))
+ )))
diff --git a/stdlib/source/test/lux/macro.lux b/stdlib/source/test/lux/macro.lux
index 35476eee0..54370efb9 100644
--- a/stdlib/source/test/lux/macro.lux
+++ b/stdlib/source/test/lux/macro.lux
@@ -5,8 +5,7 @@
["#." code]
["#." template]
["#." poly]
- ["#." syntax
- ["#/." common]]])
+ ["#." syntax]])
(def: #export test
Test
@@ -14,6 +13,5 @@
/code.test
/template.test
/syntax.test
- /syntax/common.test
/poly.test
))
diff --git a/stdlib/source/test/lux/macro/poly/json.lux b/stdlib/source/test/lux/macro/poly/json.lux
index 98b955af8..f69af1397 100644
--- a/stdlib/source/test/lux/macro/poly/json.lux
+++ b/stdlib/source/test/lux/macro/poly/json.lux
@@ -49,7 +49,7 @@
[time
["_." instant]
## ["_." duration]
- ["_." date]]]])
+ ]]])
(type: Variant
(#Bit Bit)
@@ -103,7 +103,7 @@
..gen_recursive
## _instant.instant
## _duration.duration
- _date.date
+ random.date
..qty
)))
diff --git a/stdlib/source/test/lux/macro/syntax/common/annotations.lux b/stdlib/source/test/lux/macro/syntax/annotations.lux
index b1369ef48..564af4ea1 100644
--- a/stdlib/source/test/lux/macro/syntax/common/annotations.lux
+++ b/stdlib/source/test/lux/macro/syntax/annotations.lux
@@ -19,7 +19,7 @@
["n" nat]]]]
{1
["." /]}
- ["$." //// #_
+ ["$." /// #_
["#." code]])
(def: #export random
@@ -28,7 +28,7 @@
tag (random.and word word)]
(do {! random.monad}
[size (\ ! map (n.% 10) random.nat)]
- (random.list size (random.and tag $////code.random)))))
+ (random.list size (random.and tag $///code.random)))))
(def: #export test
Test
diff --git a/stdlib/source/test/lux/macro/syntax/common/check.lux b/stdlib/source/test/lux/macro/syntax/check.lux
index 6b4a4ab3d..898ad8abb 100644
--- a/stdlib/source/test/lux/macro/syntax/common/check.lux
+++ b/stdlib/source/test/lux/macro/syntax/check.lux
@@ -16,14 +16,14 @@
["." code ("#\." equivalence)]]]
{1
["." /]}
- ["$." //// #_
+ ["$." /// #_
["#." code]])
(def: #export random
(Random /.Check)
($_ random.and
- $////code.random
- $////code.random
+ $///code.random
+ $///code.random
))
(def: #export test
diff --git a/stdlib/source/test/lux/macro/syntax/common.lux b/stdlib/source/test/lux/macro/syntax/common.lux
deleted file mode 100644
index 2929417e3..000000000
--- a/stdlib/source/test/lux/macro/syntax/common.lux
+++ /dev/null
@@ -1,71 +0,0 @@
-(.module:
- [lux #*
- ["_" test (#+ Test)]
- [abstract
- [monad (#+ do)]
- [equivalence (#+ Equivalence)]]
- [control
- [pipe (#+ case>)]
- ["." try]
- ["<>" parser
- ["<c>" code]]]
- [data
- ["." product]
- ["." bit ("#\." equivalence)]
- ["." name]
- ["." text]
- [collection
- ["." list]]]
- [macro
- ["." code]]
- [math
- ["." random (#+ Random)]
- [number
- ["n" nat]]]]
- {1
- ["." /
- ["#." reader]
- ["#." writer]]}
- ["." /// #_
- ["#." code]]
- ["." / #_
- ["#." annotations]
- ["#." check]
- ["#." declaration]
- ["#." definition]
- ["#." export]
- ["#." type #_
- ["#/." variable]]])
-
-(def: random_text
- (Random Text)
- (random.ascii/alpha 10))
-
-(def: #export test
- Test
- (<| (_.covering /._)
- (_.covering /reader._)
- (_.covering /writer._)
- ($_ _.and
- (do {! random.monad}
- [expected (: (Random /.Typed_Input)
- (random.and ///code.random
- ///code.random))]
- (_.cover [/.Typed_Input /reader.typed_input /writer.typed_input]
- (|> expected
- /writer.typed_input list
- (<c>.run /reader.typed_input)
- (case> (#try.Success actual)
- (let [equivalence (product.equivalence code.equivalence code.equivalence)]
- (\ equivalence = expected actual))
-
- (#try.Failure error)
- false))))
-
- /annotations.test
- /check.test
- /declaration.test
- /definition.test
- /export.test
- /type/variable.test
- )))
diff --git a/stdlib/source/test/lux/macro/syntax/common/declaration.lux b/stdlib/source/test/lux/macro/syntax/declaration.lux
index a9bc23296..a9bc23296 100644
--- a/stdlib/source/test/lux/macro/syntax/common/declaration.lux
+++ b/stdlib/source/test/lux/macro/syntax/declaration.lux
diff --git a/stdlib/source/test/lux/macro/syntax/common/definition.lux b/stdlib/source/test/lux/macro/syntax/definition.lux
index a769df641..d6b101894 100644
--- a/stdlib/source/test/lux/macro/syntax/common/definition.lux
+++ b/stdlib/source/test/lux/macro/syntax/definition.lux
@@ -22,7 +22,7 @@
["$."// #_
["#." check]
["#." annotations]
- ["#//" /// #_
+ ["#/" // #_
["#." code]]])
(def: #export random
@@ -30,7 +30,7 @@
($_ random.and
(random.ascii/alpha 5)
(random.or $//check.random
- $////code.random)
+ $///code.random)
$//annotations.random
random.bit
))
@@ -64,8 +64,8 @@
(do random.monad
[expected ..random
- type $////code.random
- untyped_value $////code.random]
+ type $///code.random
+ untyped_value $///code.random]
($_ _.and
(_.cover [/.write /.parser]
(case (<code>.run (/.parser compiler)
diff --git a/stdlib/source/test/lux/macro/syntax/common/export.lux b/stdlib/source/test/lux/macro/syntax/export.lux
index 59b72eb0f..59b72eb0f 100644
--- a/stdlib/source/test/lux/macro/syntax/common/export.lux
+++ b/stdlib/source/test/lux/macro/syntax/export.lux
diff --git a/stdlib/source/test/lux/macro/syntax/input.lux b/stdlib/source/test/lux/macro/syntax/input.lux
new file mode 100644
index 000000000..b0b642645
--- /dev/null
+++ b/stdlib/source/test/lux/macro/syntax/input.lux
@@ -0,0 +1,46 @@
+(.module:
+ [lux #*
+ ["_" test (#+ Test)]
+ [abstract
+ [monad (#+ do)]
+ {[0 #spec]
+ [/
+ ["$." equivalence]]}]
+ [control
+ ["." try]
+ [parser
+ ["<.>" code]]]
+ [math
+ ["." random (#+ Random)]
+ [number
+ ["n" nat]]]]
+ {1
+ ["." /]}
+ ["$." /// #_
+ ["#." code]])
+
+(def: #export random
+ (Random /.Input)
+ ($_ random.and
+ $///code.random
+ $///code.random
+ ))
+
+(def: #export test
+ Test
+ (<| (_.covering /._)
+ (_.for [/.Input])
+ ($_ _.and
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence ..random))
+
+ (do random.monad
+ [expected ..random]
+ (_.cover [/.format /.parser]
+ (case (<code>.run /.parser
+ (list (/.format expected)))
+ (#try.Failure _)
+ false
+
+ (#try.Success actual)
+ (\ /.equivalence = expected actual)))))))
diff --git a/stdlib/source/test/lux/macro/syntax/common/type/variable.lux b/stdlib/source/test/lux/macro/syntax/type/variable.lux
index 4701f5aef..4701f5aef 100644
--- a/stdlib/source/test/lux/macro/syntax/common/type/variable.lux
+++ b/stdlib/source/test/lux/macro/syntax/type/variable.lux
diff --git a/stdlib/source/test/lux/macro/template.lux b/stdlib/source/test/lux/macro/template.lux
index 5733f40ad..53d7d114e 100644
--- a/stdlib/source/test/lux/macro/template.lux
+++ b/stdlib/source/test/lux/macro/template.lux
@@ -13,6 +13,12 @@
{1
["." /]})
+(/.with [(!pow/2 <scalar>)
+ (nat.* <scalar> <scalar>)]
+ (def: pow/2
+ (-> Nat Nat)
+ (|>> !pow/2)))
+
(def: #export test
Test
(<| (_.covering /._)
@@ -59,5 +65,37 @@
var1 right]
(and (nat.= left var0)
(nat.= right var1)))))
+ (do !
+ [scalar random.nat]
+ (_.cover [/.with]
+ (let [can_use_with_statements!
+ (nat.= ($_ nat.* scalar scalar)
+ (..pow/2 scalar))]
+ (and can_use_with_statements!
+ (/.with [(pow/3 <scalar>)
+ ($_ nat.* <scalar> <scalar> <scalar>)
+
+ (pow/9 <scalar>)
+ (pow/3 (pow/3 <scalar>))]
+ (let [can_use_with_expressions!
+ (nat.= ($_ nat.* scalar scalar scalar)
+ (pow/3 scalar))
+
+ can_refer!
+ (nat.= ($_ nat.*
+ scalar scalar scalar
+ scalar scalar scalar
+ scalar scalar scalar)
+ (pow/9 scalar))
+
+ can_shadow!
+ (let [pow/3 (function (_ scalar)
+ ($_ nat.+ scalar scalar scalar))]
+ (nat.= ($_ nat.+ scalar scalar scalar)
+ (pow/3 scalar)))]
+ (and can_use_with_expressions!
+ can_refer!
+ can_shadow!)))
+ ))))
)))
))
diff --git a/stdlib/source/test/lux/time/date.lux b/stdlib/source/test/lux/time/date.lux
index 7ad0e8ddc..1c569e476 100644
--- a/stdlib/source/test/lux/time/date.lux
+++ b/stdlib/source/test/lux/time/date.lux
@@ -1,35 +1,91 @@
(.module:
[lux #*
- ["%" data/text/format (#+ format)]
["_" test (#+ Test)]
- [math
- ["." random (#+ Random)]]
[abstract
- ["." monad (#+ do)]
+ [monad (#+ do)]
{[0 #spec]
[/
["$." equivalence]
["$." order]
+ ["$." enum]
["$." codec]]}]
[control
- ["." try]]]
- [//
- ["_." instant]]
+ ["." try ("#\." functor)]
+ ["." exception]
+ [parser
+ ["<.>" text]]]
+ [data
+ [text
+ ["%" format (#+ format)]]]
+ [math
+ ["." random (#+ Random)]
+ [number
+ ["n" nat]]]]
{1
- ["." / (#+ Date)
- ["." // #_
- ["#." instant]]]})
-
-(def: #export date
- (Random Date)
- (\ random.monad map //instant.date
- _instant.instant))
+ ["." /]})
(def: #export test
Test
- (<| (_.context (%.name (name_of /._)))
+ (<| (_.covering /._)
+ (_.for [/.Date])
($_ _.and
- ($equivalence.spec /.equivalence ..date)
- ($order.spec /.order ..date)
- ($codec.spec /.equivalence /.codec ..date)
+ (_.for [/.equivalence]
+ ($equivalence.spec /.equivalence random.date))
+ (_.for [/.order]
+ ($order.spec /.order random.date))
+ (_.for [/.enum]
+ ($enum.spec /.enum random.date))
+ (_.for [/.codec]
+ ($codec.spec /.equivalence /.codec random.date))
+
+ (do random.monad
+ [expected random.date]
+ (_.cover [/.date /.year /.month /.day_of_month]
+ (|> (/.date (/.year expected)
+ (/.month expected)
+ (/.day_of_month expected))
+ (try\map (\ /.equivalence = expected))
+ (try.default false))))
+ (do random.monad
+ [expected random.date]
+ (_.cover [/.invalid_day]
+ (case (/.date (/.year expected)
+ (/.month expected)
+ (n.+ 31 (/.day_of_month expected)))
+ (#try.Failure error)
+ (exception.match? /.invalid_day error)
+
+ (#try.Success _)
+ false)))
+ (do random.monad
+ [expected random.date]
+ (_.cover [/.to_days /.from_days]
+ (|> expected
+ /.to_days
+ /.from_days
+ (\ /.equivalence = expected))))
+ (do random.monad
+ [expected random.date]
+ (_.cover [/.parser]
+ (|> (\ /.codec encode expected)
+ (<text>.run /.parser)
+ (try\map (\ /.equivalence = expected))
+ (try.default false))))
+ (do {! random.monad}
+ [year (\ ! map (|>> (n.% 10,000) inc)
+ random.nat)
+ month (\ ! map (|>> (n.% 10) (n.+ 13))
+ random.nat)
+ day (\ ! map (|>> (n.% 10) (n.+ 10))
+ random.nat)
+ #let [input (format (%.nat year)
+ "-" (%.nat month)
+ "-" (%.nat day))]]
+ (_.cover [/.invalid_month]
+ (case (<text>.run /.parser input)
+ (#try.Failure error)
+ (exception.match? /.invalid_month error)
+
+ (#try.Success _)
+ false)))
)))