diff options
Diffstat (limited to 'new-luxc/test/test/luxc/analyser')
-rw-r--r-- | new-luxc/test/test/luxc/analyser/case.lux | 190 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/function.lux | 178 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/primitive.lux | 58 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/procedure/common.lux | 674 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux | 244 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/reference.lux | 58 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/structure.lux | 514 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/type.lux | 78 |
8 files changed, 1021 insertions, 973 deletions
diff --git a/new-luxc/test/test/luxc/analyser/case.lux b/new-luxc/test/test/luxc/analyser/case.lux index e19ac3a0a..27cc9f6ae 100644 --- a/new-luxc/test/test/luxc/analyser/case.lux +++ b/new-luxc/test/test/luxc/analyser/case.lux @@ -129,97 +129,99 @@ (context: "Pattern-matching." ## #seed +9253409297339902486 ## #seed +3793366152923578600 - #seed +5004137551292836565 - [module-name (r;text +5) - variant-name (r;text +5) - record-name (|> (r;text +5) (r;filter (|>. (T/= variant-name) not))) - size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - variant-tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) - record-tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) - primitivesTC (r;list size gen-primitive) - #let [primitivesT (L/map product;left primitivesTC) - primitivesC (L/map product;right primitivesTC) - variant-tags+ (L/map (|>. [module-name] code;tag) variant-tags) - record-tags+ (L/map (|>. [module-name] code;tag) record-tags) - variantTC (list;zip2 variant-tags+ primitivesC)] - inputC (input variant-tags+ record-tags+ primitivesC) - [outputT outputC] gen-primitive - [heterogeneousT heterogeneousC] (|> gen-primitive - (r;filter (|>. product;left (tc;checks? outputT) not))) - exhaustive-patterns (exhaustive-branches true variantTC inputC) - redundant-patterns (exhaustive-branches false variantTC inputC) - redundancy-idx (|> r;nat (:: @ map (n.% (list;size redundant-patterns)))) - heterogeneous-idx (|> r;nat (:: @ map (n.% (list;size exhaustive-patterns)))) - #let [exhaustive-branchesC (L/map (branch outputC) - exhaustive-patterns) - non-exhaustive-branchesC (list;take (n.dec (list;size exhaustive-branchesC)) - exhaustive-branchesC) - redundant-branchesC (<| (L/map (branch outputC)) - list;concat - (list (list;take redundancy-idx redundant-patterns) - (list (maybe;assume (list;nth redundancy-idx redundant-patterns))) - (list;drop redundancy-idx redundant-patterns))) - heterogeneous-branchesC (list;concat (list (list;take heterogeneous-idx exhaustive-branchesC) - (list (let [[_pattern _body] (maybe;assume (list;nth heterogeneous-idx exhaustive-branchesC))] - [_pattern heterogeneousC])) - (list;drop (n.inc heterogeneous-idx) exhaustive-branchesC))) - ]] - ($_ seq - (test "Will reject empty pattern-matching (no branches)." - (|> (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC (list)))) - check-failure)) - (test "Can analyse exhaustive pattern-matching." - (|> (@module;with-module +0 module-name - (do Monad<Meta> - [_ (@module;declare-tags variant-tags false - (#;Named [module-name variant-name] - (type;variant primitivesT))) - _ (@module;declare-tags record-tags false - (#;Named [module-name record-name] - (type;tuple primitivesT)))] - (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC exhaustive-branchesC))))) - check-success)) - (test "Will reject non-exhaustive pattern-matching." - (|> (@module;with-module +0 module-name - (do Monad<Meta> - [_ (@module;declare-tags variant-tags false - (#;Named [module-name variant-name] - (type;variant primitivesT))) - _ (@module;declare-tags record-tags false - (#;Named [module-name record-name] - (type;tuple primitivesT)))] - (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC non-exhaustive-branchesC))))) - check-failure)) - (test "Will reject redundant pattern-matching." - (|> (@module;with-module +0 module-name - (do Monad<Meta> - [_ (@module;declare-tags variant-tags false - (#;Named [module-name variant-name] - (type;variant primitivesT))) - _ (@module;declare-tags record-tags false - (#;Named [module-name record-name] - (type;tuple primitivesT)))] - (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC redundant-branchesC))))) - check-failure)) - (test "Will reject pattern-matching if the bodies of the branches do not all have the same type." - (|> (@module;with-module +0 module-name - (do Monad<Meta> - [_ (@module;declare-tags variant-tags false - (#;Named [module-name variant-name] - (type;variant primitivesT))) - _ (@module;declare-tags record-tags false - (#;Named [module-name record-name] - (type;tuple primitivesT)))] - (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC heterogeneous-branchesC))))) - check-failure)) - )) + (<| (seed +5004137551292836565) + ## (times +100) + (do @ + [module-name (r;text +5) + variant-name (r;text +5) + record-name (|> (r;text +5) (r;filter (|>. (T/= variant-name) not))) + size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + variant-tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) + record-tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) + primitivesTC (r;list size gen-primitive) + #let [primitivesT (L/map product;left primitivesTC) + primitivesC (L/map product;right primitivesTC) + variant-tags+ (L/map (|>. [module-name] code;tag) variant-tags) + record-tags+ (L/map (|>. [module-name] code;tag) record-tags) + variantTC (list;zip2 variant-tags+ primitivesC)] + inputC (input variant-tags+ record-tags+ primitivesC) + [outputT outputC] gen-primitive + [heterogeneousT heterogeneousC] (|> gen-primitive + (r;filter (|>. product;left (tc;checks? outputT) not))) + exhaustive-patterns (exhaustive-branches true variantTC inputC) + redundant-patterns (exhaustive-branches false variantTC inputC) + redundancy-idx (|> r;nat (:: @ map (n.% (list;size redundant-patterns)))) + heterogeneous-idx (|> r;nat (:: @ map (n.% (list;size exhaustive-patterns)))) + #let [exhaustive-branchesC (L/map (branch outputC) + exhaustive-patterns) + non-exhaustive-branchesC (list;take (n.dec (list;size exhaustive-branchesC)) + exhaustive-branchesC) + redundant-branchesC (<| (L/map (branch outputC)) + list;concat + (list (list;take redundancy-idx redundant-patterns) + (list (maybe;assume (list;nth redundancy-idx redundant-patterns))) + (list;drop redundancy-idx redundant-patterns))) + heterogeneous-branchesC (list;concat (list (list;take heterogeneous-idx exhaustive-branchesC) + (list (let [[_pattern _body] (maybe;assume (list;nth heterogeneous-idx exhaustive-branchesC))] + [_pattern heterogeneousC])) + (list;drop (n.inc heterogeneous-idx) exhaustive-branchesC))) + ]] + ($_ seq + (test "Will reject empty pattern-matching (no branches)." + (|> (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC (list)))) + check-failure)) + (test "Can analyse exhaustive pattern-matching." + (|> (@module;with-module +0 module-name + (do Monad<Meta> + [_ (@module;declare-tags variant-tags false + (#;Named [module-name variant-name] + (type;variant primitivesT))) + _ (@module;declare-tags record-tags false + (#;Named [module-name record-name] + (type;tuple primitivesT)))] + (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC exhaustive-branchesC))))) + check-success)) + (test "Will reject non-exhaustive pattern-matching." + (|> (@module;with-module +0 module-name + (do Monad<Meta> + [_ (@module;declare-tags variant-tags false + (#;Named [module-name variant-name] + (type;variant primitivesT))) + _ (@module;declare-tags record-tags false + (#;Named [module-name record-name] + (type;tuple primitivesT)))] + (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC non-exhaustive-branchesC))))) + check-failure)) + (test "Will reject redundant pattern-matching." + (|> (@module;with-module +0 module-name + (do Monad<Meta> + [_ (@module;declare-tags variant-tags false + (#;Named [module-name variant-name] + (type;variant primitivesT))) + _ (@module;declare-tags record-tags false + (#;Named [module-name record-name] + (type;tuple primitivesT)))] + (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC redundant-branchesC))))) + check-failure)) + (test "Will reject pattern-matching if the bodies of the branches do not all have the same type." + (|> (@module;with-module +0 module-name + (do Monad<Meta> + [_ (@module;declare-tags variant-tags false + (#;Named [module-name variant-name] + (type;variant primitivesT))) + _ (@module;declare-tags record-tags false + (#;Named [module-name record-name] + (type;tuple primitivesT)))] + (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC heterogeneous-branchesC))))) + check-failure)) + )))) diff --git a/new-luxc/test/test/luxc/analyser/function.lux b/new-luxc/test/test/luxc/analyser/function.lux index 4b74db183..baef5c42c 100644 --- a/new-luxc/test/test/luxc/analyser/function.lux +++ b/new-luxc/test/test/luxc/analyser/function.lux @@ -64,92 +64,96 @@ false))) (context: "Function definition." - [func-name (r;text +5) - arg-name (|> (r;text +5) (r;filter (|>. (text/= func-name) not))) - [outputT outputC] gen-primitive - [inputT _] gen-primitive] - ($_ seq - (test "Can analyse function." - (|> (&;with-expected-type (type (All [a] (-> a outputT))) - (@;analyse-function analyse func-name arg-name outputC)) - (meta;run (init-compiler [])) - succeeds?)) - (test "Generic functions can always be specialized." - (and (|> (&;with-expected-type (-> inputT outputT) - (@;analyse-function analyse func-name arg-name outputC)) - (meta;run (init-compiler [])) - succeeds?) - (|> (&;with-expected-type (-> inputT inputT) - (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) - (meta;run (init-compiler [])) - succeeds?))) - (test "Can infer function (constant output and unused input)." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name outputC)) - (meta;run (init-compiler [])) - (check-type (type (All [a] (-> a outputT)))))) - (test "Can infer function (output = input)." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) - (meta;run (init-compiler [])) - (check-type (type (All [a] (-> a a)))))) - (test "The function's name is bound to the function's type." - (|> (&;with-expected-type (type (Rec self (-> inputT self))) - (@;analyse-function analyse func-name arg-name (code;symbol ["" func-name]))) - (meta;run (init-compiler [])) - succeeds?)) - (test "Can infer recursive types for functions." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name (code;symbol ["" func-name]))) - (meta;run (init-compiler [])) - (check-type (type (Rec self (All [a] (-> a self))))))) - )) + (<| (times +100) + (do @ + [func-name (r;text +5) + arg-name (|> (r;text +5) (r;filter (|>. (text/= func-name) not))) + [outputT outputC] gen-primitive + [inputT _] gen-primitive] + ($_ seq + (test "Can analyse function." + (|> (&;with-expected-type (type (All [a] (-> a outputT))) + (@;analyse-function analyse func-name arg-name outputC)) + (meta;run (init-compiler [])) + succeeds?)) + (test "Generic functions can always be specialized." + (and (|> (&;with-expected-type (-> inputT outputT) + (@;analyse-function analyse func-name arg-name outputC)) + (meta;run (init-compiler [])) + succeeds?) + (|> (&;with-expected-type (-> inputT inputT) + (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) + (meta;run (init-compiler [])) + succeeds?))) + (test "Can infer function (constant output and unused input)." + (|> (@common;with-unknown-type + (@;analyse-function analyse func-name arg-name outputC)) + (meta;run (init-compiler [])) + (check-type (type (All [a] (-> a outputT)))))) + (test "Can infer function (output = input)." + (|> (@common;with-unknown-type + (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) + (meta;run (init-compiler [])) + (check-type (type (All [a] (-> a a)))))) + (test "The function's name is bound to the function's type." + (|> (&;with-expected-type (type (Rec self (-> inputT self))) + (@;analyse-function analyse func-name arg-name (code;symbol ["" func-name]))) + (meta;run (init-compiler [])) + succeeds?)) + (test "Can infer recursive types for functions." + (|> (@common;with-unknown-type + (@;analyse-function analyse func-name arg-name (code;symbol ["" func-name]))) + (meta;run (init-compiler [])) + (check-type (type (Rec self (All [a] (-> a self))))))) + )))) (context: "Function application." - [full-args (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - partial-args (|> r;nat (:: @ map (n.% full-args))) - var-idx (|> r;nat (:: @ map (|>. (n.% full-args) (n.max +1)))) - inputsTC (r;list full-args gen-primitive) - #let [inputsT (list/map product;left inputsTC) - inputsC (list/map product;right inputsTC)] - [outputT outputC] gen-primitive - #let [funcT (type;function inputsT outputT) - partialT (type;function (list;drop partial-args inputsT) outputT) - varT (#;Bound +1) - polyT (<| (type;univ-q +1) - (type;function (list;concat (list (list;take var-idx inputsT) - (list varT) - (list;drop (n.inc var-idx) inputsT)))) - varT) - poly-inputT (maybe;assume (list;nth var-idx inputsT)) - partial-poly-inputsT (list;drop (n.inc var-idx) inputsT) - partial-polyT1 (<| (type;function partial-poly-inputsT) - poly-inputT) - partial-polyT2 (<| (type;univ-q +1) - (type;function (#;Cons varT partial-poly-inputsT)) - varT)]] - ($_ seq - (test "Can analyse monomorphic type application." - (|> (@common;with-unknown-type - (@;analyse-apply analyse funcT (#la;Unit) inputsC)) - (check-apply outputT full-args))) - (test "Can partially apply functions." - (|> (@common;with-unknown-type - (@;analyse-apply analyse funcT (#la;Unit) - (list;take partial-args inputsC))) - (check-apply partialT partial-args))) - (test "Can apply polymorphic functions." - (|> (@common;with-unknown-type - (@;analyse-apply analyse polyT (#la;Unit) inputsC)) - (check-apply poly-inputT full-args))) - (test "Polymorphic partial application propagates found type-vars." - (|> (@common;with-unknown-type - (@;analyse-apply analyse polyT (#la;Unit) - (list;take (n.inc var-idx) inputsC))) - (check-apply partial-polyT1 (n.inc var-idx)))) - (test "Polymorphic partial application preserves quantification for type-vars." - (|> (@common;with-unknown-type - (@;analyse-apply analyse polyT (#la;Unit) - (list;take var-idx inputsC))) - (check-apply partial-polyT2 var-idx))) - )) + (<| (times +100) + (do @ + [full-args (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + partial-args (|> r;nat (:: @ map (n.% full-args))) + var-idx (|> r;nat (:: @ map (|>. (n.% full-args) (n.max +1)))) + inputsTC (r;list full-args gen-primitive) + #let [inputsT (list/map product;left inputsTC) + inputsC (list/map product;right inputsTC)] + [outputT outputC] gen-primitive + #let [funcT (type;function inputsT outputT) + partialT (type;function (list;drop partial-args inputsT) outputT) + varT (#;Bound +1) + polyT (<| (type;univ-q +1) + (type;function (list;concat (list (list;take var-idx inputsT) + (list varT) + (list;drop (n.inc var-idx) inputsT)))) + varT) + poly-inputT (maybe;assume (list;nth var-idx inputsT)) + partial-poly-inputsT (list;drop (n.inc var-idx) inputsT) + partial-polyT1 (<| (type;function partial-poly-inputsT) + poly-inputT) + partial-polyT2 (<| (type;univ-q +1) + (type;function (#;Cons varT partial-poly-inputsT)) + varT)]] + ($_ seq + (test "Can analyse monomorphic type application." + (|> (@common;with-unknown-type + (@;analyse-apply analyse funcT (#la;Unit) inputsC)) + (check-apply outputT full-args))) + (test "Can partially apply functions." + (|> (@common;with-unknown-type + (@;analyse-apply analyse funcT (#la;Unit) + (list;take partial-args inputsC))) + (check-apply partialT partial-args))) + (test "Can apply polymorphic functions." + (|> (@common;with-unknown-type + (@;analyse-apply analyse polyT (#la;Unit) inputsC)) + (check-apply poly-inputT full-args))) + (test "Polymorphic partial application propagates found type-vars." + (|> (@common;with-unknown-type + (@;analyse-apply analyse polyT (#la;Unit) + (list;take (n.inc var-idx) inputsC))) + (check-apply partial-polyT1 (n.inc var-idx)))) + (test "Polymorphic partial application preserves quantification for type-vars." + (|> (@common;with-unknown-type + (@;analyse-apply analyse polyT (#la;Unit) + (list;take var-idx inputsC))) + (check-apply partial-polyT2 var-idx))) + )))) diff --git a/new-luxc/test/test/luxc/analyser/primitive.lux b/new-luxc/test/test/luxc/analyser/primitive.lux index 053587781..3d2e4ada6 100644 --- a/new-luxc/test/test/luxc/analyser/primitive.lux +++ b/new-luxc/test/test/luxc/analyser/primitive.lux @@ -26,33 +26,35 @@ (test/luxc common)) (context: "Primitives" - [%bool% r;bool - %nat% r;nat - %int% r;int - %deg% r;deg - %frac% r;frac - %text% (r;text +5)] - (with-expansions - [<tests> (do-template [<desc> <type> <tag> <value> <analyser>] - [(test (format "Can analyse " <desc> ".") - (|> (@common;with-unknown-type - (<analyser> <value>)) - (meta;run (init-compiler [])) - (case> (#e;Success [_type (<tag> value)]) - (and (type/= <type> _type) - (is <value> value)) + (<| (times +100) + (do @ + [%bool% r;bool + %nat% r;nat + %int% r;int + %deg% r;deg + %frac% r;frac + %text% (r;text +5)] + (with-expansions + [<tests> (do-template [<desc> <type> <tag> <value> <analyser>] + [(test (format "Can analyse " <desc> ".") + (|> (@common;with-unknown-type + (<analyser> <value>)) + (meta;run (init-compiler [])) + (case> (#e;Success [_type (<tag> value)]) + (and (type/= <type> _type) + (is <value> value)) - _ - false)) - )] + _ + false)) + )] - ["unit" Unit #~;Unit [] (function [value] @;analyse-unit)] - ["bool" Bool #~;Bool %bool% @;analyse-bool] - ["nat" Nat #~;Nat %nat% @;analyse-nat] - ["int" Int #~;Int %int% @;analyse-int] - ["deg" Deg #~;Deg %deg% @;analyse-deg] - ["frac" Frac #~;Frac %frac% @;analyse-frac] - ["text" Text #~;Text %text% @;analyse-text] - )] - ($_ seq - <tests>))) + ["unit" Unit #~;Unit [] (function [value] @;analyse-unit)] + ["bool" Bool #~;Bool %bool% @;analyse-bool] + ["nat" Nat #~;Nat %nat% @;analyse-nat] + ["int" Int #~;Int %int% @;analyse-int] + ["deg" Deg #~;Deg %deg% @;analyse-deg] + ["frac" Frac #~;Frac %frac% @;analyse-frac] + ["text" Text #~;Text %text% @;analyse-text] + )] + ($_ seq + <tests>))))) diff --git a/new-luxc/test/test/luxc/analyser/procedure/common.lux b/new-luxc/test/test/luxc/analyser/procedure/common.lux index ee342971b..208076d6e 100644 --- a/new-luxc/test/test/luxc/analyser/procedure/common.lux +++ b/new-luxc/test/test/luxc/analyser/procedure/common.lux @@ -40,358 +40,382 @@ ) (context: "Lux procedures" - [[primT primC] gen-primitive - [antiT antiC] (|> gen-primitive - (r;filter (|>. product;left (type/= primT) not)))] - ($_ seq - (test "Can test for reference equality." - (check-success+ "lux is" (list primC primC) Bool)) - (test "Reference equality must be done with elements of the same type." - (check-failure+ "lux is" (list primC antiC) Bool)) - (test "Can 'try' risky IO computations." - (check-success+ "lux try" - (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - (type (Either Text primT)))) - )) + (<| (times +100) + (do @ + [[primT primC] gen-primitive + [antiT antiC] (|> gen-primitive + (r;filter (|>. product;left (type/= primT) not)))] + ($_ seq + (test "Can test for reference equality." + (check-success+ "lux is" (list primC primC) Bool)) + (test "Reference equality must be done with elements of the same type." + (check-failure+ "lux is" (list primC antiC) Bool)) + (test "Can 'try' risky IO computations." + (check-success+ "lux try" + (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) + (type (Either Text primT)))) + )))) (context: "Bit procedures" - [subjectC (|> r;nat (:: @ map code;nat)) - signedC (|> r;int (:: @ map code;int)) - paramC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can count the number of 1 bits in a bit pattern." - (check-success+ "lux bit count" (list subjectC) Nat)) - (test "Can perform bit 'and'." - (check-success+ "lux bit and" (list subjectC paramC) Nat)) - (test "Can perform bit 'or'." - (check-success+ "lux bit or" (list subjectC paramC) Nat)) - (test "Can perform bit 'xor'." - (check-success+ "lux bit xor" (list subjectC paramC) Nat)) - (test "Can shift bit pattern to the left." - (check-success+ "lux bit shift-left" (list subjectC paramC) Nat)) - (test "Can shift bit pattern to the right." - (check-success+ "lux bit unsigned-shift-right" (list subjectC paramC) Nat)) - (test "Can shift signed bit pattern to the right." - (check-success+ "lux bit shift-right" (list signedC paramC) Int)) - )) + (<| (times +100) + (do @ + [subjectC (|> r;nat (:: @ map code;nat)) + signedC (|> r;int (:: @ map code;int)) + paramC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can count the number of 1 bits in a bit pattern." + (check-success+ "lux bit count" (list subjectC) Nat)) + (test "Can perform bit 'and'." + (check-success+ "lux bit and" (list subjectC paramC) Nat)) + (test "Can perform bit 'or'." + (check-success+ "lux bit or" (list subjectC paramC) Nat)) + (test "Can perform bit 'xor'." + (check-success+ "lux bit xor" (list subjectC paramC) Nat)) + (test "Can shift bit pattern to the left." + (check-success+ "lux bit shift-left" (list subjectC paramC) Nat)) + (test "Can shift bit pattern to the right." + (check-success+ "lux bit unsigned-shift-right" (list subjectC paramC) Nat)) + (test "Can shift signed bit pattern to the right." + (check-success+ "lux bit shift-right" (list signedC paramC) Int)) + )))) (context: "Nat procedures" - [subjectC (|> r;nat (:: @ map code;nat)) - paramC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can add natural numbers." - (check-success+ "lux nat +" (list subjectC paramC) Nat)) - (test "Can subtract natural numbers." - (check-success+ "lux nat -" (list subjectC paramC) Nat)) - (test "Can multiply natural numbers." - (check-success+ "lux nat *" (list subjectC paramC) Nat)) - (test "Can divide natural numbers." - (check-success+ "lux nat /" (list subjectC paramC) Nat)) - (test "Can calculate remainder of natural numbers." - (check-success+ "lux nat %" (list subjectC paramC) Nat)) - (test "Can test equality of natural numbers." - (check-success+ "lux nat =" (list subjectC paramC) Bool)) - (test "Can compare natural numbers." - (check-success+ "lux nat <" (list subjectC paramC) Bool)) - (test "Can obtain minimum natural number." - (check-success+ "lux nat min" (list) Nat)) - (test "Can obtain maximum natural number." - (check-success+ "lux nat max" (list) Nat)) - (test "Can convert natural number to integer." - (check-success+ "lux nat to-int" (list subjectC) Int)) - (test "Can convert natural number to text." - (check-success+ "lux nat to-text" (list subjectC) Text)) - )) + (<| (times +100) + (do @ + [subjectC (|> r;nat (:: @ map code;nat)) + paramC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can add natural numbers." + (check-success+ "lux nat +" (list subjectC paramC) Nat)) + (test "Can subtract natural numbers." + (check-success+ "lux nat -" (list subjectC paramC) Nat)) + (test "Can multiply natural numbers." + (check-success+ "lux nat *" (list subjectC paramC) Nat)) + (test "Can divide natural numbers." + (check-success+ "lux nat /" (list subjectC paramC) Nat)) + (test "Can calculate remainder of natural numbers." + (check-success+ "lux nat %" (list subjectC paramC) Nat)) + (test "Can test equality of natural numbers." + (check-success+ "lux nat =" (list subjectC paramC) Bool)) + (test "Can compare natural numbers." + (check-success+ "lux nat <" (list subjectC paramC) Bool)) + (test "Can obtain minimum natural number." + (check-success+ "lux nat min" (list) Nat)) + (test "Can obtain maximum natural number." + (check-success+ "lux nat max" (list) Nat)) + (test "Can convert natural number to integer." + (check-success+ "lux nat to-int" (list subjectC) Int)) + (test "Can convert natural number to text." + (check-success+ "lux nat to-text" (list subjectC) Text)) + )))) (context: "Int procedures" - [subjectC (|> r;int (:: @ map code;int)) - paramC (|> r;int (:: @ map code;int))] - ($_ seq - (test "Can add integers." - (check-success+ "lux int +" (list subjectC paramC) Int)) - (test "Can subtract integers." - (check-success+ "lux int -" (list subjectC paramC) Int)) - (test "Can multiply integers." - (check-success+ "lux int *" (list subjectC paramC) Int)) - (test "Can divide integers." - (check-success+ "lux int /" (list subjectC paramC) Int)) - (test "Can calculate remainder of integers." - (check-success+ "lux int %" (list subjectC paramC) Int)) - (test "Can test equality of integers." - (check-success+ "lux int =" (list subjectC paramC) Bool)) - (test "Can compare integers." - (check-success+ "lux int <" (list subjectC paramC) Bool)) - (test "Can obtain minimum integer." - (check-success+ "lux int min" (list) Int)) - (test "Can obtain maximum integer." - (check-success+ "lux int max" (list) Int)) - (test "Can convert integer to natural number." - (check-success+ "lux int to-nat" (list subjectC) Nat)) - (test "Can convert integer to frac number." - (check-success+ "lux int to-frac" (list subjectC) Frac)) - )) + (<| (times +100) + (do @ + [subjectC (|> r;int (:: @ map code;int)) + paramC (|> r;int (:: @ map code;int))] + ($_ seq + (test "Can add integers." + (check-success+ "lux int +" (list subjectC paramC) Int)) + (test "Can subtract integers." + (check-success+ "lux int -" (list subjectC paramC) Int)) + (test "Can multiply integers." + (check-success+ "lux int *" (list subjectC paramC) Int)) + (test "Can divide integers." + (check-success+ "lux int /" (list subjectC paramC) Int)) + (test "Can calculate remainder of integers." + (check-success+ "lux int %" (list subjectC paramC) Int)) + (test "Can test equality of integers." + (check-success+ "lux int =" (list subjectC paramC) Bool)) + (test "Can compare integers." + (check-success+ "lux int <" (list subjectC paramC) Bool)) + (test "Can obtain minimum integer." + (check-success+ "lux int min" (list) Int)) + (test "Can obtain maximum integer." + (check-success+ "lux int max" (list) Int)) + (test "Can convert integer to natural number." + (check-success+ "lux int to-nat" (list subjectC) Nat)) + (test "Can convert integer to frac number." + (check-success+ "lux int to-frac" (list subjectC) Frac)) + )))) (context: "Deg procedures" - [subjectC (|> r;deg (:: @ map code;deg)) - paramC (|> r;deg (:: @ map code;deg)) - natC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can add degrees." - (check-success+ "lux deg +" (list subjectC paramC) Deg)) - (test "Can subtract degrees." - (check-success+ "lux deg -" (list subjectC paramC) Deg)) - (test "Can multiply degrees." - (check-success+ "lux deg *" (list subjectC paramC) Deg)) - (test "Can divide degrees." - (check-success+ "lux deg /" (list subjectC paramC) Deg)) - (test "Can calculate remainder of degrees." - (check-success+ "lux deg %" (list subjectC paramC) Deg)) - (test "Can test equality of degrees." - (check-success+ "lux deg =" (list subjectC paramC) Bool)) - (test "Can compare degrees." - (check-success+ "lux deg <" (list subjectC paramC) Bool)) - (test "Can obtain minimum degree." - (check-success+ "lux deg min" (list) Deg)) - (test "Can obtain maximum degree." - (check-success+ "lux deg max" (list) Deg)) - (test "Can convert degree to frac number." - (check-success+ "lux deg to-frac" (list subjectC) Frac)) - (test "Can scale degree." - (check-success+ "lux deg scale" (list subjectC natC) Deg)) - (test "Can calculate the reciprocal of a natural number." - (check-success+ "lux deg reciprocal" (list natC) Deg)) - )) + (<| (times +100) + (do @ + [subjectC (|> r;deg (:: @ map code;deg)) + paramC (|> r;deg (:: @ map code;deg)) + natC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can add degrees." + (check-success+ "lux deg +" (list subjectC paramC) Deg)) + (test "Can subtract degrees." + (check-success+ "lux deg -" (list subjectC paramC) Deg)) + (test "Can multiply degrees." + (check-success+ "lux deg *" (list subjectC paramC) Deg)) + (test "Can divide degrees." + (check-success+ "lux deg /" (list subjectC paramC) Deg)) + (test "Can calculate remainder of degrees." + (check-success+ "lux deg %" (list subjectC paramC) Deg)) + (test "Can test equality of degrees." + (check-success+ "lux deg =" (list subjectC paramC) Bool)) + (test "Can compare degrees." + (check-success+ "lux deg <" (list subjectC paramC) Bool)) + (test "Can obtain minimum degree." + (check-success+ "lux deg min" (list) Deg)) + (test "Can obtain maximum degree." + (check-success+ "lux deg max" (list) Deg)) + (test "Can convert degree to frac number." + (check-success+ "lux deg to-frac" (list subjectC) Frac)) + (test "Can scale degree." + (check-success+ "lux deg scale" (list subjectC natC) Deg)) + (test "Can calculate the reciprocal of a natural number." + (check-success+ "lux deg reciprocal" (list natC) Deg)) + )))) (context: "Frac procedures" - [subjectC (|> r;frac (:: @ map code;frac)) - paramC (|> r;frac (:: @ map code;frac)) - encodedC (|> (r;text +5) (:: @ map code;text))] - ($_ seq - (test "Can add frac numbers." - (check-success+ "lux frac +" (list subjectC paramC) Frac)) - (test "Can subtract frac numbers." - (check-success+ "lux frac -" (list subjectC paramC) Frac)) - (test "Can multiply frac numbers." - (check-success+ "lux frac *" (list subjectC paramC) Frac)) - (test "Can divide frac numbers." - (check-success+ "lux frac /" (list subjectC paramC) Frac)) - (test "Can calculate remainder of frac numbers." - (check-success+ "lux frac %" (list subjectC paramC) Frac)) - (test "Can test equality of frac numbers." - (check-success+ "lux frac =" (list subjectC paramC) Bool)) - (test "Can compare frac numbers." - (check-success+ "lux frac <" (list subjectC paramC) Bool)) - (test "Can obtain minimum frac number." - (check-success+ "lux frac min" (list) Frac)) - (test "Can obtain maximum frac number." - (check-success+ "lux frac max" (list) Frac)) - (test "Can obtain smallest frac number." - (check-success+ "lux frac smallest" (list) Frac)) - (test "Can obtain not-a-number." - (check-success+ "lux frac not-a-number" (list) Frac)) - (test "Can obtain positive infinity." - (check-success+ "lux frac positive-infinity" (list) Frac)) - (test "Can obtain negative infinity." - (check-success+ "lux frac negative-infinity" (list) Frac)) - (test "Can convert frac number to integer." - (check-success+ "lux frac to-int" (list subjectC) Int)) - (test "Can convert frac number to degree." - (check-success+ "lux frac to-deg" (list subjectC) Deg)) - (test "Can convert frac number to text." - (check-success+ "lux frac encode" (list subjectC) Text)) - (test "Can convert text to frac number." - (check-success+ "lux frac encode" (list encodedC) (type (Maybe Frac)))) - )) + (<| (times +100) + (do @ + [subjectC (|> r;frac (:: @ map code;frac)) + paramC (|> r;frac (:: @ map code;frac)) + encodedC (|> (r;text +5) (:: @ map code;text))] + ($_ seq + (test "Can add frac numbers." + (check-success+ "lux frac +" (list subjectC paramC) Frac)) + (test "Can subtract frac numbers." + (check-success+ "lux frac -" (list subjectC paramC) Frac)) + (test "Can multiply frac numbers." + (check-success+ "lux frac *" (list subjectC paramC) Frac)) + (test "Can divide frac numbers." + (check-success+ "lux frac /" (list subjectC paramC) Frac)) + (test "Can calculate remainder of frac numbers." + (check-success+ "lux frac %" (list subjectC paramC) Frac)) + (test "Can test equality of frac numbers." + (check-success+ "lux frac =" (list subjectC paramC) Bool)) + (test "Can compare frac numbers." + (check-success+ "lux frac <" (list subjectC paramC) Bool)) + (test "Can obtain minimum frac number." + (check-success+ "lux frac min" (list) Frac)) + (test "Can obtain maximum frac number." + (check-success+ "lux frac max" (list) Frac)) + (test "Can obtain smallest frac number." + (check-success+ "lux frac smallest" (list) Frac)) + (test "Can obtain not-a-number." + (check-success+ "lux frac not-a-number" (list) Frac)) + (test "Can obtain positive infinity." + (check-success+ "lux frac positive-infinity" (list) Frac)) + (test "Can obtain negative infinity." + (check-success+ "lux frac negative-infinity" (list) Frac)) + (test "Can convert frac number to integer." + (check-success+ "lux frac to-int" (list subjectC) Int)) + (test "Can convert frac number to degree." + (check-success+ "lux frac to-deg" (list subjectC) Deg)) + (test "Can convert frac number to text." + (check-success+ "lux frac encode" (list subjectC) Text)) + (test "Can convert text to frac number." + (check-success+ "lux frac encode" (list encodedC) (type (Maybe Frac)))) + )))) (context: "Text procedures" - [subjectC (|> (r;text +5) (:: @ map code;text)) - paramC (|> (r;text +5) (:: @ map code;text)) - replacementC (|> (r;text +5) (:: @ map code;text)) - fromC (|> r;nat (:: @ map code;nat)) - toC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can test text equality." - (check-success+ "lux text =" (list subjectC paramC) Bool)) - (test "Compare texts in lexicographical order." - (check-success+ "lux text <" (list subjectC paramC) Bool)) - (test "Can prepend one text to another." - (check-success+ "lux text prepend" (list subjectC paramC) Text)) - (test "Can find the index of a piece of text inside a larger one that (may) contain it." - (check-success+ "lux text index" (list subjectC paramC fromC) (type (Maybe Nat)))) - (test "Can query the size/length of a text." - (check-success+ "lux text size" (list subjectC) Nat)) - (test "Can calculate a hash code for text." - (check-success+ "lux text hash" (list subjectC) Nat)) - (test "Can replace a text inside of a larger one (once)." - (check-success+ "lux text replace-once" (list subjectC paramC replacementC) Text)) - (test "Can replace a text inside of a larger one (all times)." - (check-success+ "lux text replace-all" (list subjectC paramC replacementC) Text)) - (test "Can obtain the character code of a text at a given index." - (check-success+ "lux text char" (list subjectC fromC) Nat)) - (test "Can clip a piece of text between 2 indices." - (check-success+ "lux text clip" (list subjectC fromC toC) Text)) - )) + (<| (times +100) + (do @ + [subjectC (|> (r;text +5) (:: @ map code;text)) + paramC (|> (r;text +5) (:: @ map code;text)) + replacementC (|> (r;text +5) (:: @ map code;text)) + fromC (|> r;nat (:: @ map code;nat)) + toC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can test text equality." + (check-success+ "lux text =" (list subjectC paramC) Bool)) + (test "Compare texts in lexicographical order." + (check-success+ "lux text <" (list subjectC paramC) Bool)) + (test "Can prepend one text to another." + (check-success+ "lux text prepend" (list subjectC paramC) Text)) + (test "Can find the index of a piece of text inside a larger one that (may) contain it." + (check-success+ "lux text index" (list subjectC paramC fromC) (type (Maybe Nat)))) + (test "Can query the size/length of a text." + (check-success+ "lux text size" (list subjectC) Nat)) + (test "Can calculate a hash code for text." + (check-success+ "lux text hash" (list subjectC) Nat)) + (test "Can replace a text inside of a larger one (once)." + (check-success+ "lux text replace-once" (list subjectC paramC replacementC) Text)) + (test "Can replace a text inside of a larger one (all times)." + (check-success+ "lux text replace-all" (list subjectC paramC replacementC) Text)) + (test "Can obtain the character code of a text at a given index." + (check-success+ "lux text char" (list subjectC fromC) Nat)) + (test "Can clip a piece of text between 2 indices." + (check-success+ "lux text clip" (list subjectC fromC toC) Text)) + )))) (context: "Array procedures" - [[elemT elemC] gen-primitive - sizeC (|> r;nat (:: @ map code;nat)) - idxC (|> r;nat (:: @ map code;nat)) - var-name (r;text +5) - #let [arrayT (type (Array elemT))]] - ($_ seq - (test "Can create arrays." - (check-success+ "lux array new" (list sizeC) arrayT)) - (test "Can get a value inside an array." - (|> (&scope;with-scope "" - (&scope;with-local [var-name arrayT] - (&;with-expected-type elemT - (@;analyse-procedure analyse "lux array get" - (list idxC - (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (<| (times +100) + (do @ + [[elemT elemC] gen-primitive + sizeC (|> r;nat (:: @ map code;nat)) + idxC (|> r;nat (:: @ map code;nat)) + var-name (r;text +5) + #let [arrayT (type (Array elemT))]] + ($_ seq + (test "Can create arrays." + (check-success+ "lux array new" (list sizeC) arrayT)) + (test "Can get a value inside an array." + (|> (&scope;with-scope "" + (&scope;with-local [var-name arrayT] + (&;with-expected-type elemT + (@;analyse-procedure analyse "lux array get" + (list idxC + (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - (test "Can put a value inside an array." - (|> (&scope;with-scope "" - (&scope;with-local [var-name arrayT] - (&;with-expected-type arrayT - (@;analyse-procedure analyse "lux array put" - (list idxC - elemC - (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (#e;Error _) + false))) + (test "Can put a value inside an array." + (|> (&scope;with-scope "" + (&scope;with-local [var-name arrayT] + (&;with-expected-type arrayT + (@;analyse-procedure analyse "lux array put" + (list idxC + elemC + (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - (test "Can remove a value from an array." - (|> (&scope;with-scope "" - (&scope;with-local [var-name arrayT] - (&;with-expected-type arrayT - (@;analyse-procedure analyse "lux array remove" - (list idxC - (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (#e;Error _) + false))) + (test "Can remove a value from an array." + (|> (&scope;with-scope "" + (&scope;with-local [var-name arrayT] + (&;with-expected-type arrayT + (@;analyse-procedure analyse "lux array remove" + (list idxC + (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - (test "Can query the size of an array." - (|> (&scope;with-scope "" - (&scope;with-local [var-name arrayT] - (&;with-expected-type Nat - (@;analyse-procedure analyse "lux array size" - (list (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (#e;Error _) + false))) + (test "Can query the size of an array." + (|> (&scope;with-scope "" + (&scope;with-local [var-name arrayT] + (&;with-expected-type Nat + (@;analyse-procedure analyse "lux array size" + (list (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - )) + (#e;Error _) + false))) + )))) (context: "Math procedures" - [subjectC (|> r;frac (:: @ map code;frac)) - paramC (|> r;frac (:: @ map code;frac))] - (with-expansions [<unary> (do-template [<proc> <desc>] - [(test (format "Can calculate " <desc> ".") - (check-success+ <proc> (list subjectC) Frac))] + (<| (times +100) + (do @ + [subjectC (|> r;frac (:: @ map code;frac)) + paramC (|> r;frac (:: @ map code;frac))] + (with-expansions [<unary> (do-template [<proc> <desc>] + [(test (format "Can calculate " <desc> ".") + (check-success+ <proc> (list subjectC) Frac))] - ["lux math cos" "cosine"] - ["lux math sin" "sine"] - ["lux math tan" "tangent"] - ["lux math acos" "inverse/arc cosine"] - ["lux math asin" "inverse/arc sine"] - ["lux math atan" "inverse/arc tangent"] - ["lux math cosh" "hyperbolic cosine"] - ["lux math sinh" "hyperbolic sine"] - ["lux math tanh" "hyperbolic tangent"] - ["lux math exp" "exponentiation"] - ["lux math log" "logarithm"] - ["lux math root2" "square root"] - ["lux math root3" "cubic root"] - ["lux math ceil" "ceiling"] - ["lux math floor" "floor"] - ["lux math round" "rounding"]) - <binary> (do-template [<proc> <desc>] - [(test (format "Can calculate " <desc> ".") - (check-success+ <proc> (list subjectC paramC) Frac))] + ["lux math cos" "cosine"] + ["lux math sin" "sine"] + ["lux math tan" "tangent"] + ["lux math acos" "inverse/arc cosine"] + ["lux math asin" "inverse/arc sine"] + ["lux math atan" "inverse/arc tangent"] + ["lux math cosh" "hyperbolic cosine"] + ["lux math sinh" "hyperbolic sine"] + ["lux math tanh" "hyperbolic tangent"] + ["lux math exp" "exponentiation"] + ["lux math log" "logarithm"] + ["lux math root2" "square root"] + ["lux math root3" "cubic root"] + ["lux math ceil" "ceiling"] + ["lux math floor" "floor"] + ["lux math round" "rounding"]) + <binary> (do-template [<proc> <desc>] + [(test (format "Can calculate " <desc> ".") + (check-success+ <proc> (list subjectC paramC) Frac))] - ["lux math atan2" "inverse/arc tangent (with 2 arguments)"] - ["lux math pow" "power"])] - ($_ seq - <unary> - <binary>))) + ["lux math atan2" "inverse/arc tangent (with 2 arguments)"] + ["lux math pow" "power"])] + ($_ seq + <unary> + <binary>))))) (context: "Atom procedures" - [[elemT elemC] gen-primitive - sizeC (|> r;nat (:: @ map code;nat)) - idxC (|> r;nat (:: @ map code;nat)) - var-name (r;text +5) - #let [atomT (type (atom;Atom elemT))]] - ($_ seq - (test "Can create atomic reference." - (check-success+ "lux atom new" (list elemC) atomT)) - (test "Can read the value of an atomic reference." - (|> (&scope;with-scope "" - (&scope;with-local [var-name atomT] - (&;with-expected-type elemT - (@;analyse-procedure analyse "lux atom read" - (list (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (<| (times +100) + (do @ + [[elemT elemC] gen-primitive + sizeC (|> r;nat (:: @ map code;nat)) + idxC (|> r;nat (:: @ map code;nat)) + var-name (r;text +5) + #let [atomT (type (atom;Atom elemT))]] + ($_ seq + (test "Can create atomic reference." + (check-success+ "lux atom new" (list elemC) atomT)) + (test "Can read the value of an atomic reference." + (|> (&scope;with-scope "" + (&scope;with-local [var-name atomT] + (&;with-expected-type elemT + (@;analyse-procedure analyse "lux atom read" + (list (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - (test "Can swap the value of an atomic reference." - (|> (&scope;with-scope "" - (&scope;with-local [var-name atomT] - (&;with-expected-type Bool - (@;analyse-procedure analyse "lux atom compare-and-swap" - (list elemC - elemC - (code;symbol ["" var-name])))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + (#e;Error _) + false))) + (test "Can swap the value of an atomic reference." + (|> (&scope;with-scope "" + (&scope;with-local [var-name atomT] + (&;with-expected-type Bool + (@;analyse-procedure analyse "lux atom compare-and-swap" + (list elemC + elemC + (code;symbol ["" var-name])))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error _) - false))) - )) + (#e;Error _) + false))) + )))) (context: "Process procedures" - [[primT primC] gen-primitive - timeC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can query the level of concurrency." - (check-success+ "lux process concurrency-level" (list) Nat)) - (test "Can run an IO computation concurrently." - (check-success+ "lux process future" - (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - Unit)) - (test "Can schedule an IO computation to run concurrently at some future time." - (check-success+ "lux process schedule" - (list timeC - (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - Unit)) - )) + (<| (times +100) + (do @ + [[primT primC] gen-primitive + timeC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can query the level of concurrency." + (check-success+ "lux process concurrency-level" (list) Nat)) + (test "Can run an IO computation concurrently." + (check-success+ "lux process future" + (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) + Unit)) + (test "Can schedule an IO computation to run concurrently at some future time." + (check-success+ "lux process schedule" + (list timeC + (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) + Unit)) + )))) (context: "IO procedures" - [logC (|> (r;text +5) (:: @ map code;text)) - exitC (|> r;nat (:: @ map code;nat))] - ($_ seq - (test "Can log messages to standard output." - (check-success+ "lux io log" (list logC) Unit)) - (test "Can log messages to standard output." - (check-success+ "lux io error" (list logC) Bottom)) - (test "Can log messages to standard output." - (check-success+ "lux io exit" (list exitC) Bottom)) - (test "Can query the current time (as milliseconds since epoch)." - (check-success+ "lux io current-time" (list) Int)) - )) + (<| (times +100) + (do @ + [logC (|> (r;text +5) (:: @ map code;text)) + exitC (|> r;nat (:: @ map code;nat))] + ($_ seq + (test "Can log messages to standard output." + (check-success+ "lux io log" (list logC) Unit)) + (test "Can log messages to standard output." + (check-success+ "lux io error" (list logC) Bottom)) + (test "Can log messages to standard output." + (check-success+ "lux io exit" (list exitC) Bottom)) + (test "Can query the current time (as milliseconds since epoch)." + (check-success+ "lux io current-time" (list) Int)) + )))) diff --git a/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux b/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux index ba59500f4..aa0f2388d 100644 --- a/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux +++ b/new-luxc/test/test/luxc/analyser/procedure/host.jvm.lux @@ -249,47 +249,49 @@ (wrap [unboxed boxed])))) (context: "Array." - [#let [cap (|>. (n.% +10) (n.max +1))] - [unboxed boxed] array-type - size (|> r;nat (:: @ map cap)) - idx (|> r;nat (:: @ map (n.% size))) - level (|> r;nat (:: @ map cap)) - #let [unboxedT (#;Host unboxed (list)) - arrayT (#;Host "#Array" (list unboxedT)) - arrayC (`' (_lux_check (+0 "#Array" (+1 (+0 (~ (code;text unboxed)) (+0)) (+0))) - ("jvm array new" (~ (code;nat size))))) - boxedT (#;Host boxed (list)) - boxedTC (` (+0 (~ (code;text boxed)) (+0))) - multi-arrayT (list/fold (function [_ innerT] - (|> innerT (list) (#;Host "#Array"))) - boxedT - (list;n.range +1 level))]] - ($_ seq - (test "jvm array new" - (success "jvm array new" - (list (code;nat size)) - arrayT)) - (test "jvm array new (no nesting)" - (failure "jvm array new" - (list (code;nat size)) - unboxedT)) - (test "jvm array new (nested/multi-level)" - (success "jvm array new" - (list (code;nat size)) - multi-arrayT)) - (test "jvm array length" - (success "jvm array length" - (list arrayC) - Nat)) - (test "jvm array read" - (success "jvm array read" - (list arrayC (code;nat idx)) - boxedT)) - (test "jvm array write" - (success "jvm array write" - (list arrayC (code;nat idx) (`' (_lux_coerce (~ boxedTC) []))) - arrayT)) - )) + (<| (times +100) + (do @ + [#let [cap (|>. (n.% +10) (n.max +1))] + [unboxed boxed] array-type + size (|> r;nat (:: @ map cap)) + idx (|> r;nat (:: @ map (n.% size))) + level (|> r;nat (:: @ map cap)) + #let [unboxedT (#;Primitive unboxed (list)) + arrayT (#;Primitive "#Array" (list unboxedT)) + arrayC (`' (_lux_check (+0 "#Array" (+1 (+0 (~ (code;text unboxed)) (+0)) (+0))) + ("jvm array new" (~ (code;nat size))))) + boxedT (#;Primitive boxed (list)) + boxedTC (` (+0 (~ (code;text boxed)) (+0))) + multi-arrayT (list/fold (function [_ innerT] + (|> innerT (list) (#;Primitive "#Array"))) + boxedT + (list;n.range +1 level))]] + ($_ seq + (test "jvm array new" + (success "jvm array new" + (list (code;nat size)) + arrayT)) + (test "jvm array new (no nesting)" + (failure "jvm array new" + (list (code;nat size)) + unboxedT)) + (test "jvm array new (nested/multi-level)" + (success "jvm array new" + (list (code;nat size)) + multi-arrayT)) + (test "jvm array length" + (success "jvm array length" + (list arrayC) + Nat)) + (test "jvm array read" + (success "jvm array read" + (list arrayC (code;nat idx)) + boxedT)) + (test "jvm array write" + (success "jvm array write" + (list arrayC (code;nat idx) (`' (_lux_coerce (~ boxedTC) []))) + arrayT)) + )))) (def: throwables (List Text) @@ -302,74 +304,76 @@ "java.lang.RuntimeException")) (context: "Object." - [[unboxed boxed] array-type - [!unboxed !boxed] (|> array-type - (r;filter (function [[!unboxed !boxed]] - (not (text/= boxed !boxed))))) - #let [boxedT (#;Host boxed (list)) - boxedC (`' (_lux_check (+0 (~ (code;text boxed)) (+0)) - ("jvm object null"))) - !boxedC (`' (_lux_check (+0 (~ (code;text !boxed)) (+0)) - ("jvm object null"))) - unboxedC (`' (_lux_check (+0 (~ (code;text unboxed)) (+0)) - ("jvm object null")))] - throwable (|> r;nat - (:: @ map (n.% (n.inc (list;size throwables)))) - (:: @ map (function [idx] - (|> throwables - (list;nth idx) - (maybe;default "java.lang.Object"))))) - #let [throwableC (`' (_lux_check (+0 (~ (code;text throwable)) (+0)) - ("jvm object null")))]] - ($_ seq - (test "jvm object null" - (success "jvm object null" - (list) - (#;Host boxed (list)))) - (test "jvm object null (no primitives)" - (or (text/= "java.lang.Object" boxed) - (failure "jvm object null" - (list) - (#;Host unboxed (list))))) - (test "jvm object null?" - (success "jvm object null?" - (list boxedC) - Bool)) - (test "jvm object synchronized" - (success "jvm object synchronized" - (list boxedC boxedC) - boxedT)) - (test "jvm object synchronized (no primitives)" - (or (text/= "java.lang.Object" boxed) - (failure "jvm object synchronized" - (list unboxedC boxedC) - boxedT))) - (test "jvm object throw" - (or (text/= "java.lang.Object" throwable) - (success "jvm object throw" - (list throwableC) - Bottom))) - (test "jvm object class" - (success "jvm object class" - (list (code;text boxed)) - (#;Host "java.lang.Class" (list boxedT)))) - (test "jvm object instance?" - (success "jvm object instance?" - (list (code;text boxed) - boxedC) - Bool)) - (test "jvm object instance? (lineage)" - (success "jvm object instance?" - (list (' "java.lang.Object") - boxedC) - Bool)) - (test "jvm object instance? (no lineage)" - (or (text/= "java.lang.Object" boxed) - (failure "jvm object instance?" - (list (code;text boxed) - !boxedC) - Bool))) - )) + (<| (times +100) + (do @ + [[unboxed boxed] array-type + [!unboxed !boxed] (|> array-type + (r;filter (function [[!unboxed !boxed]] + (not (text/= boxed !boxed))))) + #let [boxedT (#;Primitive boxed (list)) + boxedC (`' (_lux_check (+0 (~ (code;text boxed)) (+0)) + ("jvm object null"))) + !boxedC (`' (_lux_check (+0 (~ (code;text !boxed)) (+0)) + ("jvm object null"))) + unboxedC (`' (_lux_check (+0 (~ (code;text unboxed)) (+0)) + ("jvm object null")))] + throwable (|> r;nat + (:: @ map (n.% (n.inc (list;size throwables)))) + (:: @ map (function [idx] + (|> throwables + (list;nth idx) + (maybe;default "java.lang.Object"))))) + #let [throwableC (`' (_lux_check (+0 (~ (code;text throwable)) (+0)) + ("jvm object null")))]] + ($_ seq + (test "jvm object null" + (success "jvm object null" + (list) + (#;Primitive boxed (list)))) + (test "jvm object null (no primitives)" + (or (text/= "java.lang.Object" boxed) + (failure "jvm object null" + (list) + (#;Primitive unboxed (list))))) + (test "jvm object null?" + (success "jvm object null?" + (list boxedC) + Bool)) + (test "jvm object synchronized" + (success "jvm object synchronized" + (list boxedC boxedC) + boxedT)) + (test "jvm object synchronized (no primitives)" + (or (text/= "java.lang.Object" boxed) + (failure "jvm object synchronized" + (list unboxedC boxedC) + boxedT))) + (test "jvm object throw" + (or (text/= "java.lang.Object" throwable) + (success "jvm object throw" + (list throwableC) + Bottom))) + (test "jvm object class" + (success "jvm object class" + (list (code;text boxed)) + (#;Primitive "java.lang.Class" (list boxedT)))) + (test "jvm object instance?" + (success "jvm object instance?" + (list (code;text boxed) + boxedC) + Bool)) + (test "jvm object instance? (lineage)" + (success "jvm object instance?" + (list (' "java.lang.Object") + boxedC) + Bool)) + (test "jvm object instance? (no lineage)" + (or (text/= "java.lang.Object" boxed) + (failure "jvm object instance?" + (list (code;text boxed) + !boxedC) + Bool))) + )))) (context: "Member [Static Field]." ($_ seq @@ -377,12 +381,12 @@ (success "jvm member static get" (list (code;text "java.lang.System") (code;text "out")) - (#;Host "java.io.PrintStream" (list)))) + (#;Primitive "java.io.PrintStream" (list)))) (test "jvm member static get (inheritance out)" (success "jvm member static get" (list (code;text "java.lang.System") (code;text "out")) - (#;Host "java.lang.Object" (list)))) + (#;Primitive "java.lang.Object" (list)))) (test "jvm member static put" (success "jvm member static put" (list (code;text "java.awt.datatransfer.DataFlavor") @@ -414,14 +418,14 @@ (code;text "id") (`' (_lux_check (+0 "org.omg.CORBA.ValueMember" (+0)) ("jvm object null")))) - (#;Host "java.lang.String" (list)))) + (#;Primitive "java.lang.String" (list)))) (test "jvm member virtual get (inheritance out)" (success "jvm member virtual get" (list (code;text "org.omg.CORBA.ValueMember") (code;text "id") (`' (_lux_check (+0 "org.omg.CORBA.ValueMember" (+0)) ("jvm object null")))) - (#;Host "java.lang.Object" (list)))) + (#;Primitive "java.lang.Object" (list)))) (test "jvm member virtual put" (success "jvm member virtual put" (list (code;text "org.omg.CORBA.ValueMember") @@ -457,14 +461,14 @@ (success "jvm member static get" (list (code;text "java.util.GregorianCalendar") (code;text "AD")) - (#;Host "java.lang.Integer" (list)))) + (#;Primitive "java.lang.Integer" (list)))) (test "jvm member virtual get" (success "jvm member virtual get" (list (code;text "javax.accessibility.AccessibleAttributeSequence") (code;text "startIndex") (`' (_lux_check (+0 "javax.accessibility.AccessibleAttributeSequence" (+0)) ("jvm object null")))) - (#;Host "java.lang.Integer" (list)))) + (#;Primitive "java.lang.Integer" (list)))) (test "jvm member virtual put" (success "jvm member virtual put" (list (code;text "javax.accessibility.AccessibleAttributeSequence") @@ -491,7 +495,7 @@ (code;tuple (list (' "java.lang.String") (' (_lux_coerce (+0 "java.lang.String" (+0)) "YOLO"))))) - (#;Host "java.lang.Long" (list)))) + (#;Primitive "java.lang.Long" (list)))) (test "jvm member invoke virtual" (success "jvm member invoke virtual" (list (code;text "java.lang.Object") @@ -499,7 +503,7 @@ longC (code;tuple (list (' "java.lang.Object") longC))) - (#;Host "java.lang.Boolean" (list)))) + (#;Primitive "java.lang.Boolean" (list)))) (test "jvm member invoke special" (success "jvm member invoke special" (list (code;text "java.lang.Long") @@ -507,7 +511,7 @@ longC (code;tuple (list (' "java.lang.Object") longC))) - (#;Host "java.lang.Boolean" (list)))) + (#;Primitive "java.lang.Boolean" (list)))) (test "jvm member invoke interface" (success "jvm member invoke interface" (list (code;text "java.util.Collection") @@ -515,10 +519,10 @@ objectC (code;tuple (list (' "java.lang.Object") longC))) - (#;Host "java.lang.Boolean" (list)))) + (#;Primitive "java.lang.Boolean" (list)))) (test "jvm member invoke constructor" (success "jvm member invoke constructor" (list (code;text "java.util.ArrayList") (code;tuple (list (' "int") intC))) - (All [a] (#;Host "java.util.ArrayList" (list a))))) + (All [a] (#;Primitive "java.util.ArrayList" (list a))))) ))) diff --git a/new-luxc/test/test/luxc/analyser/reference.lux b/new-luxc/test/test/luxc/analyser/reference.lux index 8ffdf15b7..89d68484f 100644 --- a/new-luxc/test/test/luxc/analyser/reference.lux +++ b/new-luxc/test/test/luxc/analyser/reference.lux @@ -18,33 +18,35 @@ (test/luxc common)) (context: "References" - [[ref-type _] gen-primitive - module-name (r;text +5) - scope-name (r;text +5) - var-name (r;text +5)] - ($_ seq - (test "Can analyse variable." - (|> (&scope;with-scope scope-name - (&scope;with-local [var-name ref-type] - (@common;with-unknown-type - (@;analyse-reference ["" var-name])))) - (meta;run (init-compiler [])) - (case> (#e;Success [_type (#~;Variable idx)]) - (type/= ref-type _type) + (<| (times +100) + (do @ + [[ref-type _] gen-primitive + module-name (r;text +5) + scope-name (r;text +5) + var-name (r;text +5)] + ($_ seq + (test "Can analyse variable." + (|> (&scope;with-scope scope-name + (&scope;with-local [var-name ref-type] + (@common;with-unknown-type + (@;analyse-reference ["" var-name])))) + (meta;run (init-compiler [])) + (case> (#e;Success [_type (#~;Variable idx)]) + (type/= ref-type _type) - _ - false))) - (test "Can analyse definition." - (|> (do Monad<Meta> - [_ (&module;create +0 module-name) - _ (&module;define [module-name var-name] - [ref-type (' {}) (:! Void [])])] - (@common;with-unknown-type - (@;analyse-reference [module-name var-name]))) - (meta;run (init-compiler [])) - (case> (#e;Success [_type (#~;Definition idx)]) - (type/= ref-type _type) + _ + false))) + (test "Can analyse definition." + (|> (do Monad<Meta> + [_ (&module;create +0 module-name) + _ (&module;define [module-name var-name] + [ref-type (' {}) (:! Void [])])] + (@common;with-unknown-type + (@;analyse-reference [module-name var-name]))) + (meta;run (init-compiler [])) + (case> (#e;Success [_type (#~;Definition idx)]) + (type/= ref-type _type) - _ - false))) - )) + _ + false))) + )))) diff --git a/new-luxc/test/test/luxc/analyser/structure.lux b/new-luxc/test/test/luxc/analyser/structure.lux index 7ac9c29c9..40896c334 100644 --- a/new-luxc/test/test/luxc/analyser/structure.lux +++ b/new-luxc/test/test/luxc/analyser/structure.lux @@ -57,161 +57,165 @@ #;None)) (context: "Sums" - [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - choice (|> r;nat (:: @ map (n.% size))) - primitives (r;list size gen-primitive) - +choice (|> r;nat (:: @ map (n.% (n.inc size)))) - [_ +valueC] gen-primitive - #let [variantT (type;variant (list/map product;left primitives)) - [valueT valueC] (maybe;assume (list;nth choice primitives)) - +size (n.inc size) - +primitives (list;concat (list (list;take choice primitives) - (list [(#;Bound +1) +valueC]) - (list;drop choice primitives))) - [+valueT +valueC] (maybe;assume (list;nth +choice +primitives)) - +variantT (type;variant (list/map product;left +primitives))]] - ($_ seq - (test "Can analyse sum." - (|> (&;with-scope - (&;with-expected-type variantT - (@;analyse-sum analyse choice valueC))) - (meta;run (init-compiler [])) - (case> (^multi (#e;Success [_ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag choice) - (bool/= last? (n.= (n.dec size) choice))) + (<| (times +100) + (do @ + [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + choice (|> r;nat (:: @ map (n.% size))) + primitives (r;list size gen-primitive) + +choice (|> r;nat (:: @ map (n.% (n.inc size)))) + [_ +valueC] gen-primitive + #let [variantT (type;variant (list/map product;left primitives)) + [valueT valueC] (maybe;assume (list;nth choice primitives)) + +size (n.inc size) + +primitives (list;concat (list (list;take choice primitives) + (list [(#;Bound +1) +valueC]) + (list;drop choice primitives))) + [+valueT +valueC] (maybe;assume (list;nth +choice +primitives)) + +variantT (type;variant (list/map product;left +primitives))]] + ($_ seq + (test "Can analyse sum." + (|> (&;with-scope + (&;with-expected-type variantT + (@;analyse-sum analyse choice valueC))) + (meta;run (init-compiler [])) + (case> (^multi (#e;Success [_ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag choice) + (bool/= last? (n.= (n.dec size) choice))) - _ - false))) - (test "Can analyse sum through bound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] - (do meta;Monad<Meta> - [_ (&;with-type-env - (tc;check varT variantT))] - (&;with-expected-type varT - (@;analyse-sum analyse choice valueC)))))) - (meta;run (init-compiler [])) - (case> (^multi (#e;Success [_ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag choice) - (bool/= last? (n.= (n.dec size) choice))) + _ + false))) + (test "Can analyse sum through bound type-vars." + (|> (&;with-scope + (@common;with-var + (function [[var-id varT]] + (do meta;Monad<Meta> + [_ (&;with-type-env + (tc;check varT variantT))] + (&;with-expected-type varT + (@;analyse-sum analyse choice valueC)))))) + (meta;run (init-compiler [])) + (case> (^multi (#e;Success [_ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag choice) + (bool/= last? (n.= (n.dec size) choice))) - _ - false))) - (test "Cannot analyse sum through unbound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] - (&;with-expected-type varT - (@;analyse-sum analyse choice valueC))))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - false + _ + false))) + (test "Cannot analyse sum through unbound type-vars." + (|> (&;with-scope + (@common;with-var + (function [[var-id varT]] + (&;with-expected-type varT + (@;analyse-sum analyse choice valueC))))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + false - _ - true))) - (test "Can analyse sum through existential quantification." - (|> (&;with-scope - (&;with-expected-type (type;ex-q +1 +variantT) - (@;analyse-sum analyse +choice +valueC))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + _ + true))) + (test "Can analyse sum through existential quantification." + (|> (&;with-scope + (&;with-expected-type (type;ex-q +1 +variantT) + (@;analyse-sum analyse +choice +valueC))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error error) - false))) - (test "Can analyse sum through universal quantification." - (|> (&;with-scope - (&;with-expected-type (type;univ-q +1 +variantT) - (@;analyse-sum analyse +choice +valueC))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - (not (n.= choice +choice)) + (#e;Error error) + false))) + (test "Can analyse sum through universal quantification." + (|> (&;with-scope + (&;with-expected-type (type;univ-q +1 +variantT) + (@;analyse-sum analyse +choice +valueC))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + (not (n.= choice +choice)) - (#e;Error error) - (n.= choice +choice)))) - )) + (#e;Error error) + (n.= choice +choice)))) + )))) (context: "Products" - [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - primitives (r;list size gen-primitive) - choice (|> r;nat (:: @ map (n.% size))) - [_ +valueC] gen-primitive - #let [[singletonT singletonC] (|> primitives (list;nth choice) maybe;assume) - +primitives (list;concat (list (list;take choice primitives) - (list [(#;Bound +1) +valueC]) - (list;drop choice primitives))) - +tupleT (type;tuple (list/map product;left +primitives))]] - ($_ seq - (test "Can analyse product." - (|> (&;with-expected-type (type;tuple (list/map product;left primitives)) - (@;analyse-product analyse (list/map product;right primitives))) - (meta;run (init-compiler [])) - (case> (#e;Success tupleA) - (n.= size (list;size (flatten-tuple tupleA))) + (<| (times +100) + (do @ + [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + primitives (r;list size gen-primitive) + choice (|> r;nat (:: @ map (n.% size))) + [_ +valueC] gen-primitive + #let [[singletonT singletonC] (|> primitives (list;nth choice) maybe;assume) + +primitives (list;concat (list (list;take choice primitives) + (list [(#;Bound +1) +valueC]) + (list;drop choice primitives))) + +tupleT (type;tuple (list/map product;left +primitives))]] + ($_ seq + (test "Can analyse product." + (|> (&;with-expected-type (type;tuple (list/map product;left primitives)) + (@;analyse-product analyse (list/map product;right primitives))) + (meta;run (init-compiler [])) + (case> (#e;Success tupleA) + (n.= size (list;size (flatten-tuple tupleA))) - _ - false))) - (test "Can infer product." - (|> (@common;with-unknown-type - (@;analyse-product analyse (list/map product;right primitives))) - (meta;run (init-compiler [])) - (case> (#e;Success [_type tupleA]) - (and (type/= (type;tuple (list/map product;left primitives)) - _type) - (n.= size (list;size (flatten-tuple tupleA)))) + _ + false))) + (test "Can infer product." + (|> (@common;with-unknown-type + (@;analyse-product analyse (list/map product;right primitives))) + (meta;run (init-compiler [])) + (case> (#e;Success [_type tupleA]) + (and (type/= (type;tuple (list/map product;left primitives)) + _type) + (n.= size (list;size (flatten-tuple tupleA)))) - _ - false))) - (test "Can analyse pseudo-product (singleton tuple)" - (|> (&;with-expected-type singletonT - (analyse (` [(~ singletonC)]))) - (meta;run (init-compiler [])) - (case> (#e;Success singletonA) - true + _ + false))) + (test "Can analyse pseudo-product (singleton tuple)" + (|> (&;with-expected-type singletonT + (analyse (` [(~ singletonC)]))) + (meta;run (init-compiler [])) + (case> (#e;Success singletonA) + true - (#e;Error error) - false))) - (test "Can analyse product through bound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] - (do meta;Monad<Meta> - [_ (&;with-type-env - (tc;check varT (type;tuple (list/map product;left primitives))))] - (&;with-expected-type varT - (@;analyse-product analyse (list/map product;right primitives))))))) - (meta;run (init-compiler [])) - (case> (#e;Success [_ tupleA]) - (n.= size (list;size (flatten-tuple tupleA))) + (#e;Error error) + false))) + (test "Can analyse product through bound type-vars." + (|> (&;with-scope + (@common;with-var + (function [[var-id varT]] + (do meta;Monad<Meta> + [_ (&;with-type-env + (tc;check varT (type;tuple (list/map product;left primitives))))] + (&;with-expected-type varT + (@;analyse-product analyse (list/map product;right primitives))))))) + (meta;run (init-compiler [])) + (case> (#e;Success [_ tupleA]) + (n.= size (list;size (flatten-tuple tupleA))) - _ - false))) - (test "Can analyse product through existential quantification." - (|> (&;with-scope - (&;with-expected-type (type;ex-q +1 +tupleT) - (@;analyse-product analyse (list/map product;right +primitives)))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - true + _ + false))) + (test "Can analyse product through existential quantification." + (|> (&;with-scope + (&;with-expected-type (type;ex-q +1 +tupleT) + (@;analyse-product analyse (list/map product;right +primitives)))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + true - (#e;Error error) - false))) - (test "Cannot analyse product through universal quantification." - (|> (&;with-scope - (&;with-expected-type (type;univ-q +1 +tupleT) - (@;analyse-product analyse (list/map product;right +primitives)))) - (meta;run (init-compiler [])) - (case> (#e;Success _) - false + (#e;Error error) + false))) + (test "Cannot analyse product through universal quantification." + (|> (&;with-scope + (&;with-expected-type (type;univ-q +1 +tupleT) + (@;analyse-product analyse (list/map product;right +primitives)))) + (meta;run (init-compiler [])) + (case> (#e;Success _) + false - (#e;Error error) - true))) - )) + (#e;Error error) + true))) + )))) (def: (check-variant-inference variantT choice size analysis) (-> Type Nat Nat (Meta [Module Scope Type la;Analysis]) Bool) @@ -241,118 +245,122 @@ false))) (context: "Tagged Sums" - [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) - choice (|> r;nat (:: @ map (n.% size))) - other-choice (|> r;nat (:: @ map (n.% size)) (r;filter (|>. (n.= choice) not))) - primitives (r;list size gen-primitive) - module-name (r;text +5) - type-name (r;text +5) - #let [varT (#;Bound +1) - primitivesT (list/map product;left primitives) - [choiceT choiceC] (maybe;assume (list;nth choice primitives)) - [other-choiceT other-choiceC] (maybe;assume (list;nth other-choice primitives)) - variantT (type;variant primitivesT) - namedT (#;Named [module-name type-name] variantT) - polyT (|> (type;variant (list;concat (list (list;take choice primitivesT) - (list varT) - (list;drop (n.inc choice) primitivesT)))) - (type;univ-q +1)) - named-polyT (#;Named [module-name type-name] polyT) - choice-tag (maybe;assume (list;nth choice tags)) - other-choice-tag (maybe;assume (list;nth other-choice tags))]] - ($_ seq - (test "Can infer tagged sum." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false namedT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-tagged-sum analyse [module-name choice-tag] choiceC))))) - (check-variant-inference variantT choice size))) - (test "Tagged sums specialize when type-vars get bound." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-tagged-sum analyse [module-name choice-tag] choiceC))))) - (check-variant-inference variantT choice size))) - (test "Tagged sum inference retains universal quantification when type-vars are not bound." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) - (check-variant-inference polyT other-choice size))) - (test "Can specialize generic tagged sums." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (&;with-expected-type variantT - (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) - (meta;run (init-compiler [])) - (case> (^multi (#e;Success [_ _ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag other-choice) - (bool/= last? (n.= (n.dec size) other-choice))) + (<| (times +100) + (do @ + [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) + choice (|> r;nat (:: @ map (n.% size))) + other-choice (|> r;nat (:: @ map (n.% size)) (r;filter (|>. (n.= choice) not))) + primitives (r;list size gen-primitive) + module-name (r;text +5) + type-name (r;text +5) + #let [varT (#;Bound +1) + primitivesT (list/map product;left primitives) + [choiceT choiceC] (maybe;assume (list;nth choice primitives)) + [other-choiceT other-choiceC] (maybe;assume (list;nth other-choice primitives)) + variantT (type;variant primitivesT) + namedT (#;Named [module-name type-name] variantT) + polyT (|> (type;variant (list;concat (list (list;take choice primitivesT) + (list varT) + (list;drop (n.inc choice) primitivesT)))) + (type;univ-q +1)) + named-polyT (#;Named [module-name type-name] polyT) + choice-tag (maybe;assume (list;nth choice tags)) + other-choice-tag (maybe;assume (list;nth other-choice tags))]] + ($_ seq + (test "Can infer tagged sum." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false namedT)] + (&;with-scope + (@common;with-unknown-type + (@;analyse-tagged-sum analyse [module-name choice-tag] choiceC))))) + (check-variant-inference variantT choice size))) + (test "Tagged sums specialize when type-vars get bound." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (@common;with-unknown-type + (@;analyse-tagged-sum analyse [module-name choice-tag] choiceC))))) + (check-variant-inference variantT choice size))) + (test "Tagged sum inference retains universal quantification when type-vars are not bound." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (@common;with-unknown-type + (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) + (check-variant-inference polyT other-choice size))) + (test "Can specialize generic tagged sums." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (&;with-expected-type variantT + (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) + (meta;run (init-compiler [])) + (case> (^multi (#e;Success [_ _ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag other-choice) + (bool/= last? (n.= (n.dec size) other-choice))) - _ - false))) - )) + _ + false))) + )))) (context: "Records" - [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) - tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) - primitives (r;list size gen-primitive) - module-name (r;text +5) - type-name (r;text +5) - choice (|> r;nat (:: @ map (n.% size))) - #let [varT (#;Bound +1) - tagsC (list/map (|>. [module-name] code;tag) tags) - primitivesT (list/map product;left primitives) - primitivesC (list/map product;right primitives) - tupleT (type;tuple primitivesT) - namedT (#;Named [module-name type-name] tupleT) - recordC (list;zip2 tagsC primitivesC) - polyT (|> (type;tuple (list;concat (list (list;take choice primitivesT) - (list varT) - (list;drop (n.inc choice) primitivesT)))) - (type;univ-q +1)) - named-polyT (#;Named [module-name type-name] polyT)]] - ($_ seq - (test "Can infer record." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false namedT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-record analyse recordC))))) - (check-record-inference tupleT size))) - (test "Records specialize when type-vars get bound." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-record analyse recordC))))) - (check-record-inference tupleT size))) - (test "Can specialize generic records." - (|> (@module;with-module +0 module-name - (do meta;Monad<Meta> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (&;with-expected-type tupleT - (@;analyse-record analyse recordC))))) - (meta;run (init-compiler [])) - (case> (^multi (#e;Success [_ _ productA]) - [(flatten-tuple productA) - membersA]) - (n.= size (list;size membersA)) + (<| (times +100) + (do @ + [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) + tags (|> (r;set text;Hash<Text> size (r;text +5)) (:: @ map S;to-list)) + primitives (r;list size gen-primitive) + module-name (r;text +5) + type-name (r;text +5) + choice (|> r;nat (:: @ map (n.% size))) + #let [varT (#;Bound +1) + tagsC (list/map (|>. [module-name] code;tag) tags) + primitivesT (list/map product;left primitives) + primitivesC (list/map product;right primitives) + tupleT (type;tuple primitivesT) + namedT (#;Named [module-name type-name] tupleT) + recordC (list;zip2 tagsC primitivesC) + polyT (|> (type;tuple (list;concat (list (list;take choice primitivesT) + (list varT) + (list;drop (n.inc choice) primitivesT)))) + (type;univ-q +1)) + named-polyT (#;Named [module-name type-name] polyT)]] + ($_ seq + (test "Can infer record." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false namedT)] + (&;with-scope + (@common;with-unknown-type + (@;analyse-record analyse recordC))))) + (check-record-inference tupleT size))) + (test "Records specialize when type-vars get bound." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (@common;with-unknown-type + (@;analyse-record analyse recordC))))) + (check-record-inference tupleT size))) + (test "Can specialize generic records." + (|> (@module;with-module +0 module-name + (do meta;Monad<Meta> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (&;with-expected-type tupleT + (@;analyse-record analyse recordC))))) + (meta;run (init-compiler [])) + (case> (^multi (#e;Success [_ _ productA]) + [(flatten-tuple productA) + membersA]) + (n.= size (list;size membersA)) - _ - false))) - )) + _ + false))) + )))) diff --git a/new-luxc/test/test/luxc/analyser/type.lux b/new-luxc/test/test/luxc/analyser/type.lux index 87def3dad..eb414bf04 100644 --- a/new-luxc/test/test/luxc/analyser/type.lux +++ b/new-luxc/test/test/luxc/analyser/type.lux @@ -47,43 +47,45 @@ <triples>))) (context: "Type checking/coercion." - [[typeC codeT exprC] check] - ($_ seq - (test (format "Can analyse type-checking.") - (|> (do Monad<Meta> - [runtime-bytecode @runtime;generate] - (&;with-scope - (@common;with-unknown-type - (@;analyse-check analyse eval;eval typeC exprC)))) - (meta;run (init-compiler [])) - (case> (#e;Success [_ [analysisT analysisA]]) - (and (type/= codeT analysisT) - (case [exprC analysisA] - (^template [<expected> <actual> <test>] - [[_ (<expected> expected)] (<actual> actual)] - (<test> expected actual)) - ([#;Bool #~;Bool bool/=] - [#;Nat #~;Nat n.=] - [#;Int #~;Int i.=] - [#;Deg #~;Deg d.=] - [#;Frac #~;Frac f.=] - [#;Text #~;Text text/=]) - - _ - false)) + (<| (times +100) + (do @ + [[typeC codeT exprC] check] + ($_ seq + (test (format "Can analyse type-checking.") + (|> (do Monad<Meta> + [runtime-bytecode @runtime;generate] + (&;with-scope + (@common;with-unknown-type + (@;analyse-check analyse eval;eval typeC exprC)))) + (meta;run (init-compiler [])) + (case> (#e;Success [_ [analysisT analysisA]]) + (and (type/= codeT analysisT) + (case [exprC analysisA] + (^template [<expected> <actual> <test>] + [[_ (<expected> expected)] (<actual> actual)] + (<test> expected actual)) + ([#;Bool #~;Bool bool/=] + [#;Nat #~;Nat n.=] + [#;Int #~;Int i.=] + [#;Deg #~;Deg d.=] + [#;Frac #~;Frac f.=] + [#;Text #~;Text text/=]) + + _ + false)) - (#e;Error error) - false))) - (test (format "Can analyse type-coercion.") - (|> (do Monad<Meta> - [runtime-bytecode @runtime;generate] - (&;with-scope - (@common;with-unknown-type - (@;analyse-coerce analyse eval;eval typeC exprC)))) - (meta;run (init-compiler [])) - (case> (#e;Success [_ [analysisT analysisA]]) - (type/= codeT analysisT) + (#e;Error error) + false))) + (test (format "Can analyse type-coercion.") + (|> (do Monad<Meta> + [runtime-bytecode @runtime;generate] + (&;with-scope + (@common;with-unknown-type + (@;analyse-coerce analyse eval;eval typeC exprC)))) + (meta;run (init-compiler [])) + (case> (#e;Success [_ [analysisT analysisA]]) + (type/= codeT analysisT) - (#e;Error error) - false))) - )) + (#e;Error error) + false))) + )))) |