Migrate even more tests

This commit is contained in:
Ayaz Hafiz 2023-03-31 19:05:10 -05:00
parent 346e3f0dd5
commit 6b3a4b419e
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
21 changed files with 168 additions and 362 deletions

View file

@ -7463,359 +7463,4 @@ mod solve_expr {
"###
);
}
#[test]
fn catchall_branch_for_pattern_not_last() {
infer_queries!(
indoc!(
r#"
\x -> when x is
#^
A B _ -> ""
A _ C -> ""
"#
),
@r#"x : [A [B]w_a [C]w_b]"#
allow_errors: true
);
}
#[test]
fn catchall_branch_walk_into_nested_types() {
infer_queries!(
indoc!(
r#"
\x -> when x is
#^
{ a: A { b: B } } -> ""
_ -> ""
"#
),
@"x : { a : [A { b : [B]w_a }*]w_b }*"
);
}
#[test]
fn infer_type_with_underscore_destructure_assignment() {
infer_eq_without_problem(
indoc!(
r#"
Pair x _ = Pair 0 1
x
"#
),
"Num *",
);
}
#[test]
fn issue_3444() {
infer_queries!(
indoc!(
r#"
compose = \f, g ->
closCompose = \x -> g (f x)
closCompose
const = \x ->
closConst = \_ -> x
closConst
list = []
res : Str -> Str
res = List.walk list (const "z") (\c1, c2 -> compose c1 c2)
# ^^^^^ ^^^^^^^
# ^^^^^^^^^^^^^^^^^^^^^^^^
#^^^{-1}
res "hello"
#^^^{-1}
"#
),
@r###"
const : Str -[[const(2)]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
compose : (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str), (Str -[[]]-> Str) -[[compose(1)]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
\c1, c2 -> compose c1 c2 : (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str), (Str -[[]]-> Str) -[[11]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
res : Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str
res : Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str
"###
);
}
#[test]
fn transient_captures() {
infer_queries!(
indoc!(
r#"
x = "abc"
getX = \{} -> x
h = \{} -> (getX {})
#^{-1}
h {}
"#
),
@"h : {}* -[[h(3) Str]]-> Str"
);
}
#[test]
fn transient_captures_after_def_ordering() {
infer_queries!(
indoc!(
r#"
h = \{} -> (getX {})
#^{-1}
getX = \{} -> x
x = "abc"
h {}
"#
),
@"h : {}* -[[h(1) Str]]-> Str"
);
}
#[test]
fn mutually_recursive_captures() {
infer_queries!(
indoc!(
r#"
x = Bool.true
y = Bool.false
a = "foo"
b = "bar"
foo = \{} -> if x then a else bar {}
#^^^{-1}
bar = \{} -> if y then b else foo {}
#^^^{-1}
bar {}
"#
),
@r###"
foo : {} -[[foo(5) Bool Bool Str Str]]-> Str
bar : {} -[[bar(6) Bool Bool Str Str]]-> Str
"###
);
}
#[test]
fn unify_optional_record_fields_in_two_closed_records() {
infer_eq_without_problem(
indoc!(
r#"
f : { x ? Str, y ? Str } -> {}
f {x : ""}
"#
),
"{}",
);
}
#[test]
fn match_on_result_with_uninhabited_error_branch() {
infer_eq_without_problem(
indoc!(
r#"
x : Result Str []
x = Ok "abc"
when x is
Ok s -> s
"#
),
"Str",
);
}
#[test]
fn match_on_result_with_uninhabited_error_destructuring() {
infer_eq_without_problem(
indoc!(
r#"
x : Result Str []
x = Ok "abc"
Ok str = x
str
"#
),
"Str",
);
}
#[test]
fn match_on_result_with_uninhabited_error_destructuring_in_lambda_syntax() {
infer_eq_without_problem(
indoc!(
r#"
x : Result Str [] -> Str
x = \Ok s -> s
x
"#
),
"Result Str [] -> Str",
);
}
#[test]
fn custom_implement_hash() {
infer_eq_without_problem(
indoc!(
r#"
app "test" provides [main] to "./platform"
Noop := {} has [Hash {hash}]
hash = \hasher, @Noop {} -> hasher
main = \hasher -> hash hasher (@Noop {})
"#
),
"hasher -> hasher | hasher has Hasher",
);
}
#[test]
fn dispatch_tag_union_function_inferred() {
infer_eq_without_problem(
indoc!(
r#"
g = if Bool.true then A else B
g ""
"#
),
"[A Str, B Str]",
);
}
#[test]
fn check_char_as_u8() {
infer_eq_without_problem(
indoc!(
r#"
x : U8
x = '.'
x
"#
),
"U8",
);
}
#[test]
fn check_char_as_u16() {
infer_eq_without_problem(
indoc!(
r#"
x : U16
x = '.'
x
"#
),
"U16",
);
}
#[test]
fn check_char_as_u32() {
infer_eq_without_problem(
indoc!(
r#"
x : U32
x = '.'
x
"#
),
"U32",
);
}
#[test]
fn check_char_pattern_as_u8() {
infer_eq_without_problem(
indoc!(
r#"
f : U8 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
f
"#
),
"U8 -> U8",
);
}
#[test]
fn check_char_pattern_as_u16() {
infer_eq_without_problem(
indoc!(
r#"
f : U16 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
f
"#
),
"U16 -> U16",
);
}
#[test]
fn check_char_pattern_as_u32() {
infer_eq_without_problem(
indoc!(
r#"
f : U32 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
f
"#
),
"U32 -> U32",
);
}
#[test]
fn issue_4246_admit_recursion_between_opaque_functions() {
infer_eq_without_problem(
indoc!(
r#"
app "test" provides [b] to "./platform"
O := {} -> {}
a = @O \{} -> ((\@O f -> f {}) b)
b = a
"#
),
"O",
);
}
}

View file

@ -0,0 +1,8 @@
app "test" provides [main] to "./platform"
Noop := {} has [Hash {hash}]
hash = \hasher, @Noop {} -> hasher
main = \hasher -> hash hasher (@Noop {})
#^^^^{-1} hasher -[[main(0)]]-> hasher | hasher has Hasher

View file

@ -0,0 +1,8 @@
# +opt infer:allow_errors
app "test" provides [main] to "./platform"
main =
\x -> when x is
#^ [A [B]w_a [C]w_b]
A B _ -> ""
A _ C -> ""

View file

@ -0,0 +1,7 @@
app "test" provides [main] to "./platform"
main =
\x -> when x is
#^ { a : [A { b : [B]w_a }*]w_b }*
{ a: A { b: B } } -> ""
_ -> ""

View file

@ -0,0 +1,8 @@
app "test" provides [main] to "./platform"
x : Result Str []
x = Ok "abc"
main = when x is
#^^^^{-1} Str
Ok s -> s

View file

@ -0,0 +1,9 @@
app "test" provides [main] to "./platform"
x : Result Str []
x = Ok "abc"
Ok str = x
main = str
# ^^^ Str

View file

@ -0,0 +1,5 @@
app "test" provides [x] to "./platform"
x : Result Str [] -> Str
x = \Ok s -> s
#^{-1} Result Str [] -[[x(0)]]-> Str

View file

@ -0,0 +1,6 @@
app "test" provides [main] to "./platform"
g = if Bool.true then A else B
main = g ""
# ^ Str -[[2, 3]]-> [A Str, B Str]w_a

View file

@ -0,0 +1,16 @@
app "test" provides [main] to "./platform"
main =
x = Bool.true
y = Bool.false
a = "foo"
b = "bar"
foo = \{} -> if x then a else bar {}
#^^^{-1} {} -[[foo(5) Bool Bool Str Str]]-> Str
bar = \{} -> if y then b else foo {}
#^^^{-1} {} -[[bar(6) Bool Bool Str Str]]-> Str
bar {}

View file

@ -0,0 +1,22 @@
app "test" provides [main] to "./platform"
main =
compose = \f, g ->
closCompose = \x -> g (f x)
closCompose
const = \x ->
closConst = \_ -> x
closConst
list = []
res : Str -> Str
res = List.walk list (const "z") (\c1, c2 -> compose c1 c2)
# ^^^^^^^ (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str), (Str -[[]]-> Str) -[[compose(1)]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
# ^^^^^ Str -[[const(2)]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
# ^^^^^^^^^^^^^^^^^^^^^^^^ (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str), (Str -[[]]-> Str) -[[11]]-> (Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str)
#^^^{-1} Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str
res "hello"
#^^^{-1} Str -[[closCompose(7) (Str -a-> Str) (Str -[[]]-> Str), closConst(10) Str] as a]-> Str

View file

@ -0,0 +1,11 @@
app "test" provides [main] to "./platform"
main =
x = "abc"
getX = \{} -> x
h = \{} -> (getX {})
#^{-1} {}* -[[h(3) Str]]-> Str
h {}

View file

@ -0,0 +1,11 @@
app "test" provides [main] to "./platform"
main =
h = \{} -> (getX {})
#^{-1} {}* -[[h(1) Str]]-> Str
getX = \{} -> x
x = "abc"
h {}

View file

@ -1,7 +0,0 @@
app "test" provides [main] to "./platform"
main = when A "foo" is
A _ as a -> a
# ^ [A Str]w_a
b -> b
# ^ [A Str]w_a

View file

@ -0,0 +1,6 @@
app "test" provides [main] to "./platform"
Pair x _ = Pair 0 1
main = x
# ^ Num w_a

View file

@ -0,0 +1,5 @@
app "test" provides [x] to "./platform"
x : U16
x = '.'
#^{-1} U16

View file

@ -0,0 +1,5 @@
app "test" provides [x] to "./platform"
x : U32
x = '.'
#^{-1} U32

View file

@ -0,0 +1,5 @@
app "test" provides [x] to "./platform"
x : U8
x = '.'
#^{-1} U8

View file

@ -0,0 +1,10 @@
app "test" provides [main] to "./platform"
f : U16 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
main = f
# ^ U16 -[[f(1)]]-> U16

View file

@ -0,0 +1,10 @@
app "test" provides [main] to "./platform"
f : U32 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
main = f
# ^ U32 -[[f(1)]]-> U32

View file

@ -0,0 +1,10 @@
app "test" provides [main] to "./platform"
f : U8 -> _
f = \c ->
when c is
'.' -> 'A'
c1 -> c1
main = f
# ^ U8 -[[f(1)]]-> U8

View file

@ -0,0 +1,6 @@
app "test" provides [main] to "./platform"
f : { x ? Str, y ? Str } -> {}
main = f {x : ""}
# ^ { x : Str, y ? Str } -[[f(1)]]-> {}