diff options
author | Eduardo Julian | 2018-07-04 20:11:57 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-07-04 20:11:57 -0400 |
commit | 7179bb2ea733a99c326642abbf48638d540ff651 (patch) | |
tree | db6564d6d7cf130ff28d9d4e589c47282a851378 /stdlib/test | |
parent | 08bcad002a638a8eb3ff963f004cb4ea584e4287 (diff) |
- Test (and fix) that global-reference analysis only allows you to see definitions within your current module, or exports from imported modules.
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/lang/compiler/analysis/reference.lux | 74 |
1 files changed, 59 insertions, 15 deletions
diff --git a/stdlib/test/test/lux/lang/compiler/analysis/reference.lux b/stdlib/test/test/lux/lang/compiler/analysis/reference.lux index 98db0a006..c6fbf5da0 100644 --- a/stdlib/test/test/lux/lang/compiler/analysis/reference.lux +++ b/stdlib/test/test/lux/lang/compiler/analysis/reference.lux @@ -4,7 +4,8 @@ (control [monad #+ do] pipe) (data ["e" error] - [ident "ident/" Eq<Ident>]) + [ident "ident/" Eq<Ident>] + [text "text/" Eq<Text>]) ["r" math/random] [macro #+ Monad<Meta>] (macro [code]) @@ -22,14 +23,49 @@ (def: analyse (expressionA.analyser (:coerce lang.Eval []))) +(type: Check (-> (e.Error Any) Bool)) + +(do-template [<name> <on-success> <on-failure>] + [(def: <name> + Check + (|>> (case> (#e.Success _) + <on-success> + + (#e.Error _) + <on-failure>)))] + + [success? true false] + [failure? false true] + ) + +(def: (reach-test var-name [export? def-module] [import? dependent-module] check!) + (-> Text [Bool Text] [Bool Text] Check Bool) + (|> (do Monad<Meta> + [_ (moduleL.with-module +0 def-module + (moduleL.define var-name [Any + (if export? + (' {#.export? true}) + (' {})) + []]))] + (moduleL.with-module +0 dependent-module + (do @ + [_ (if import? + (moduleL.import def-module) + (wrap []))] + (typeA.with-inference + (..analyse (code.symbol [def-module var-name])))))) + (macro.run (initL.compiler [])) + check!)) + (context: "References" (<| (times +100) (do @ [[expectedT _] _primitive.primitive - module-name (r.unicode +5) + def-module (r.unicode +5) scope-name (r.unicode +5) var-name (r.unicode +5) - #let [def-name [module-name var-name]]] + dependent-module (|> (r.unicode +5) + (r.filter (|>> (text/= def-module) not)))] ($_ seq (test "Can analyse variable." (|> (scopeL.with-scope scope-name @@ -43,16 +79,24 @@ _ 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.Reference (referenceL.constant constant-name))])) - (and (type/= expectedT inferredT) - (ident/= def-name constant-name)) + (test "Can analyse definition (in the same module)." + (let [def-name [def-module var-name]] + (|> (do Monad<Meta> + [_ (moduleL.define var-name [expectedT (' {}) []])] + (typeA.with-inference + (..analyse (code.symbol def-name)))) + (moduleL.with-module +0 def-module) + (macro.run (initL.compiler [])) + (case> (^ (#e.Success [_ inferredT (#analysisL.Reference (referenceL.constant constant-name))])) + (and (type/= expectedT inferredT) + (ident/= def-name constant-name)) - _ - false))))))) + _ + false)))) + (test "Can analyse definition (if exported from imported module)." + (reach-test var-name [true def-module] [true dependent-module] success?)) + (test "Cannot analyse definition (if not exported from imported module)." + (reach-test var-name [false def-module] [true dependent-module] failure?)) + (test "Cannot analyse definition (if exported from non-imported module)." + (reach-test var-name [true def-module] [false dependent-module] failure?)) + )))) |