aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/macro/expansion.lux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/test/lux/meta/macro/expansion.lux89
1 files changed, 89 insertions, 0 deletions
diff --git a/stdlib/source/test/lux/meta/macro/expansion.lux b/stdlib/source/test/lux/meta/macro/expansion.lux
new file mode 100644
index 000000000..fb552a8fe
--- /dev/null
+++ b/stdlib/source/test/lux/meta/macro/expansion.lux
@@ -0,0 +1,89 @@
+(.require
+ [library
+ [lux (.except)
+ [abstract
+ [monad (.only do)]]
+ [control
+ ["[0]" try]
+ ["[0]" exception]]
+ [data
+ ["[0]" text (.only)
+ ["%" \\format]]
+ [collection
+ ["[0]" list]]]
+ [math
+ [number
+ ["n" nat]]]
+ ["[0]" meta (.only)
+ ["[0]" static]
+ ["[0]" code (.use "[1]#[0]" equivalence)
+ ["<[1]>" \\parser]]
+ [macro
+ [syntax (.only syntax)]]]
+ [test
+ ["_" property (.only Test)]]]]
+ [\\library
+ ["[0]" /]])
+
+(use "code_list#[0]" (list.equivalence code.equivalence))
+
+(def dup
+ (syntax (_ [times <code>.nat
+ what <code>.any])
+ (when times
+ 0 (in (list what))
+ _ (let [it (` (..dup (, (code.nat (-- times))) (, what)))]
+ (in (list it it))))))
+
+(def .public test
+ Test
+ (<| (_.covering /._)
+ (`` (all _.and
+ (,, (with_template [<expansion> <inner> <0> <1>]
+ [(_.coverage [<expansion>]
+ (and (<| static.expansion
+ (do meta.monad
+ [it (<expansion> (` (..dup 0 <inner>)))]
+ (in (list (code.bit (code_list#= <0>
+ it))))))
+ (<| static.expansion
+ (do meta.monad
+ [it (<expansion> (` (..dup 1 <inner>)))]
+ (in (list (code.bit (code_list#= <1>
+ it))))))))]
+
+ [/.single [] (list (` [])) (list (` (..dup 0 [])) (` (..dup 0 [])))]
+ [/.complete [] (list (` [])) (list (` []) (` []))]
+ [/.total (..dup 0 []) (list (` [])) (list (` []) (` []))]
+ ))
+ (_.coverage [/.one]
+ (and (<| static.expansion
+ (do meta.monad
+ [it (/.one (` (..dup 0 [])))]
+ (in (list (code.bit (code#= (` [])
+ it))))))
+ (<| static.expansion
+ (do meta.monad
+ [it (meta.try (/.one (` (..dup 1 []))))]
+ (in (list (code.bit (when it
+ {try.#Failure _}
+ true
+
+ {try.#Success _}
+ false))))))))
+ (_.coverage [/.log_single!]
+ (exec
+ (,, (/.log_single! "omit" (..dup 0 [])))
+ (,, (/.log_single! (..dup 0 [])))
+ true))
+ (_.coverage [/.log_complete!]
+ (exec
+ (,, (/.log_complete! "omit" (..dup 1 [])))
+ (,, (/.log_complete! (..dup 1 [])))
+ true))
+ (_.coverage [/.log_total!]
+ (exec
+ (,, (/.log_total! "omit" (..dup 1 (..dup 0 []))))
+ (,, (/.log_total! (..dup 1 (..dup 0 []))))
+ true))
+ ))))