mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-31 00:57:24 +00:00
Migrate even more tests
This commit is contained in:
parent
7c14b78e5d
commit
721d3836cd
50 changed files with 559 additions and 900 deletions
|
@ -5209,904 +5209,4 @@ mod solve_expr {
|
|||
r#"{ bi128 : I128 -> I128, bi16 : I16 -> I16, bi32 : I32 -> I32, bi64 : I64 -> I64, bi8 : I8 -> I8, bnat : Nat -> Nat, bu128 : U128 -> U128, bu16 : U16 -> U16, bu32 : U32 -> U32, bu64 : U64 -> U64, bu8 : U8 -> U8, dec : Dec -> Dec, f32 : F32 -> F32, f64 : F64 -> F64, fdec : Dec -> Dec, ff32 : F32 -> F32, ff64 : F64 -> F64, i128 : I128 -> I128, i16 : I16 -> I16, i32 : I32 -> I32, i64 : I64 -> I64, i8 : I8 -> I8, nat : Nat -> Nat, u128 : U128 -> U128, u16 : U16 -> U16, u32 : U32 -> U32, u64 : U64 -> U64, u8 : U8 -> U8 }"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2458() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Foo a : [Blah (Result (Bar a) { val: a })]
|
||||
Bar a : Foo a
|
||||
|
||||
v : Bar U8
|
||||
v = Blah (Ok (Blah (Err { val: 1 })))
|
||||
|
||||
v
|
||||
"#
|
||||
),
|
||||
"Bar U8",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2458_swapped_order() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Bar a : Foo a
|
||||
Foo a : [Blah (Result (Bar a) { val: a })]
|
||||
|
||||
v : Bar U8
|
||||
v = Blah (Ok (Blah (Err { val: 1 })))
|
||||
|
||||
v
|
||||
"#
|
||||
),
|
||||
"Bar U8",
|
||||
)
|
||||
}
|
||||
|
||||
// https://github.com/roc-lang/roc/issues/2379
|
||||
#[test]
|
||||
fn copy_vars_referencing_copied_vars() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Job : [Job [Command] (List Job)]
|
||||
|
||||
job : Job
|
||||
|
||||
job
|
||||
"#
|
||||
),
|
||||
"Job",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generalize_and_specialize_recursion_var() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Job a : [Job (List (Job a)) a]
|
||||
|
||||
job : Job Str
|
||||
|
||||
when job is
|
||||
Job lst s -> P lst s
|
||||
"#
|
||||
),
|
||||
"[P (List ([Job (List a) Str] as a)) Str]",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_int() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
{
|
||||
toI8: Num.toI8,
|
||||
toI16: Num.toI16,
|
||||
toI32: Num.toI32,
|
||||
toI64: Num.toI64,
|
||||
toI128: Num.toI128,
|
||||
toNat: Num.toNat,
|
||||
toU8: Num.toU8,
|
||||
toU16: Num.toU16,
|
||||
toU32: Num.toU32,
|
||||
toU64: Num.toU64,
|
||||
toU128: Num.toU128,
|
||||
}
|
||||
"#
|
||||
),
|
||||
r#"{ toI128 : Int * -> I128, toI16 : Int a -> I16, toI32 : Int b -> I32, toI64 : Int c -> I64, toI8 : Int d -> I8, toNat : Int e -> Nat, toU128 : Int f -> U128, toU16 : Int g -> U16, toU32 : Int h -> U32, toU64 : Int i -> U64, toU8 : Int j -> U8 }"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_float() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
{
|
||||
toF32: Num.toF32,
|
||||
toF64: Num.toF64,
|
||||
}
|
||||
"#
|
||||
),
|
||||
r#"{ toF32 : Num * -> F32, toF64 : Num a -> F64 }"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Age := U32
|
||||
|
||||
@Age 21
|
||||
"#
|
||||
),
|
||||
r#"Age"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Age := U32
|
||||
|
||||
a : Age
|
||||
a = @Age 21
|
||||
|
||||
a
|
||||
"#
|
||||
),
|
||||
r#"Age"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_polymorphic_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
@Id (Id 21 "sasha")
|
||||
"#
|
||||
),
|
||||
r#"Id Str"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_polymorphic_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
a : Id Str
|
||||
a = @Id (Id 21 "sasha")
|
||||
|
||||
a
|
||||
"#
|
||||
),
|
||||
r#"Id Str"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_polymorphic_from_multiple_branches_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
condition : Bool
|
||||
|
||||
if condition
|
||||
then @Id (Id 21 (Y "sasha"))
|
||||
else @Id (Id 21 (Z "felix"))
|
||||
"#
|
||||
),
|
||||
r#"Id [Y Str, Z Str]"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_wrap_polymorphic_from_multiple_branches_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
condition : Bool
|
||||
|
||||
v : Id [Y Str, Z Str]
|
||||
v =
|
||||
if condition
|
||||
then @Id (Id 21 (Y "sasha"))
|
||||
else @Id (Id 21 (Z "felix"))
|
||||
|
||||
v
|
||||
"#
|
||||
),
|
||||
r#"Id [Y Str, Z Str]"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Age := U32
|
||||
|
||||
\@Age n -> n
|
||||
"#
|
||||
),
|
||||
r#"Age -> U32"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Age := U32
|
||||
|
||||
v : Age -> U32
|
||||
v = \@Age n -> n
|
||||
v
|
||||
"#
|
||||
),
|
||||
r#"Age -> U32"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
\@Id (Id _ n) -> n
|
||||
"#
|
||||
),
|
||||
r#"Id a -> a"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
v : Id a -> a
|
||||
v = \@Id (Id _ n) -> n
|
||||
|
||||
v
|
||||
"#
|
||||
),
|
||||
r#"Id a -> a"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_specialized_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
strToBool : Str -> Bool
|
||||
|
||||
\@Id (Id _ n) -> strToBool n
|
||||
"#
|
||||
),
|
||||
r#"Id Str -> Bool"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_specialized_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
strToBool : Str -> Bool
|
||||
|
||||
v : Id Str -> Bool
|
||||
v = \@Id (Id _ n) -> strToBool n
|
||||
|
||||
v
|
||||
"#
|
||||
),
|
||||
r#"Id Str -> Bool"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_from_multiple_branches_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
\id ->
|
||||
when id is
|
||||
@Id (Id _ A) -> ""
|
||||
@Id (Id _ B) -> ""
|
||||
@Id (Id _ (C { a: "" })) -> ""
|
||||
@Id (Id _ (C { a: _ })) -> "" # any other string, for exhautiveness
|
||||
"#
|
||||
),
|
||||
r#"Id [A, B, C { a : Str }*] -> Str"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_unwrap_polymorphic_from_multiple_branches_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Id n := [Id U32 n]
|
||||
|
||||
f : Id [A, B, C { a : Str }e] -> Str
|
||||
f = \id ->
|
||||
when id is
|
||||
@Id (Id _ A) -> ""
|
||||
@Id (Id _ B) -> ""
|
||||
@Id (Id _ (C { a: "" })) -> ""
|
||||
@Id (Id _ (C { a: _ })) -> "" # any other string, for exhautiveness
|
||||
|
||||
f
|
||||
"#
|
||||
),
|
||||
r#"Id [A, B, C { a : Str }e] -> Str"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lambda_set_within_alias_is_quantified() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [effectAlways] to "./platform"
|
||||
|
||||
Effect a := {} -> a
|
||||
|
||||
effectAlways : a -> Effect a
|
||||
effectAlways = \x ->
|
||||
inner = \{} -> x
|
||||
|
||||
@Effect inner
|
||||
"#
|
||||
),
|
||||
r#"a -> Effect a"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn generalized_accessor_function_applied() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
returnFoo = .foo
|
||||
|
||||
returnFoo { foo: "foo" }
|
||||
"#
|
||||
),
|
||||
"Str",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_extension_variable_is_alias() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Other a b : { y: a, z: b }
|
||||
|
||||
f : { x : Str }(Other Str Str)
|
||||
f
|
||||
"#
|
||||
),
|
||||
r#"{ x : Str, y : Str, z : Str }"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_extension_variable_is_alias() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Other : [B, C]
|
||||
|
||||
f : [A]Other
|
||||
f
|
||||
"#
|
||||
),
|
||||
r#"[A, B, C]"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
// https://github.com/roc-lang/roc/issues/2702
|
||||
fn tag_inclusion_behind_opaque() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Outer k := [Empty, Wrapped k]
|
||||
|
||||
insert : Outer k, k -> Outer k
|
||||
insert = \m, var ->
|
||||
when m is
|
||||
@Outer Empty -> @Outer (Wrapped var)
|
||||
@Outer (Wrapped _) -> @Outer (Wrapped var)
|
||||
|
||||
insert
|
||||
"#
|
||||
),
|
||||
r#"Outer k, k -> Outer k"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_inclusion_behind_opaque_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Outer k := [Empty, Wrapped k]
|
||||
|
||||
when (@Outer Empty) is
|
||||
@Outer Empty -> @Outer (Wrapped "")
|
||||
@Outer (Wrapped k) -> @Outer (Wrapped k)
|
||||
"#
|
||||
),
|
||||
r#"Outer Str"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_inclusion_behind_opaque_infer_single_ctor() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
Outer := [A, B]
|
||||
|
||||
when (@Outer A) is
|
||||
@Outer A -> @Outer A
|
||||
@Outer B -> @Outer B
|
||||
"#
|
||||
),
|
||||
r#"Outer"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2583_specialize_errors_behind_unified_branches() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
if Bool.true then List.first [] else Str.toI64 ""
|
||||
"#
|
||||
),
|
||||
"Result I64 [InvalidNumStr, ListWasEmpty]",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lots_of_type_variables() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
fun = \a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb -> {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb}
|
||||
fun
|
||||
"#
|
||||
),
|
||||
"a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, aa, bb -> { a : a, aa : aa, b : b, bb : bb, c : c, d : d, e : e, f : f, g : g, h : h, i : i, j : j, k : k, l : l, m : m, n : n, o : o, p : p, q : q, r : r, s : s, t : t, u : u, v : v, w : w, x : x, y : y, z : z }",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exposed_ability_name() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash] to "./platform"
|
||||
|
||||
MHash has hash : a -> U64 | a has MHash
|
||||
"#
|
||||
),
|
||||
"a -> U64 | a has MHash",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_ability_single_member_specializations() {
|
||||
check_inferred_abilities(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash] to "./platform"
|
||||
|
||||
MHash has hash : a -> U64 | a has MHash
|
||||
|
||||
Id := U64 has [MHash {hash}]
|
||||
|
||||
hash = \@Id n -> n
|
||||
"#
|
||||
),
|
||||
[("MHash:hash", "Id")],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_ability_multiple_members_specializations() {
|
||||
check_inferred_abilities(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash, hash32] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
hash32 : a -> U32 | a has MHash
|
||||
|
||||
Id := U64 has [MHash {hash, hash32}]
|
||||
|
||||
hash = \@Id n -> n
|
||||
hash32 = \@Id n -> Num.toU32 n
|
||||
"#
|
||||
),
|
||||
[("MHash:hash", "Id"), ("MHash:hash32", "Id")],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_abilities_multiple_members_specializations() {
|
||||
check_inferred_abilities(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash, hash32, eq, le] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
hash32 : a -> U32 | a has MHash
|
||||
|
||||
Ord has
|
||||
eq : a, a -> Bool | a has Ord
|
||||
le : a, a -> Bool | a has Ord
|
||||
|
||||
Id := U64 has [MHash {hash, hash32}, Ord {eq, le}]
|
||||
|
||||
hash = \@Id n -> n
|
||||
hash32 = \@Id n -> Num.toU32 n
|
||||
|
||||
eq = \@Id m, @Id n -> m == n
|
||||
le = \@Id m, @Id n -> m < n
|
||||
"#
|
||||
),
|
||||
[
|
||||
("MHash:hash", "Id"),
|
||||
("MHash:hash32", "Id"),
|
||||
("Ord:eq", "Id"),
|
||||
("Ord:le", "Id"),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_checked_specialization_with_typed_body() {
|
||||
check_inferred_abilities(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
Id := U64 has [MHash {hash}]
|
||||
|
||||
hash : Id -> U64
|
||||
hash = \@Id n -> n
|
||||
"#
|
||||
),
|
||||
[("MHash:hash", "Id")],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_checked_specialization_with_annotation_only() {
|
||||
check_inferred_abilities(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hash] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
Id := U64 has [MHash {hash}]
|
||||
|
||||
hash : Id -> U64
|
||||
"#
|
||||
),
|
||||
[("MHash:hash", "Id")],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_specialization_called() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [zero] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
Id := U64 has [MHash {hash}]
|
||||
|
||||
hash = \@Id n -> n
|
||||
|
||||
zero = hash (@Id 0)
|
||||
"#
|
||||
),
|
||||
"U64",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_ability_member() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [thething] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
thething =
|
||||
itis = hash
|
||||
itis
|
||||
"#
|
||||
),
|
||||
"a -> U64 | a has MHash",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn when_branch_and_body_flipflop() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
func = \record ->
|
||||
when record.tag is
|
||||
A -> { record & tag: B }
|
||||
B -> { record & tag: A }
|
||||
|
||||
func
|
||||
"#
|
||||
),
|
||||
"{ tag : [A, B] }a -> { tag : [A, B] }a",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_constrained_in_non_member_check() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hashEq] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
hashEq : a, a -> Bool | a has MHash
|
||||
hashEq = \x, y -> hash x == hash y
|
||||
"#
|
||||
),
|
||||
"a, a -> Bool | a has MHash",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_constrained_in_non_member_infer() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [hashEq] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
hashEq = \x, y -> hash x == hash y
|
||||
"#
|
||||
),
|
||||
"a, a1 -> Bool | a has MHash, a1 has MHash",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_constrained_in_non_member_infer_usage() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [result] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
hashEq = \x, y -> hash x == hash y
|
||||
|
||||
Id := U64 has [MHash {hash}]
|
||||
hash = \@Id n -> n
|
||||
|
||||
result = hashEq (@Id 100) (@Id 101)
|
||||
"#
|
||||
),
|
||||
"Bool",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ability_constrained_in_non_member_multiple_specializations() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [result] to "./platform"
|
||||
|
||||
MHash has
|
||||
hash : a -> U64 | a has MHash
|
||||
|
||||
mulMHashes = \x, y -> hash x * hash y
|
||||
|
||||
Id := U64 has [MHash { hash: hashId }]
|
||||
hashId = \@Id n -> n
|
||||
|
||||
Three := {} has [MHash { hash: hashThree }]
|
||||
hashThree = \@Three _ -> 3
|
||||
|
||||
result = mulMHashes (@Id 100) (@Three {})
|
||||
"#
|
||||
),
|
||||
"U64",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_open_tag_union() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [go] to "./platform"
|
||||
|
||||
Expr : [
|
||||
Wrap Expr,
|
||||
Val I64,
|
||||
]
|
||||
|
||||
go : Expr -> Expr
|
||||
go = \e ->
|
||||
when P e is
|
||||
P (Wrap (Val _)) -> Wrap e
|
||||
|
||||
# This branch should force the first argument to `P` and
|
||||
# the first argument to `Wrap` to be an open tag union.
|
||||
# This tests checks that we don't regress on that.
|
||||
P y1 -> Wrap y1
|
||||
"#
|
||||
),
|
||||
indoc!(r#"Expr -> Expr"#),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opaque_and_alias_unify() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [always] to "./platform"
|
||||
|
||||
Effect a := {} -> a
|
||||
|
||||
Task a err : Effect (Result a err)
|
||||
|
||||
always : a -> Task a *
|
||||
always = \x -> @Effect (\{} -> Ok x)
|
||||
"#
|
||||
),
|
||||
"a -> Task a *",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn export_rigid_to_lower_rank() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [foo] to "./platform"
|
||||
|
||||
F a : { foo : a }
|
||||
|
||||
foo = \arg ->
|
||||
x : F b
|
||||
x = arg
|
||||
x.foo
|
||||
"#
|
||||
),
|
||||
"F b -> b",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_in_opaque() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [foo] to "./platform"
|
||||
|
||||
MyError : [Error]
|
||||
|
||||
MyResult := Result U8 MyError
|
||||
|
||||
foo = @MyResult (Err Error)
|
||||
"#
|
||||
),
|
||||
"MyResult",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias_propagates_able_var() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [zeroEncoder] to "./platform"
|
||||
|
||||
MEncoder fmt := List U8, fmt -> List U8 | fmt has Format
|
||||
|
||||
Format has it : fmt -> {} | fmt has Format
|
||||
|
||||
zeroEncoder = @MEncoder \lst, _ -> lst
|
||||
"#
|
||||
),
|
||||
"MEncoder a | a has Format",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn task_wildcard_wildcard() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test" provides [tforever] to "./platform"
|
||||
|
||||
Effect a := {} -> a
|
||||
|
||||
eforever : Effect a -> Effect b
|
||||
|
||||
Task a err : Effect (Result a err)
|
||||
|
||||
tforever : Task val err -> Task * *
|
||||
tforever = \task -> eforever task
|
||||
"#
|
||||
),
|
||||
"Task val err -> Task * *",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stdlib_encode_json() {
|
||||
infer_eq_without_problem(
|
||||
indoc!(
|
||||
r#"
|
||||
app "test"
|
||||
imports [Json]
|
||||
provides [main] to "./platform"
|
||||
|
||||
HelloWorld := {} has [Encoding {toEncoder}]
|
||||
|
||||
toEncoder = \@HelloWorld {} ->
|
||||
Encode.custom \bytes, fmt ->
|
||||
bytes
|
||||
|> Encode.appendWith (Encode.string "Hello, World!\n") fmt
|
||||
|
||||
main =
|
||||
when Str.fromUtf8 (Encode.toBytes (@HelloWorld {}) Json.toUtf8) is
|
||||
Ok s -> s
|
||||
_ -> "<bad>"
|
||||
"#
|
||||
),
|
||||
"Str",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue