diff options
Diffstat (limited to '')
-rw-r--r-- | new-luxc/test/test/luxc/analyser/case.lux | 64 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/function.lux | 118 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/primitive.lux | 22 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/procedure/common.lux | 510 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/reference.lux | 46 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/analyser/structure.lux | 378 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/common.lux | 3 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/generator/primitive.lux | 30 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/generator/structure.lux | 62 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/parser.lux | 110 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/synthesizer/function.lux | 76 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/synthesizer/loop.lux | 44 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/synthesizer/primitive.lux | 14 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/synthesizer/procedure.lux | 20 | ||||
-rw-r--r-- | new-luxc/test/test/luxc/synthesizer/structure.lux | 38 |
15 files changed, 769 insertions, 766 deletions
diff --git a/new-luxc/test/test/luxc/analyser/case.lux b/new-luxc/test/test/luxc/analyser/case.lux index 3fe67b7a3..037f99feb 100644 --- a/new-luxc/test/test/luxc/analyser/case.lux +++ b/new-luxc/test/test/luxc/analyser/case.lux @@ -120,7 +120,7 @@ (r/wrap (code;record (list;zip2 record-tags primitivesC))) )))) -(test: "Pattern-matching." +(context: "Pattern-matching." #seed +9253409297339902486 [module-name (r;text +5) variant-name (r;text +5) @@ -142,35 +142,35 @@ non-total-branchesC (list;take (n.dec (list;size total-branchesC)) total-branchesC)]] ($_ seq - (assert "Will reject empty pattern-matching (no branches)." - (|> (&;with-scope - (&;with-expected-type outputT - (@;analyse-case analyse inputC (list)))) - check-failure)) - (assert "Can analyse total pattern-matching." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@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 total-branchesC))))) - check-success)) - (assert "Will reject non-total pattern-matching." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@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-total-branchesC))))) - check-failure)) + (test "Will reject empty pattern-matching (no branches)." + (|> (&;with-scope + (&;with-expected-type outputT + (@;analyse-case analyse inputC (list)))) + check-failure)) + (test "Can analyse total pattern-matching." + (|> (@module;with-module +0 module-name + (do Monad<Lux> + [_ (@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 total-branchesC))))) + check-success)) + (test "Will reject non-total pattern-matching." + (|> (@module;with-module +0 module-name + (do Monad<Lux> + [_ (@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-total-branchesC))))) + check-failure)) )) diff --git a/new-luxc/test/test/luxc/analyser/function.lux b/new-luxc/test/test/luxc/analyser/function.lux index 4957bfe06..909fb9293 100644 --- a/new-luxc/test/test/luxc/analyser/function.lux +++ b/new-luxc/test/test/luxc/analyser/function.lux @@ -64,49 +64,49 @@ (#R;Error error) false))) -(test: "Function definition." +(context: "Function definition." [func-name (r;text +5) arg-name (|> (r;text +5) (r;filter (|>. (T/= func-name) not))) [outputT outputC] gen-primitive [inputT _] gen-primitive] ($_ seq - (assert "Can analyse function." - (|> (&;with-expected-type (type (All [a] (-> a outputT))) - (@;analyse-function analyse func-name arg-name outputC)) - (macro;run (init-compiler [])) - succeeds?)) - (assert "Generic functions can always be specialized." - (and (|> (&;with-expected-type (-> inputT outputT) - (@;analyse-function analyse func-name arg-name outputC)) - (macro;run (init-compiler [])) - succeeds?) - (|> (&;with-expected-type (-> inputT inputT) - (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) - (macro;run (init-compiler [])) - succeeds?))) - (assert "Can infer function (constant output and unused input)." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name outputC)) - (macro;run (init-compiler [])) - (check-type (type (All [a] (-> a outputT)))))) - (assert "Can infer function (output = input)." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) - (macro;run (init-compiler [])) - (check-type (type (All [a] (-> a a)))))) - (assert "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]))) - (macro;run (init-compiler [])) - succeeds?)) - (assert "Can infer recursive types for functions." - (|> (@common;with-unknown-type - (@;analyse-function analyse func-name arg-name (code;symbol ["" func-name]))) - (macro;run (init-compiler [])) - (check-type (type (Rec self (All [a] (-> a self))))))) + (test "Can analyse function." + (|> (&;with-expected-type (type (All [a] (-> a outputT))) + (@;analyse-function analyse func-name arg-name outputC)) + (macro;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)) + (macro;run (init-compiler [])) + succeeds?) + (|> (&;with-expected-type (-> inputT inputT) + (@;analyse-function analyse func-name arg-name (code;symbol ["" arg-name]))) + (macro;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)) + (macro;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]))) + (macro;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]))) + (macro;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]))) + (macro;run (init-compiler [])) + (check-type (type (Rec self (All [a] (-> a self))))))) )) -(test: "Function application." +(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)))) @@ -130,27 +130,27 @@ (type;function (#;Cons varT partial-poly-inputsT)) varT)]] ($_ seq - (assert "Can analyse monomorphic type application." - (|> (@common;with-unknown-type - (@;analyse-apply analyse funcT (#la;Unit) inputsC)) - (check-apply outputT full-args))) - (assert "Can partially apply functions." - (|> (@common;with-unknown-type - (@;analyse-apply analyse funcT (#la;Unit) - (list;take partial-args inputsC))) - (check-apply partialT partial-args))) - (assert "Can apply polymorphic functions." - (|> (@common;with-unknown-type - (@;analyse-apply analyse polyT (#la;Unit) inputsC)) - (check-apply poly-inputT full-args))) - (assert "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)))) - (assert "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))) + (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 5e4e318a5..545b4e0fd 100644 --- a/new-luxc/test/test/luxc/analyser/primitive.lux +++ b/new-luxc/test/test/luxc/analyser/primitive.lux @@ -27,7 +27,7 @@ (.. common) (test/luxc common)) -(test: "Primitives" +(context: "Primitives" [%bool% r;bool %nat% r;nat %int% r;int @@ -37,17 +37,17 @@ %text% (r;text +5)] (with-expansions [<tests> (do-template [<desc> <type> <tag> <value> <analyser>] - [(assert (format "Can analyse " <desc> ".") - (|> (@common;with-unknown-type - (<analyser> <value>)) - (macro;run (init-compiler [])) - (case> (#R;Success [_type (<tag> value)]) - (and (Type/= <type> _type) - (is <value> value)) + [(test (format "Can analyse " <desc> ".") + (|> (@common;with-unknown-type + (<analyser> <value>)) + (macro;run (init-compiler [])) + (case> (#R;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] diff --git a/new-luxc/test/test/luxc/analyser/procedure/common.lux b/new-luxc/test/test/luxc/analyser/procedure/common.lux index 9ebcf6880..dd099829c 100644 --- a/new-luxc/test/test/luxc/analyser/procedure/common.lux +++ b/new-luxc/test/test/luxc/analyser/procedure/common.lux @@ -39,268 +39,268 @@ [check-failure+ false true] ) -(test: "Lux procedures" +(context: "Lux procedures" [[primT primC] gen-primitive [antiT antiC] (|> gen-primitive (r;filter (|>. product;left (Type/= primT) not)))] ($_ seq - (assert "Can test for reference equality." - (check-success+ "lux is" (list primC primC) Bool)) - (assert "Reference equality must be done with elements of the same type." - (check-failure+ "lux is" (list primC antiC) Bool)) - (assert "Can 'try' risky IO computations." - (check-success+ "lux try" - (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - (type (Either Text primT)))) + (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)))) )) -(test: "Bit procedures" +(context: "Bit procedures" [subjectC (|> r;nat (:: @ map code;nat)) signedC (|> r;int (:: @ map code;int)) paramC (|> r;nat (:: @ map code;nat))] ($_ seq - (assert "Can count the number of 1 bits in a bit pattern." - (check-success+ "bit count" (list subjectC) Nat)) - (assert "Can perform bit 'and'." - (check-success+ "bit and" (list subjectC paramC) Nat)) - (assert "Can perform bit 'or'." - (check-success+ "bit or" (list subjectC paramC) Nat)) - (assert "Can perform bit 'xor'." - (check-success+ "bit xor" (list subjectC paramC) Nat)) - (assert "Can shift bit pattern to the left." - (check-success+ "bit shift-left" (list subjectC paramC) Nat)) - (assert "Can shift bit pattern to the right." - (check-success+ "bit unsigned-shift-right" (list subjectC paramC) Nat)) - (assert "Can shift signed bit pattern to the right." - (check-success+ "bit shift-right" (list signedC paramC) Int)) + (test "Can count the number of 1 bits in a bit pattern." + (check-success+ "bit count" (list subjectC) Nat)) + (test "Can perform bit 'and'." + (check-success+ "bit and" (list subjectC paramC) Nat)) + (test "Can perform bit 'or'." + (check-success+ "bit or" (list subjectC paramC) Nat)) + (test "Can perform bit 'xor'." + (check-success+ "bit xor" (list subjectC paramC) Nat)) + (test "Can shift bit pattern to the left." + (check-success+ "bit shift-left" (list subjectC paramC) Nat)) + (test "Can shift bit pattern to the right." + (check-success+ "bit unsigned-shift-right" (list subjectC paramC) Nat)) + (test "Can shift signed bit pattern to the right." + (check-success+ "bit shift-right" (list signedC paramC) Int)) )) -(test: "Nat procedures" +(context: "Nat procedures" [subjectC (|> r;nat (:: @ map code;nat)) paramC (|> r;nat (:: @ map code;nat))] ($_ seq - (assert "Can add natural numbers." - (check-success+ "nat +" (list subjectC paramC) Nat)) - (assert "Can subtract natural numbers." - (check-success+ "nat -" (list subjectC paramC) Nat)) - (assert "Can multiply natural numbers." - (check-success+ "nat *" (list subjectC paramC) Nat)) - (assert "Can divide natural numbers." - (check-success+ "nat /" (list subjectC paramC) Nat)) - (assert "Can calculate remainder of natural numbers." - (check-success+ "nat %" (list subjectC paramC) Nat)) - (assert "Can test equality of natural numbers." - (check-success+ "nat =" (list subjectC paramC) Bool)) - (assert "Can compare natural numbers." - (check-success+ "nat <" (list subjectC paramC) Bool)) - (assert "Can obtain minimum natural number." - (check-success+ "nat min" (list) Nat)) - (assert "Can obtain maximum natural number." - (check-success+ "nat max" (list) Nat)) - (assert "Can convert natural number to integer." - (check-success+ "nat to-int" (list subjectC) Int)) - (assert "Can convert natural number to text." - (check-success+ "nat to-text" (list subjectC) Text)) + (test "Can add natural numbers." + (check-success+ "nat +" (list subjectC paramC) Nat)) + (test "Can subtract natural numbers." + (check-success+ "nat -" (list subjectC paramC) Nat)) + (test "Can multiply natural numbers." + (check-success+ "nat *" (list subjectC paramC) Nat)) + (test "Can divide natural numbers." + (check-success+ "nat /" (list subjectC paramC) Nat)) + (test "Can calculate remainder of natural numbers." + (check-success+ "nat %" (list subjectC paramC) Nat)) + (test "Can test equality of natural numbers." + (check-success+ "nat =" (list subjectC paramC) Bool)) + (test "Can compare natural numbers." + (check-success+ "nat <" (list subjectC paramC) Bool)) + (test "Can obtain minimum natural number." + (check-success+ "nat min" (list) Nat)) + (test "Can obtain maximum natural number." + (check-success+ "nat max" (list) Nat)) + (test "Can convert natural number to integer." + (check-success+ "nat to-int" (list subjectC) Int)) + (test "Can convert natural number to text." + (check-success+ "nat to-text" (list subjectC) Text)) )) -(test: "Int procedures" +(context: "Int procedures" [subjectC (|> r;int (:: @ map code;int)) paramC (|> r;int (:: @ map code;int))] ($_ seq - (assert "Can add integers." - (check-success+ "int +" (list subjectC paramC) Int)) - (assert "Can subtract integers." - (check-success+ "int -" (list subjectC paramC) Int)) - (assert "Can multiply integers." - (check-success+ "int *" (list subjectC paramC) Int)) - (assert "Can divide integers." - (check-success+ "int /" (list subjectC paramC) Int)) - (assert "Can calculate remainder of integers." - (check-success+ "int %" (list subjectC paramC) Int)) - (assert "Can test equality of integers." - (check-success+ "int =" (list subjectC paramC) Bool)) - (assert "Can compare integers." - (check-success+ "int <" (list subjectC paramC) Bool)) - (assert "Can obtain minimum integer." - (check-success+ "int min" (list) Int)) - (assert "Can obtain maximum integer." - (check-success+ "int max" (list) Int)) - (assert "Can convert integer to natural number." - (check-success+ "int to-nat" (list subjectC) Nat)) - (assert "Can convert integer to real number." - (check-success+ "int to-real" (list subjectC) Real)) + (test "Can add integers." + (check-success+ "int +" (list subjectC paramC) Int)) + (test "Can subtract integers." + (check-success+ "int -" (list subjectC paramC) Int)) + (test "Can multiply integers." + (check-success+ "int *" (list subjectC paramC) Int)) + (test "Can divide integers." + (check-success+ "int /" (list subjectC paramC) Int)) + (test "Can calculate remainder of integers." + (check-success+ "int %" (list subjectC paramC) Int)) + (test "Can test equality of integers." + (check-success+ "int =" (list subjectC paramC) Bool)) + (test "Can compare integers." + (check-success+ "int <" (list subjectC paramC) Bool)) + (test "Can obtain minimum integer." + (check-success+ "int min" (list) Int)) + (test "Can obtain maximum integer." + (check-success+ "int max" (list) Int)) + (test "Can convert integer to natural number." + (check-success+ "int to-nat" (list subjectC) Nat)) + (test "Can convert integer to real number." + (check-success+ "int to-real" (list subjectC) Real)) )) -(test: "Deg procedures" +(context: "Deg procedures" [subjectC (|> r;deg (:: @ map code;deg)) paramC (|> r;deg (:: @ map code;deg)) natC (|> r;nat (:: @ map code;nat))] ($_ seq - (assert "Can add degrees." - (check-success+ "deg +" (list subjectC paramC) Deg)) - (assert "Can subtract degrees." - (check-success+ "deg -" (list subjectC paramC) Deg)) - (assert "Can multiply degrees." - (check-success+ "deg *" (list subjectC paramC) Deg)) - (assert "Can divide degrees." - (check-success+ "deg /" (list subjectC paramC) Deg)) - (assert "Can calculate remainder of degrees." - (check-success+ "deg %" (list subjectC paramC) Deg)) - (assert "Can test equality of degrees." - (check-success+ "deg =" (list subjectC paramC) Bool)) - (assert "Can compare degrees." - (check-success+ "deg <" (list subjectC paramC) Bool)) - (assert "Can obtain minimum degree." - (check-success+ "deg min" (list) Deg)) - (assert "Can obtain maximum degree." - (check-success+ "deg max" (list) Deg)) - (assert "Can convert degree to real number." - (check-success+ "deg to-real" (list subjectC) Real)) - (assert "Can scale degree." - (check-success+ "deg scale" (list subjectC natC) Deg)) - (assert "Can calculate the reciprocal of a natural number." - (check-success+ "deg reciprocal" (list natC) Deg)) + (test "Can add degrees." + (check-success+ "deg +" (list subjectC paramC) Deg)) + (test "Can subtract degrees." + (check-success+ "deg -" (list subjectC paramC) Deg)) + (test "Can multiply degrees." + (check-success+ "deg *" (list subjectC paramC) Deg)) + (test "Can divide degrees." + (check-success+ "deg /" (list subjectC paramC) Deg)) + (test "Can calculate remainder of degrees." + (check-success+ "deg %" (list subjectC paramC) Deg)) + (test "Can test equality of degrees." + (check-success+ "deg =" (list subjectC paramC) Bool)) + (test "Can compare degrees." + (check-success+ "deg <" (list subjectC paramC) Bool)) + (test "Can obtain minimum degree." + (check-success+ "deg min" (list) Deg)) + (test "Can obtain maximum degree." + (check-success+ "deg max" (list) Deg)) + (test "Can convert degree to real number." + (check-success+ "deg to-real" (list subjectC) Real)) + (test "Can scale degree." + (check-success+ "deg scale" (list subjectC natC) Deg)) + (test "Can calculate the reciprocal of a natural number." + (check-success+ "deg reciprocal" (list natC) Deg)) )) -(test: "Real procedures" +(context: "Real procedures" [subjectC (|> r;real (:: @ map code;real)) paramC (|> r;real (:: @ map code;real)) encodedC (|> (r;text +5) (:: @ map code;text))] ($_ seq - (assert "Can add real numbers." - (check-success+ "real +" (list subjectC paramC) Real)) - (assert "Can subtract real numbers." - (check-success+ "real -" (list subjectC paramC) Real)) - (assert "Can multiply real numbers." - (check-success+ "real *" (list subjectC paramC) Real)) - (assert "Can divide real numbers." - (check-success+ "real /" (list subjectC paramC) Real)) - (assert "Can calculate remainder of real numbers." - (check-success+ "real %" (list subjectC paramC) Real)) - (assert "Can test equality of real numbers." - (check-success+ "real =" (list subjectC paramC) Bool)) - (assert "Can compare real numbers." - (check-success+ "real <" (list subjectC paramC) Bool)) - (assert "Can obtain minimum real number." - (check-success+ "real min" (list) Real)) - (assert "Can obtain maximum real number." - (check-success+ "real max" (list) Real)) - (assert "Can obtain smallest real number." - (check-success+ "real smallest" (list) Real)) - (assert "Can obtain not-a-number." - (check-success+ "real not-a-number" (list) Real)) - (assert "Can obtain positive infinity." - (check-success+ "real positive-infinity" (list) Real)) - (assert "Can obtain negative infinity." - (check-success+ "real negative-infinity" (list) Real)) - (assert "Can convert real number to integer." - (check-success+ "real to-int" (list subjectC) Int)) - (assert "Can convert real number to degree." - (check-success+ "real to-deg" (list subjectC) Deg)) - (assert "Can convert real number to text." - (check-success+ "real to-text" (list subjectC) Text)) - (assert "Can convert text to real number." - (check-success+ "real from-text" (list encodedC) (type (Maybe Real)))) + (test "Can add real numbers." + (check-success+ "real +" (list subjectC paramC) Real)) + (test "Can subtract real numbers." + (check-success+ "real -" (list subjectC paramC) Real)) + (test "Can multiply real numbers." + (check-success+ "real *" (list subjectC paramC) Real)) + (test "Can divide real numbers." + (check-success+ "real /" (list subjectC paramC) Real)) + (test "Can calculate remainder of real numbers." + (check-success+ "real %" (list subjectC paramC) Real)) + (test "Can test equality of real numbers." + (check-success+ "real =" (list subjectC paramC) Bool)) + (test "Can compare real numbers." + (check-success+ "real <" (list subjectC paramC) Bool)) + (test "Can obtain minimum real number." + (check-success+ "real min" (list) Real)) + (test "Can obtain maximum real number." + (check-success+ "real max" (list) Real)) + (test "Can obtain smallest real number." + (check-success+ "real smallest" (list) Real)) + (test "Can obtain not-a-number." + (check-success+ "real not-a-number" (list) Real)) + (test "Can obtain positive infinity." + (check-success+ "real positive-infinity" (list) Real)) + (test "Can obtain negative infinity." + (check-success+ "real negative-infinity" (list) Real)) + (test "Can convert real number to integer." + (check-success+ "real to-int" (list subjectC) Int)) + (test "Can convert real number to degree." + (check-success+ "real to-deg" (list subjectC) Deg)) + (test "Can convert real number to text." + (check-success+ "real to-text" (list subjectC) Text)) + (test "Can convert text to real number." + (check-success+ "real from-text" (list encodedC) (type (Maybe Real)))) )) -(test: "Text procedures" +(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 - (assert "Can test text equality." - (check-success+ "text =" (list subjectC paramC) Bool)) - (assert "Compare texts in lexicographical order." - (check-success+ "text <" (list subjectC paramC) Bool)) - (assert "Can prepend one text to another." - (check-success+ "text prepend" (list subjectC paramC) Text)) - (assert "Can find the index of a piece of text inside a larger one that (may) contain it." - (check-success+ "text index" (list subjectC paramC fromC) (type (Maybe Nat)))) - (assert "Can query the size/length of a text." - (check-success+ "text size" (list subjectC) Nat)) - (assert "Can calculate a hash code for text." - (check-success+ "text hash" (list subjectC) Nat)) - (assert "Can replace a text inside of a larger one (once)." - (check-success+ "text replace-once" (list subjectC paramC replacementC) Text)) - (assert "Can replace a text inside of a larger one (all times)." - (check-success+ "text replace-all" (list subjectC paramC replacementC) Text)) - (assert "Can obtain the character code of a text at a given index." - (check-success+ "text char" (list subjectC fromC) Nat)) - (assert "Can clip a piece of text between 2 indices." - (check-success+ "text clip" (list subjectC fromC toC) Text)) + (test "Can test text equality." + (check-success+ "text =" (list subjectC paramC) Bool)) + (test "Compare texts in lexicographical order." + (check-success+ "text <" (list subjectC paramC) Bool)) + (test "Can prepend one text to another." + (check-success+ "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+ "text index" (list subjectC paramC fromC) (type (Maybe Nat)))) + (test "Can query the size/length of a text." + (check-success+ "text size" (list subjectC) Nat)) + (test "Can calculate a hash code for text." + (check-success+ "text hash" (list subjectC) Nat)) + (test "Can replace a text inside of a larger one (once)." + (check-success+ "text replace-once" (list subjectC paramC replacementC) Text)) + (test "Can replace a text inside of a larger one (all times)." + (check-success+ "text replace-all" (list subjectC paramC replacementC) Text)) + (test "Can obtain the character code of a text at a given index." + (check-success+ "text char" (list subjectC fromC) Nat)) + (test "Can clip a piece of text between 2 indices." + (check-success+ "text clip" (list subjectC fromC toC) Text)) )) -(test: "Array procedures" +(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;Array elemT))]] ($_ seq - (assert "Can create arrays." - (check-success+ "array new" (list sizeC) arrayT)) - (assert "Can get a value inside an array." - (|> (&env;with-scope "" - (&env;with-local [var-name arrayT] - (&;with-expected-type elemT - (@;analyse-procedure analyse "array get" - (list idxC - (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (test "Can create arrays." + (check-success+ "array new" (list sizeC) arrayT)) + (test "Can get a value inside an array." + (|> (&env;with-scope "" + (&env;with-local [var-name arrayT] + (&;with-expected-type elemT + (@;analyse-procedure analyse "array get" + (list idxC + (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) - (assert "Can put a value inside an array." - (|> (&env;with-scope "" - (&env;with-local [var-name arrayT] - (&;with-expected-type arrayT - (@;analyse-procedure analyse "array put" - (list idxC - elemC - (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (#R;Error _) + false))) + (test "Can put a value inside an array." + (|> (&env;with-scope "" + (&env;with-local [var-name arrayT] + (&;with-expected-type arrayT + (@;analyse-procedure analyse "array put" + (list idxC + elemC + (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) - (assert "Can remove a value from an array." - (|> (&env;with-scope "" - (&env;with-local [var-name arrayT] - (&;with-expected-type arrayT - (@;analyse-procedure analyse "array remove" - (list idxC - (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (#R;Error _) + false))) + (test "Can remove a value from an array." + (|> (&env;with-scope "" + (&env;with-local [var-name arrayT] + (&;with-expected-type arrayT + (@;analyse-procedure analyse "array remove" + (list idxC + (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) - (assert "Can query the size of an array." - (|> (&env;with-scope "" - (&env;with-local [var-name arrayT] - (&;with-expected-type Nat - (@;analyse-procedure analyse "array size" - (list (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (#R;Error _) + false))) + (test "Can query the size of an array." + (|> (&env;with-scope "" + (&env;with-local [var-name arrayT] + (&;with-expected-type Nat + (@;analyse-procedure analyse "array size" + (list (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) + (#R;Error _) + false))) )) -(test: "Math procedures" +(context: "Math procedures" [subjectC (|> r;real (:: @ map code;real)) paramC (|> r;real (:: @ map code;real))] (with-expansions [<unary> (do-template [<proc> <desc>] - [(assert (format "Can calculate " <desc> ".") - (check-success+ <proc> (list subjectC) Real))] + [(test (format "Can calculate " <desc> ".") + (check-success+ <proc> (list subjectC) Real))] ["math cos" "cosine"] ["math sin" "sine"] @@ -319,8 +319,8 @@ ["math floor" "floor"] ["math round" "rounding"]) <binary> (do-template [<proc> <desc>] - [(assert (format "Can calculate " <desc> ".") - (check-success+ <proc> (list subjectC paramC) Real))] + [(test (format "Can calculate " <desc> ".") + (check-success+ <proc> (list subjectC paramC) Real))] ["math atan2" "inverse/arc tangent (with 2 arguments)"] ["math pow" "power"])] @@ -328,70 +328,70 @@ <unary> <binary>))) -(test: "Atom procedures" +(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 - (assert "Can create atomic reference." - (check-success+ "atom new" (list elemC) atomT)) - (assert "Can read the value of an atomic reference." - (|> (&env;with-scope "" - (&env;with-local [var-name atomT] - (&;with-expected-type elemT - (@;analyse-procedure analyse "atom read" - (list (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (test "Can create atomic reference." + (check-success+ "atom new" (list elemC) atomT)) + (test "Can read the value of an atomic reference." + (|> (&env;with-scope "" + (&env;with-local [var-name atomT] + (&;with-expected-type elemT + (@;analyse-procedure analyse "atom read" + (list (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) - (assert "Can swap the value of an atomic reference." - (|> (&env;with-scope "" - (&env;with-local [var-name atomT] - (&;with-expected-type Bool - (@;analyse-procedure analyse "atom compare-and-swap" - (list elemC - elemC - (code;symbol ["" var-name])))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + (#R;Error _) + false))) + (test "Can swap the value of an atomic reference." + (|> (&env;with-scope "" + (&env;with-local [var-name atomT] + (&;with-expected-type Bool + (@;analyse-procedure analyse "atom compare-and-swap" + (list elemC + elemC + (code;symbol ["" var-name])))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error _) - false))) + (#R;Error _) + false))) )) -(test: "Process procedures" +(context: "Process procedures" [[primT primC] gen-primitive timeC (|> r;nat (:: @ map code;nat))] ($_ seq - (assert "Can query the level of concurrency." - (check-success+ "process concurrency-level" (list) Nat)) - (assert "Can run an IO computation concurrently." - (check-success+ "process future" - (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - Unit)) - (assert "Can schedule an IO computation to run concurrently at some future time." - (check-success+ "process schedule" - (list timeC - (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) - Unit)) + (test "Can query the level of concurrency." + (check-success+ "process concurrency-level" (list) Nat)) + (test "Can run an IO computation concurrently." + (check-success+ "process future" + (list (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) + Unit)) + (test "Can schedule an IO computation to run concurrently at some future time." + (check-success+ "process schedule" + (list timeC + (` ((~' _lux_function) (~' _) (~' _) (~ primC)))) + Unit)) )) -(test: "IO procedures" +(context: "IO procedures" [logC (|> (r;text +5) (:: @ map code;text)) exitC (|> r;nat (:: @ map code;nat))] ($_ seq - (assert "Can log messages to standard output." - (check-success+ "io log" (list logC) Unit)) - (assert "Can log messages to standard output." - (check-success+ "io error" (list logC) Bottom)) - (assert "Can log messages to standard output." - (check-success+ "io exit" (list exitC) Bottom)) - (assert "Can query the current time (as milliseconds since epoch)." - (check-success+ "io current-time" (list) Int)) + (test "Can log messages to standard output." + (check-success+ "io log" (list logC) Unit)) + (test "Can log messages to standard output." + (check-success+ "io error" (list logC) Bottom)) + (test "Can log messages to standard output." + (check-success+ "io exit" (list exitC) Bottom)) + (test "Can query the current time (as milliseconds since epoch)." + (check-success+ "io current-time" (list) Int)) )) diff --git a/new-luxc/test/test/luxc/analyser/reference.lux b/new-luxc/test/test/luxc/analyser/reference.lux index 5e277b2a6..33d93e415 100644 --- a/new-luxc/test/test/luxc/analyser/reference.lux +++ b/new-luxc/test/test/luxc/analyser/reference.lux @@ -17,34 +17,34 @@ (.. common) (test/luxc common)) -(test: "References" +(context: "References" [[ref-type _] gen-primitive module-name (r;text +5) scope-name (r;text +5) var-name (r;text +5)] ($_ seq - (assert "Can analyse relative reference." - (|> (&env;with-scope scope-name - (&env;with-local [var-name ref-type] - (@common;with-unknown-type - (@;analyse-reference ["" var-name])))) - (macro;run (init-compiler [])) - (case> (#R;Success [_type (#~;Relative idx)]) - (Type/= ref-type _type) - - _ - false))) - (assert "Can analyse absolute reference." - (|> (do Monad<Lux> - [_ (&module;create +0 module-name) - _ (&module;define [module-name var-name] - [ref-type (list) (:! Void [])])] + (test "Can analyse relative reference." + (|> (&env;with-scope scope-name + (&env;with-local [var-name ref-type] (@common;with-unknown-type - (@;analyse-reference [module-name var-name]))) - (macro;run (init-compiler [])) - (case> (#R;Success [_type (#~;Absolute idx)]) - (Type/= ref-type _type) + (@;analyse-reference ["" var-name])))) + (macro;run (init-compiler [])) + (case> (#R;Success [_type (#~;Relative idx)]) + (Type/= ref-type _type) + + _ + false))) + (test "Can analyse absolute reference." + (|> (do Monad<Lux> + [_ (&module;create +0 module-name) + _ (&module;define [module-name var-name] + [ref-type (list) (:! Void [])])] + (@common;with-unknown-type + (@;analyse-reference [module-name var-name]))) + (macro;run (init-compiler [])) + (case> (#R;Success [_type (#~;Absolute 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 597388aa2..914b1bf3b 100644 --- a/new-luxc/test/test/luxc/analyser/structure.lux +++ b/new-luxc/test/test/luxc/analyser/structure.lux @@ -55,7 +55,7 @@ _ #;None)) -(test: "Sums" +(context: "Sums" [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) choice (|> r;nat (:: @ map (n.% size))) primitives (r;list size gen-primitive) @@ -70,72 +70,72 @@ [+valueT +valueC] (assume (list;nth +choice +primitives)) +variantT (type;variant (L/map product;left +primitives))]] ($_ seq - (assert "Can analyse sum." - (|> (&;with-scope - (&;with-expected-type variantT - (@;analyse-sum analyse choice valueC))) - (macro;run (init-compiler [])) - (case> (^multi (#R;Success [_ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag choice) - (B/= last? (n.= (n.dec size) choice))) + (test "Can analyse sum." + (|> (&;with-scope + (&;with-expected-type variantT + (@;analyse-sum analyse choice valueC))) + (macro;run (init-compiler [])) + (case> (^multi (#R;Success [_ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag choice) + (B/= last? (n.= (n.dec size) choice))) - _ - false))) - (assert "Can analyse sum through bound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] - (do Monad<Lux> - [_ (&;within-type-env - (TC;check varT variantT))] - (&;with-expected-type varT - (@;analyse-sum analyse choice valueC)))))) - (macro;run (init-compiler [])) - (case> (^multi (#R;Success [_ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag choice) - (B/= last? (n.= (n.dec size) choice))) - - _ - false))) - (assert "Cannot analyse sum through unbound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] + _ + false))) + (test "Can analyse sum through bound type-vars." + (|> (&;with-scope + (@common;with-var + (function [[var-id varT]] + (do Monad<Lux> + [_ (&;within-type-env + (TC;check varT variantT))] (&;with-expected-type varT - (@;analyse-sum analyse choice valueC))))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - false + (@;analyse-sum analyse choice valueC)))))) + (macro;run (init-compiler [])) + (case> (^multi (#R;Success [_ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag choice) + (B/= 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))))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + false - _ - true))) - (assert "Can analyse sum through existential quantification." - (|> (&;with-scope - (&;with-expected-type (type;ex-q +1 +variantT) - (@;analyse-sum analyse +choice +valueC))) - (macro;run (init-compiler [])) - (case> (#R;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))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error error) - false))) - (assert "Can analyse sum through universal quantification." - (|> (&;with-scope - (&;with-expected-type (type;univ-q +1 +variantT) - (@;analyse-sum analyse +choice +valueC))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - (not (n.= choice +choice)) + (#R;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))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + (not (n.= choice +choice)) - (#R;Error error) - (n.= choice +choice)))) + (#R;Error error) + (n.= choice +choice)))) )) -(test: "Products" +(context: "Products" [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) primitives (r;list size gen-primitive) choice (|> r;nat (:: @ map (n.% size))) @@ -146,70 +146,70 @@ (list;drop choice primitives))) +tupleT (type;tuple (L/map product;left +primitives))]] ($_ seq - (assert "Can analyse product." - (|> (&;with-expected-type (type;tuple (L/map product;left primitives)) - (@;analyse-product analyse (L/map product;right primitives))) - (macro;run (init-compiler [])) - (case> (#R;Success tupleA) - (n.= size (list;size (flatten-tuple tupleA))) + (test "Can analyse product." + (|> (&;with-expected-type (type;tuple (L/map product;left primitives)) + (@;analyse-product analyse (L/map product;right primitives))) + (macro;run (init-compiler [])) + (case> (#R;Success tupleA) + (n.= size (list;size (flatten-tuple tupleA))) - _ - false))) - (assert "Can infer product." - (|> (@common;with-unknown-type - (@;analyse-product analyse (L/map product;right primitives))) - (macro;run (init-compiler [])) - (case> (#R;Success [_type tupleA]) - (and (Type/= (type;tuple (L/map product;left primitives)) - _type) - (n.= size (list;size (flatten-tuple tupleA)))) + _ + false))) + (test "Can infer product." + (|> (@common;with-unknown-type + (@;analyse-product analyse (L/map product;right primitives))) + (macro;run (init-compiler [])) + (case> (#R;Success [_type tupleA]) + (and (Type/= (type;tuple (L/map product;left primitives)) + _type) + (n.= size (list;size (flatten-tuple tupleA)))) - _ - false))) - (assert "Can analyse pseudo-product (singleton tuple)" - (|> (&;with-expected-type singletonT - (analyse (` [(~ singletonC)]))) - (macro;run (init-compiler [])) - (case> (#R;Success singletonA) - true + _ + false))) + (test "Can analyse pseudo-product (singleton tuple)" + (|> (&;with-expected-type singletonT + (analyse (` [(~ singletonC)]))) + (macro;run (init-compiler [])) + (case> (#R;Success singletonA) + true - (#R;Error error) - false))) - (assert "Can analyse product through bound type-vars." - (|> (&;with-scope - (@common;with-var - (function [[var-id varT]] - (do Monad<Lux> - [_ (&;within-type-env - (TC;check varT (type;tuple (L/map product;left primitives))))] - (&;with-expected-type varT - (@;analyse-product analyse (L/map product;right primitives))))))) - (macro;run (init-compiler [])) - (case> (#R;Success [_ tupleA]) - (n.= size (list;size (flatten-tuple tupleA))) + (#R;Error error) + false))) + (test "Can analyse product through bound type-vars." + (|> (&;with-scope + (@common;with-var + (function [[var-id varT]] + (do Monad<Lux> + [_ (&;within-type-env + (TC;check varT (type;tuple (L/map product;left primitives))))] + (&;with-expected-type varT + (@;analyse-product analyse (L/map product;right primitives))))))) + (macro;run (init-compiler [])) + (case> (#R;Success [_ tupleA]) + (n.= size (list;size (flatten-tuple tupleA))) - _ - false))) - (assert "Can analyse product through existential quantification." - (|> (&;with-scope - (&;with-expected-type (type;ex-q +1 +tupleT) - (@;analyse-product analyse (L/map product;right +primitives)))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - true + _ + false))) + (test "Can analyse product through existential quantification." + (|> (&;with-scope + (&;with-expected-type (type;ex-q +1 +tupleT) + (@;analyse-product analyse (L/map product;right +primitives)))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + true - (#R;Error error) - false))) - (assert "Cannot analyse product through universal quantification." - (|> (&;with-scope - (&;with-expected-type (type;univ-q +1 +tupleT) - (@;analyse-product analyse (L/map product;right +primitives)))) - (macro;run (init-compiler [])) - (case> (#R;Success _) - false + (#R;Error error) + false))) + (test "Cannot analyse product through universal quantification." + (|> (&;with-scope + (&;with-expected-type (type;univ-q +1 +tupleT) + (@;analyse-product analyse (L/map product;right +primitives)))) + (macro;run (init-compiler [])) + (case> (#R;Success _) + false - (#R;Error error) - true))) + (#R;Error error) + true))) )) (def: (check-variant-inference variantT choice size analysis) @@ -239,7 +239,7 @@ _ false))) -(test: "Tagged Sums" +(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))) @@ -261,49 +261,49 @@ choice-tag (assume (list;nth choice tags)) other-choice-tag (assume (list;nth other-choice tags))]] ($_ seq - (assert "Can infer tagged sum." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@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))) - (assert "Tagged sums specialize when type-vars get bound." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@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))) - (assert "Tagged sum inference retains universal quantification when type-vars are not bound." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@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))) - (assert "Can specialize generic tagged sums." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (&;with-expected-type variantT - (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) - (macro;run (init-compiler [])) - (case> (^multi (#R;Success [_ _ sumA]) - [(flatten-variant sumA) - (#;Some [tag last? valueA])]) - (and (n.= tag other-choice) - (B/= last? (n.= (n.dec size) other-choice))) + (test "Can infer tagged sum." + (|> (@module;with-module +0 module-name + (do Monad<Lux> + [_ (@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 Monad<Lux> + [_ (@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 Monad<Lux> + [_ (@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 Monad<Lux> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (&;with-expected-type variantT + (@;analyse-tagged-sum analyse [module-name other-choice-tag] other-choiceC))))) + (macro;run (init-compiler [])) + (case> (^multi (#R;Success [_ _ sumA]) + [(flatten-variant sumA) + (#;Some [tag last? valueA])]) + (and (n.= tag other-choice) + (B/= last? (n.= (n.dec size) other-choice))) - _ - false))) + _ + false))) )) -(test: "Records" +(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) @@ -323,35 +323,35 @@ (type;univ-q +1)) named-polyT (#;Named [module-name type-name] polyT)]] ($_ seq - (assert "Can infer record." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@module;declare-tags tags false namedT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-record analyse recordC))))) - (check-record-inference tupleT size))) - (assert "Records specialize when type-vars get bound." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (@common;with-unknown-type - (@;analyse-record analyse recordC))))) - (check-record-inference tupleT size))) - (assert "Can specialize generic records." - (|> (@module;with-module +0 module-name - (do Monad<Lux> - [_ (@module;declare-tags tags false named-polyT)] - (&;with-scope - (&;with-expected-type tupleT - (@;analyse-record analyse recordC))))) - (macro;run (init-compiler [])) - (case> (^multi (#R;Success [_ _ productA]) - [(flatten-tuple productA) - membersA]) - (n.= size (list;size membersA)) + (test "Can infer record." + (|> (@module;with-module +0 module-name + (do Monad<Lux> + [_ (@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 Monad<Lux> + [_ (@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 Monad<Lux> + [_ (@module;declare-tags tags false named-polyT)] + (&;with-scope + (&;with-expected-type tupleT + (@;analyse-record analyse recordC))))) + (macro;run (init-compiler [])) + (case> (^multi (#R;Success [_ _ productA]) + [(flatten-tuple productA) + membersA]) + (n.= size (list;size membersA)) - _ - false))) + _ + false))) )) diff --git a/new-luxc/test/test/luxc/common.lux b/new-luxc/test/test/luxc/common.lux index 6892274e4..161675075 100644 --- a/new-luxc/test/test/luxc/common.lux +++ b/new-luxc/test/test/luxc/common.lux @@ -11,7 +11,8 @@ (def: init-compiler-info Compiler-Info - {#;compiler-version &;compiler-version + {#;compiler-name "Lux/JVM" + #;compiler-version &;compiler-version #;compiler-mode #;Build}) (def: init-type-context diff --git a/new-luxc/test/test/luxc/generator/primitive.lux b/new-luxc/test/test/luxc/generator/primitive.lux index a64712e86..53b455812 100644 --- a/new-luxc/test/test/luxc/generator/primitive.lux +++ b/new-luxc/test/test/luxc/generator/primitive.lux @@ -19,7 +19,7 @@ ["@;" common])) (test/luxc common)) -(test: "Primitives." +(context: "Primitives." [%bool% r;bool %nat% r;nat %int% r;int @@ -29,14 +29,14 @@ %text% (r;text +5)] (with-expansions [<tests> (do-template [<desc> <type> <synthesis> <sample> <test>] - [(assert (format "Can generate " <desc> ".") - (|> (@eval;eval (@;generate (<synthesis> <sample>))) - (macro;run (init-compiler [])) - (case> (#R;Success valueG) - (<test> <sample> (:! <type> valueG)) + [(test (format "Can generate " <desc> ".") + (|> (@eval;eval (@;generate (<synthesis> <sample>))) + (macro;run (init-compiler [])) + (case> (#R;Success valueG) + (<test> <sample> (:! <type> valueG)) - _ - false)))] + _ + false)))] ["bool" Bool #ls;Bool %bool% B/=] ["nat" Nat #ls;Nat %nat% n.=] @@ -46,13 +46,13 @@ ["char" Char #ls;Char %char% C/=] ["text" Text #ls;Text %text% T/=])] ($_ seq - (assert "Can generate unit." - (|> (@eval;eval (@;generate #ls;Unit)) - (macro;run (init-compiler [])) - (case> (#R;Success valueG) - (is @common;unit (:! Text valueG)) + (test "Can generate unit." + (|> (@eval;eval (@;generate #ls;Unit)) + (macro;run (init-compiler [])) + (case> (#R;Success valueG) + (is @common;unit (:! Text valueG)) - _ - false))) + _ + false))) <tests> ))) diff --git a/new-luxc/test/test/luxc/generator/structure.lux b/new-luxc/test/test/luxc/generator/structure.lux index ddf4f0afc..817052eff 100644 --- a/new-luxc/test/test/luxc/generator/structure.lux +++ b/new-luxc/test/test/luxc/generator/structure.lux @@ -62,44 +62,44 @@ false )) -(test: "Tuples." +(context: "Tuples." [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) members (r;list size gen-primitive)] - (assert "Can generate tuple." - (|> (@eval;eval (@;generate (#ls;Tuple members))) - (macro;run (init-compiler [])) - (case> (#R;Success valueG) - (let [valueG (:! (a;Array Top) valueG)] - (and (n.= size (a;size valueG)) - (list;every? corresponds? (list;zip2 members (a;to-list valueG))))) + (test "Can generate tuple." + (|> (@eval;eval (@;generate (#ls;Tuple members))) + (macro;run (init-compiler [])) + (case> (#R;Success valueG) + (let [valueG (:! (a;Array Top) valueG)] + (and (n.= size (a;size valueG)) + (list;every? corresponds? (list;zip2 members (a;to-list valueG))))) - _ - false)))) + _ + false)))) -(test: "Variants." +(context: "Variants." [num-tags (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) tag (|> r;nat (:: @ map (n.% num-tags))) #let [last? (n.= (n.dec num-tags) tag)] member gen-primitive] - (assert "Can generate variant." - (|> (do Monad<Lux> - [runtime-bytecode @runtime;generate] - (@eval;eval (@;generate (#ls;Variant tag last? member)))) - (macro;run (init-compiler [])) - (case> (#R;Success valueG) - (let [valueG (:! (a;Array Top) valueG)] - (and (n.= +3 (a;size valueG)) - (let [_tag (:! Integer (assume (a;get +0 valueG))) - _last? (a;get +1 valueG) - _value (:! Top (assume (a;get +2 valueG)))] - (and (n.= tag (|> _tag host;i2l int-to-nat)) - (case _last? - (#;Some _last?') - (and last? (T/= "" (:! Text _last?'))) + (test "Can generate variant." + (|> (do Monad<Lux> + [runtime-bytecode @runtime;generate] + (@eval;eval (@;generate (#ls;Variant tag last? member)))) + (macro;run (init-compiler [])) + (case> (#R;Success valueG) + (let [valueG (:! (a;Array Top) valueG)] + (and (n.= +3 (a;size valueG)) + (let [_tag (:! Integer (assume (a;get +0 valueG))) + _last? (a;get +1 valueG) + _value (:! Top (assume (a;get +2 valueG)))] + (and (n.= tag (|> _tag host;i2l int-to-nat)) + (case _last? + (#;Some _last?') + (and last? (T/= "" (:! Text _last?'))) - #;None - (not last?)) - (corresponds? [member _value]))))) + #;None + (not last?)) + (corresponds? [member _value]))))) - _ - false)))) + _ + false)))) diff --git a/new-luxc/test/test/luxc/parser.lux b/new-luxc/test/test/luxc/parser.lux index 33b6eba36..21d34f7c0 100644 --- a/new-luxc/test/test/luxc/parser.lux +++ b/new-luxc/test/test/luxc/parser.lux @@ -75,16 +75,17 @@ (r;either simple^ composite^)))))) -(test: "Lux code parser." +(context: "Lux code parser." + #seed +15765541630132670628 [sample code^] - (assert "Can parse Lux code." - (case (&;parse [default-cursor (code;to-text sample)]) - (#R;Error error) - false + (test "Can parse Lux code." + (case (&;parse [default-cursor (code;to-text sample)]) + (#R;Error error) + false - (#R;Success [_ parsed]) - (:: code;Eq<Code> = parsed sample)) - )) + (#R;Success [_ parsed]) + (:: code;Eq<Code> = parsed sample)) + )) (def: comment-text^ (r;Random Text) @@ -109,7 +110,8 @@ nested^)] (wrap (format "#( " comment " )#"))))))) -(test: "Multi-line text & comments." +(context: "Multi-line text & comments." + #seed +13835085537605735783 [#let [char-gen (|> r;char (r;filter (function [value] (not (or (char;space? value) (C/= #"\"" value) @@ -123,57 +125,57 @@ comment comment^ unbalanced-comment comment-text^] ($_ seq - (assert "Will reject invalid multi-line text." - (let [bad-match (format (char;as-text x) "\n" + (test "Will reject invalid multi-line text." + (let [bad-match (format (char;as-text x) "\n" + (char;as-text y) "\n" + (char;as-text z))] + (case (&;parse [default-cursor + (format "\"" bad-match "\"")]) + (#R;Error error) + true + + (#R;Success [_ parsed]) + false))) + (test "Will accept valid multi-line text" + (let [good-input (format (char;as-text x) "\n" + offset (char;as-text y) "\n" + offset (char;as-text z)) + good-output (format (char;as-text x) "\n" (char;as-text y) "\n" (char;as-text z))] - (case (&;parse [default-cursor - (format "\"" bad-match "\"")]) - (#R;Error error) - true - - (#R;Success [_ parsed]) - false))) - (assert "Will accept valid multi-line text" - (let [good-input (format (char;as-text x) "\n" - offset (char;as-text y) "\n" - offset (char;as-text z)) - good-output (format (char;as-text x) "\n" - (char;as-text y) "\n" - (char;as-text z))] - (case (&;parse [(|> default-cursor - (update@ #;column (n.+ (n.dec offset-size)))) - (format "\"" good-input "\"")]) - (#R;Error error) - false - - (#R;Success [_ parsed]) - (:: code;Eq<Code> = - parsed - (code;text good-output))))) - (assert "Can handle comments." - (case (&;parse [default-cursor - (format comment (code;to-text sample))]) + (case (&;parse [(|> default-cursor + (update@ #;column (n.+ (n.dec offset-size)))) + (format "\"" good-input "\"")]) (#R;Error error) false (#R;Success [_ parsed]) - (:: code;Eq<Code> = parsed sample))) - (assert "Will reject unbalanced multi-line comments." - (and (case (&;parse [default-cursor - (format "#(" "#(" unbalanced-comment ")#" - (code;to-text sample))]) - (#R;Error error) - true + (:: code;Eq<Code> = + parsed + (code;text good-output))))) + (test "Can handle comments." + (case (&;parse [default-cursor + (format comment (code;to-text sample))]) + (#R;Error error) + false + + (#R;Success [_ parsed]) + (:: code;Eq<Code> = parsed sample))) + (test "Will reject unbalanced multi-line comments." + (and (case (&;parse [default-cursor + (format "#(" "#(" unbalanced-comment ")#" + (code;to-text sample))]) + (#R;Error error) + true - (#R;Success [_ parsed]) - false) - (case (&;parse [default-cursor - (format "#(" unbalanced-comment ")#" ")#" - (code;to-text sample))]) - (#R;Error error) - true + (#R;Success [_ parsed]) + false) + (case (&;parse [default-cursor + (format "#(" unbalanced-comment ")#" ")#" + (code;to-text sample))]) + (#R;Error error) + true - (#R;Success [_ parsed]) - false))) + (#R;Success [_ parsed]) + false))) )) diff --git a/new-luxc/test/test/luxc/synthesizer/function.lux b/new-luxc/test/test/luxc/synthesizer/function.lux index 6ad7ed634..acc39ce16 100644 --- a/new-luxc/test/test/luxc/synthesizer/function.lux +++ b/new-luxc/test/test/luxc/synthesizer/function.lux @@ -104,52 +104,52 @@ (|> chosen (n.+ (n.dec num-args)) nat-to-int) (#la;Relative (#;Local chosen))]))))) -(test: "Function definition." +(context: "Function definition." [[args1 prediction1 function1] gen-function//constant [args2 prediction2 function2] gen-function//captured [args3 prediction3 function3] gen-function//local] ($_ seq - (assert "Nested functions will get folded together." - (|> (synthesizer;synthesize function1) - (case> (#ls;Function args captured output) - (and (n.= args1 args) - (corresponds? prediction1 output)) - - _ - (n.= +0 args1)))) - (assert "Folded functions provide direct access to captured variables." - (|> (synthesizer;synthesize function2) - (case> (#ls;Function args captured (#ls;Variable output)) - (and (n.= args2 args) - (i.= prediction2 output)) - - _ - false))) - (assert "Folded functions properly offset local variables." - (|> (synthesizer;synthesize function3) - (case> (#ls;Function args captured (#ls;Variable output)) - (and (n.= args3 args) - (i.= prediction3 output)) - - _ - false))) + (test "Nested functions will get folded together." + (|> (synthesizer;synthesize function1) + (case> (#ls;Function args captured output) + (and (n.= args1 args) + (corresponds? prediction1 output)) + + _ + (n.= +0 args1)))) + (test "Folded functions provide direct access to captured variables." + (|> (synthesizer;synthesize function2) + (case> (#ls;Function args captured (#ls;Variable output)) + (and (n.= args2 args) + (i.= prediction2 output)) + + _ + false))) + (test "Folded functions properly offset local variables." + (|> (synthesizer;synthesize function3) + (case> (#ls;Function args captured (#ls;Variable output)) + (and (n.= args3 args) + (i.= prediction3 output)) + + _ + false))) )) -(test: "Function application." +(context: "Function application." [num-args (|> r;nat (:: @ map (|>. (n.% +10) (n.max +1)))) funcA gen-primitive argsA (r;list num-args gen-primitive)] ($_ seq - (assert "Can synthesize function application." - (|> (synthesizer;synthesize (la;apply argsA funcA)) - (case> (#ls;Call funcS argsS) - (and (corresponds? funcA funcS) - (list;every? (product;uncurry corresponds?) - (list;zip2 argsA argsS))) - - _ - false))) - (assert "Function application on no arguments just synthesizes to the function itself." - (|> (synthesizer;synthesize (la;apply (list) funcA)) - (corresponds? funcA))) + (test "Can synthesize function application." + (|> (synthesizer;synthesize (la;apply argsA funcA)) + (case> (#ls;Call funcS argsS) + (and (corresponds? funcA funcS) + (list;every? (product;uncurry corresponds?) + (list;zip2 argsA argsS))) + + _ + false))) + (test "Function application on no arguments just synthesizes to the function itself." + (|> (synthesizer;synthesize (la;apply (list) funcA)) + (corresponds? funcA))) )) diff --git a/new-luxc/test/test/luxc/synthesizer/loop.lux b/new-luxc/test/test/luxc/synthesizer/loop.lux index 07f2b8a13..abc06dbb8 100644 --- a/new-luxc/test/test/luxc/synthesizer/loop.lux +++ b/new-luxc/test/test/luxc/synthesizer/loop.lux @@ -134,31 +134,31 @@ arity (make-function arity bodyS)]))) -(test: "Recursion." +(context: "Recursion." [[prediction arity analysis] gen-recursion] ($_ seq - (assert "Can accurately identify (and then reify) tail recursion." - (case (synthesizer;synthesize analysis) - (#ls;Function _arity _env _body) - (|> _body - (does-recursion? arity) - (B/= prediction) - (and (n.= arity _arity))) - - _ - false)))) - -(test: "Loop." + (test "Can accurately identify (and then reify) tail recursion." + (case (synthesizer;synthesize analysis) + (#ls;Function _arity _env _body) + (|> _body + (does-recursion? arity) + (B/= prediction) + (and (n.= arity _arity))) + + _ + false)))) + +(context: "Loop." [[prediction arity analysis] gen-recursion] ($_ seq - (assert "Can reify loops." - (case (synthesizer;synthesize (make-apply analysis (list;repeat arity #la;Unit))) - (#ls;Loop _register _inits _body) - (and (n.= arity (list;size _inits)) - (not (&&loop;contains-self-reference? _body))) + (test "Can reify loops." + (case (synthesizer;synthesize (make-apply analysis (list;repeat arity #la;Unit))) + (#ls;Loop _register _inits _body) + (and (n.= arity (list;size _inits)) + (not (&&loop;contains-self-reference? _body))) - (#ls;Call (#ls;Function _arity _env _bodyS) argsS) - (&&loop;contains-self-reference? _bodyS) + (#ls;Call (#ls;Function _arity _env _bodyS) argsS) + (&&loop;contains-self-reference? _bodyS) - _ - false)))) + _ + false)))) diff --git a/new-luxc/test/test/luxc/synthesizer/primitive.lux b/new-luxc/test/test/luxc/synthesizer/primitive.lux index 4c67fa0a4..c17d41a78 100644 --- a/new-luxc/test/test/luxc/synthesizer/primitive.lux +++ b/new-luxc/test/test/luxc/synthesizer/primitive.lux @@ -11,7 +11,7 @@ [analyser] [synthesizer])) -(test: "Primitives" +(context: "Primitives" [%bool% r;bool %nat% r;nat %int% r;int @@ -21,13 +21,13 @@ %text% (r;text +5)] (with-expansions [<tests> (do-template [<desc> <analysis> <synthesis> <sample>] - [(assert (format "Can synthesize " <desc> ".") - (|> (synthesizer;synthesize (<analysis> <sample>)) - (case> (<synthesis> value) - (is <sample> value) + [(test (format "Can synthesize " <desc> ".") + (|> (synthesizer;synthesize (<analysis> <sample>)) + (case> (<synthesis> value) + (is <sample> value) - _ - false)))] + _ + false)))] ["unit" #la;Unit #ls;Unit []] ["bool" #la;Bool #ls;Bool %bool%] diff --git a/new-luxc/test/test/luxc/synthesizer/procedure.lux b/new-luxc/test/test/luxc/synthesizer/procedure.lux index 898987308..91369a59b 100644 --- a/new-luxc/test/test/luxc/synthesizer/procedure.lux +++ b/new-luxc/test/test/luxc/synthesizer/procedure.lux @@ -15,18 +15,18 @@ [synthesizer]) (.. common)) -(test: "Procedures" +(context: "Procedures" [num-args (|> r;nat (:: @ map (n.% +10))) nameA (r;text +5) argsA (r;list num-args gen-primitive)] ($_ seq - (assert "Can synthesize procedure calls." - (|> (synthesizer;synthesize (#la;Procedure nameA argsA)) - (case> (#ls;Procedure nameS argsS) - (and (T/= nameA nameS) - (list;every? (product;uncurry corresponds?) - (list;zip2 argsA argsS))) - - _ - false))) + (test "Can synthesize procedure calls." + (|> (synthesizer;synthesize (#la;Procedure nameA argsA)) + (case> (#ls;Procedure nameS argsS) + (and (T/= nameA nameS) + (list;every? (product;uncurry corresponds?) + (list;zip2 argsA argsS))) + + _ + false))) )) diff --git a/new-luxc/test/test/luxc/synthesizer/structure.lux b/new-luxc/test/test/luxc/synthesizer/structure.lux index 3f90bf321..eba24213e 100644 --- a/new-luxc/test/test/luxc/synthesizer/structure.lux +++ b/new-luxc/test/test/luxc/synthesizer/structure.lux @@ -13,33 +13,33 @@ [synthesizer]) (.. common)) -(test: "Variants" +(context: "Variants" [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) tagA (|> r;nat (:: @ map (n.% size))) memberA gen-primitive] ($_ seq - (assert "Can synthesize variants." - (|> (synthesizer;synthesize (la;sum tagA size +0 memberA)) - (case> (#ls;Variant tagS last?S memberS) - (and (n.= tagA tagS) - (B/= (n.= (n.dec size) tagA) - last?S) - (corresponds? memberA memberS)) - - _ - false))) + (test "Can synthesize variants." + (|> (synthesizer;synthesize (la;sum tagA size +0 memberA)) + (case> (#ls;Variant tagS last?S memberS) + (and (n.= tagA tagS) + (B/= (n.= (n.dec size) tagA) + last?S) + (corresponds? memberA memberS)) + + _ + false))) )) -(test: "Tuples" +(context: "Tuples" [size (|> r;nat (:: @ map (|>. (n.% +10) (n.max +2)))) membersA (r;list size gen-primitive)] ($_ seq - (assert "Can synthesize tuple." - (|> (synthesizer;synthesize (la;product membersA)) - (case> (#ls;Tuple membersS) - (and (n.= size (list;size membersS)) - (list;every? (product;uncurry corresponds?) (list;zip2 membersA membersS))) + (test "Can synthesize tuple." + (|> (synthesizer;synthesize (la;product membersA)) + (case> (#ls;Tuple membersS) + (and (n.= size (list;size membersS)) + (list;every? (product;uncurry corresponds?) (list;zip2 membersA membersS))) - _ - false))) + _ + false))) )) |