diff options
Diffstat (limited to 'stdlib/source/library/lux/test/inline.lux')
-rw-r--r-- | stdlib/source/library/lux/test/inline.lux | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/stdlib/source/library/lux/test/inline.lux b/stdlib/source/library/lux/test/inline.lux new file mode 100644 index 000000000..191a798cb --- /dev/null +++ b/stdlib/source/library/lux/test/inline.lux @@ -0,0 +1,73 @@ +(.require + [library + [lux (.except static) + [abstract + [monad (.only do)]] + [control + ["?" parser] + ["[0]" try] + ["[0]" exception (.only Exception)]] + [data + ["[0]" text (.only) + ["%" \\format]]] + [math + [number (.only hex)] + ["[0]" random (.only Random)]] + ["[0]" meta (.only) + ["[0]" code (.only) + ["?[1]" \\parser (.only Parser)]] + [macro + [syntax (.only syntax)]]]]]) + +(exception.def .public (failure test) + (Exception Code) + (exception.report + (list ["Test" (%.code test)]))) + +(type .public Test + (Random Bit)) + +(def pcg_32_magic_inc + Nat + (hex "FEDCBA9876543210")) + +(def ?static + (Parser [(Maybe Nat) + Code]) + (?.either (do ?.monad + [seed ?code.nat + term ?code.any] + (in [{.#Some seed} term])) + (do ?.monad + [term ?code.any] + (in [{.#None} term])))) + +(def .public static + (syntax (_ [[seed term] ?static]) + (do [! meta.monad] + [test (meta.eval Test term) + seed (when seed + {.#Some seed} + (in seed) + + _ + meta.seed) + .let [[_ success?] (random.result (random.pcg_32 [..pcg_32_magic_inc seed]) + (as Test test))]] + (if success? + (in (list)) + (meta.failure (exception.error ..failure [term])))))) + +(def .public dynamic + (syntax (_ [test ?code.any]) + (do [! meta.monad] + [error_message (meta.try (meta.failure (exception.error ..failure [test])))] + (in (list (` (is Any + (if (is Bit (, test)) + [] + (panic! (, (code.text (when error_message + {try.#Failure error} + error + + {try.#Success _} + "")))))))))))) |