aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test/test/lux/lang/analysis/reference.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/test/test/lux/lang/analysis/reference.lux')
-rw-r--r--stdlib/test/test/lux/lang/analysis/reference.lux57
1 files changed, 57 insertions, 0 deletions
diff --git a/stdlib/test/test/lux/lang/analysis/reference.lux b/stdlib/test/test/lux/lang/analysis/reference.lux
new file mode 100644
index 000000000..00689f3e0
--- /dev/null
+++ b/stdlib/test/test/lux/lang/analysis/reference.lux
@@ -0,0 +1,57 @@
+(.module:
+ lux
+ (lux [io]
+ (control [monad #+ do]
+ pipe)
+ (data ["e" error]
+ [ident "ident/" Eq<Ident>])
+ ["r" math/random]
+ [macro #+ Monad<Meta>]
+ (macro [code])
+ [lang]
+ (lang [type "type/" Eq<Type>]
+ [".L" scope]
+ [".L" module]
+ [".L" init]
+ [".L" analysis]
+ (analysis [".A" type]
+ [".A" expression]))
+ test)
+ (// ["_." primitive]))
+
+(def: analyse (expressionA.analyser (:! lang.Eval [])))
+
+(context: "References"
+ (<| (times +100)
+ (do @
+ [[expectedT _] _primitive.primitive
+ module-name (r.unicode +5)
+ scope-name (r.unicode +5)
+ var-name (r.unicode +5)
+ #let [def-name [module-name var-name]]]
+ ($_ seq
+ (test "Can analyse variable."
+ (|> (scopeL.with-scope scope-name
+ (scopeL.with-local [var-name expectedT]
+ (typeA.with-inference
+ (..analyse (code.symbol ["" var-name])))))
+ (macro.run (initL.compiler []))
+ (case> (^ (#e.Success [inferredT (#analysisL.Variable (#analysisL.Local var))]))
+ (and (type/= expectedT inferredT)
+ (n/= +0 var))
+
+ _
+ false)))
+ (test "Can analyse definition."
+ (|> (do Monad<Meta>
+ [_ (moduleL.define var-name [expectedT (' {}) []])]
+ (typeA.with-inference
+ (..analyse (code.symbol def-name))))
+ (moduleL.with-module +0 module-name)
+ (macro.run (initL.compiler []))
+ (case> (#e.Success [_ inferredT (#analysisL.Constant constant-name)])
+ (and (type/= expectedT inferredT)
+ (ident/= def-name constant-name))
+
+ _
+ false)))))))