aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/test/test/luxc/analyser
diff options
context:
space:
mode:
Diffstat (limited to 'new-luxc/test/test/luxc/analyser')
-rw-r--r--new-luxc/test/test/luxc/analyser/case.lux64
-rw-r--r--new-luxc/test/test/luxc/analyser/function.lux118
-rw-r--r--new-luxc/test/test/luxc/analyser/primitive.lux22
-rw-r--r--new-luxc/test/test/luxc/analyser/procedure/common.lux510
-rw-r--r--new-luxc/test/test/luxc/analyser/reference.lux46
-rw-r--r--new-luxc/test/test/luxc/analyser/structure.lux378
6 files changed, 569 insertions, 569 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)))
))