Use insta for inferred queried tests

This commit is contained in:
Ayaz Hafiz 2022-07-18 15:39:42 -04:00
parent 159ddd3906
commit 4d0c1e6a9c
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 139 additions and 143 deletions

View file

@ -245,7 +245,7 @@ mod solve_expr {
assert_eq!(actual, expected.to_string());
}
fn infer_queries_help(src: &str, expected: &[&'static str], print_only_under_alias: bool) {
fn infer_queries_help(src: &str, expected: impl FnOnce(&str), print_only_under_alias: bool) {
let (
LoadedModule {
module_id: home,
@ -319,15 +319,17 @@ mod solve_expr {
solved_queries.push(elaborated);
}
assert_eq!(solved_queries, expected)
let pretty_solved_queries = solved_queries.join("\n");
expected(&pretty_solved_queries);
}
macro_rules! infer_queries {
($program:expr, $queries:expr $(,)?) => {
infer_queries_help($program, $queries, false)
($program:expr, @$queries:literal $(,)?) => {
infer_queries_help($program, |golden| insta::assert_snapshot!(golden, @$queries), false)
};
($program:expr, $queries:expr, print_only_under_alias=true $(,)?) => {
infer_queries_help($program, $queries, true)
($program:expr, @$queries:literal, print_only_under_alias=true $(,)?) => {
infer_queries_help($program, |golden| insta::assert_snapshot!(golden, @$queries), true)
};
}
@ -6197,12 +6199,12 @@ mod solve_expr {
# ^^^^^
"#
),
&[
"ob : Bool",
"ob : Bool",
"True : [False, True]",
"False : [False, True]",
],
@r###"
ob : Bool
ob : Bool
True : [False, True]
False : [False, True]
"###
)
}
@ -6345,11 +6347,11 @@ mod solve_expr {
#^^^^^^^^^{-1}
"#
),
&[
"Linear#u8(22) : U8 -[[u8(22)]]-> Encoder Linear",
"MyU8#toEncoder(23) : MyU8 -[[toEncoder(23)]]-> Encoder fmt | fmt has Format",
"myU8Bytes : List U8",
],
@r###"
Linear#u8(10) : U8 -[[u8(10)]]-> Encoder Linear
MyU8#toEncoder(11) : MyU8 -[[toEncoder(11)]]-> Encoder fmt | fmt has Format
myU8Bytes : List U8
"###
)
}
@ -6406,11 +6408,11 @@ mod solve_expr {
#^^^^{-1}
"#
),
&[
"Linear#u8(27) : Decoder U8 Linear",
"MyU8#decoder(28) : Decoder MyU8 fmt | fmt has DecoderFormatting",
"myU8 : Result MyU8 DecodeError",
],
@r#"
Linear#u8(11) : Decoder U8 Linear
MyU8#decoder(12) : Decoder MyU8 fmt | fmt has DecoderFormatting
myU8 : Result MyU8 DecodeError
"#
)
}
@ -6454,7 +6456,7 @@ mod solve_expr {
a
"#
),
&["A#default(5) : {} -[[default(5)]]-> A"],
@"A#default(4) : {} -[[default(4)]]-> A"
)
}
@ -6498,9 +6500,9 @@ mod solve_expr {
# ^^^^^^^^^
"#
),
&[
"Encoding#toEncoder(2) : { a : Str } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt | fmt has EncoderFormatting",
],
@r#"
"Encoding#toEncoder(2) : { a : Str } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt | fmt has EncoderFormatting",
"#
)
}
@ -6521,9 +6523,9 @@ mod solve_expr {
# ^^^^^^^^^
"#
),
&[
"Encoding#toEncoder(2) : { a : A } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt | fmt has EncoderFormatting",
],
@r#"
"Encoding#toEncoder(2) : { a : A } -[[#Derived.toEncoder_{a}(0)]]-> Encoder fmt | fmt has EncoderFormatting",
"#
)
}
@ -6553,12 +6555,12 @@ mod solve_expr {
a
"#
),
&[
"A#id(5) : A -[[id(5)]]-> A",
"Id#id(4) : a -[[] + a:id(4):1]-> a | a has Id",
"alias1 : a -[[] + a:id(4):1]-> a | a has Id",
"alias2 : A -[[id(5)]]-> A",
],
@r###"
A#id(4) : A -[[id(4)]]-> A
Id#id(2) : a -[[] + a:id(2):1]-> a | a has Id
alias1 : a -[[] + a:id(2):1]-> a | a has Id
alias2 : A -[[id(4)]]-> A
"###
)
}
@ -6587,14 +6589,12 @@ mod solve_expr {
a
"#
),
&[
"A#id1(8) : A -[[id1(8)]]-> A",
//
"A#id2(9) : A -[[id2(9)]]-> A",
"A#id1(8) : A -[[id1(8)]]-> A",
//
"A#id2(9) : A -[[id2(9)]]-> A",
],
@r###"
A#id1(6) : A -[[id1(6)]]-> A
A#id2(7) : A -[[id2(7)]]-> A
A#id1(6) : A -[[id1(6)]]-> A
A#id2(7) : A -[[id2(7)]]-> A
"###
)
}
@ -6627,12 +6627,12 @@ mod solve_expr {
#^^^^^^^^{-1}
"#
),
&[
"A#id(5) : A -[[id(5)]]-> A",
"idNotAbility : a -[[idNotAbility(6)]]-> a",
"idChoice : a -[[idNotAbility(6)] + a:id(4):1]-> a | a has Id",
"idChoice : A -[[id(5), idNotAbility(6)]]-> A",
],
@r###"
A#id(4) : A -[[id(4)]]-> A
idNotAbility : a -[[idNotAbility(5)]]-> a
idChoice : a -[[idNotAbility(5)] + a:id(2):1]-> a | a has Id
idChoice : A -[[id(4), idNotAbility(5)]]-> A
"###
)
}
@ -6662,11 +6662,11 @@ mod solve_expr {
#^^^^^^^^{-1}
"#
),
&[
"A#id(5) : A -[[id(5)]]-> A",
"idChoice : a -[[] + a:id(4):1]-> a | a has Id",
"idChoice : A -[[id(5)]]-> A",
],
@r#"
A#id(4) : A -[[id(4)]]-> A
idChoice : a -[[] + a:id(2):1]-> a | a has Id
idChoice : A -[[id(4)]]-> A
"#,
)
}
@ -6696,11 +6696,11 @@ mod solve_expr {
a
"#
),
&[
"A#id(7) : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
"Id#id(6) : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
"alias : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
],
@r#"
A#id(5) : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
Id#id(3) : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
alias : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
"#,
print_only_under_alias = true,
)
}
@ -6727,10 +6727,10 @@ mod solve_expr {
#^^{-1}
"#
),
&[
"A#id(7) : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
"it : {} -[[8(8)]]-> {}",
],
@r#"
A#id(5) : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
it : {} -[[8(8)]]-> {}
"#,
print_only_under_alias = true,
)
}
@ -6758,10 +6758,10 @@ mod solve_expr {
a
"#
),
&[
"A#id(7) : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
"A#id(7) : {} -[[id(7)]]-> ({} -[[8(8)]]-> {})",
],
@r#"
A#id(5) : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
A#id(5) : {} -[[id(5)]]-> ({} -[[8(8)]]-> {})
"#,
print_only_under_alias = true,
)
}
@ -6787,12 +6787,11 @@ mod solve_expr {
a
"#
),
&[
"A#diverge(5) : A -[[diverge(5)]]-> A",
"Diverge#diverge(4) : A -[[diverge(5)]]-> A",
//
"A#diverge(5) : A -[[diverge(5)]]-> A",
],
@r###"
A#diverge(4) : A -[[diverge(4)]]-> A
Diverge#diverge(2) : A -[[diverge(4)]]-> A
A#diverge(4) : A -[[diverge(4)]]-> A
"###
)
}
@ -6823,15 +6822,13 @@ mod solve_expr {
a
"#
),
&[
"A#ping(7) : A -[[ping(7)]]-> A",
"Bounce#pong(6) : A -[[pong(8)]]-> A",
//
"A#pong(8) : A -[[pong(8)]]-> A",
"A#ping(7) : A -[[ping(7)]]-> A",
//
"A#ping(7) : A -[[ping(7)]]-> A",
],
@r###"
A#ping(5) : A -[[ping(5)]]-> A
Bounce#pong(3) : A -[[pong(6)]]-> A
A#pong(6) : A -[[pong(6)]]-> A
A#ping(5) : A -[[ping(5)]]-> A
A#ping(5) : A -[[ping(5)]]-> A
"###
)
}
@ -6844,7 +6841,7 @@ mod solve_expr {
#^^^^^^^^^^^^^^^^^^^^^^{-1}
"#
),
&[r#"[\{} -> {}, \{} -> {}] : List ({}* -[[1(1), 2(2)]]-> {})"#],
@r#"[\{} -> {}, \{} -> {}] : List ({}* -[[1(1), 2(2)]]-> {})"#
)
}
@ -6897,12 +6894,12 @@ mod solve_expr {
{name, outerList}
"#
),
&[
"foo : [Named Str (List a)] as a",
"Named name outerList : [Named Str (List a)] as a",
"name : Str",
"outerList : List ([Named Str (List a)] as a)",
],
@r#"
foo : [Named Str (List a)] as a
Named name outerList : [Named Str (List a)] as a
name : Str
outerList : List ([Named Str (List a)] as a)
"#,
print_only_under_alias = true
)
}
@ -6984,11 +6981,11 @@ mod solve_expr {
#^^^{-1}
"#
),
&[
"capture : Str -[[capture(1)]]-> ({} -[[thunk(5) {}, thunk(5) Str]]-> Str)",
"capture : {} -[[capture(1)]]-> ({} -[[thunk(5) {}, thunk(5) Str]]-> Str)",
"fun : {} -[[thunk(5) {}, thunk(5) Str]]-> Str",
]
@r#"
capture : Str -[[capture(1)]]-> ({} -[[thunk(5) {}, thunk(5) Str]]-> Str)
capture : {} -[[capture(1)]]-> ({} -[[thunk(5) {}, thunk(5) Str]]-> Str)
fun : {} -[[thunk(5) {}, thunk(5) Str]]-> Str
"#
);
}
@ -7019,10 +7016,7 @@ mod solve_expr {
#^^^{-1}
"#
),
&[
"fun : {} -[[thunk(9) (({} -[[15(15)]]-> { s1 : Str })) ({ s1 : Str } -[[g(4)]]-> ({} -[[13(13) Str]]-> Str)), \
thunk(9) (({} -[[14(14)]]-> Str)) (Str -[[f(3)]]-> ({} -[[11(11)]]-> Str))]]-> Str",
],
@r#"fun : {} -[[thunk(9) (({} -[[15(15)]]-> { s1 : Str })) ({ s1 : Str } -[[g(4)]]-> ({} -[[13(13) Str]]-> Str)), thunk(9) (({} -[[14(14)]]-> Str)) (Str -[[f(3)]]-> ({} -[[11(11)]]-> Str))]]-> Str"#,
print_only_under_alias = true,
);
}
@ -7050,7 +7044,7 @@ mod solve_expr {
#^^^{-1}
"#
),
&["fun : {} -[[thunk(5) [A Str]*, thunk(5) { a : Str }]]-> Str",]
@r#"fun : {} -[[thunk(5) [A Str]*, thunk(5) { a : Str }]]-> Str"#
);
}
@ -7128,12 +7122,12 @@ mod solve_expr {
# ^^^^^^^^^^
"#
),
&[
"Fo#f(10) : Fo -[[f(10)]]-> (b -[[] + b:g(8):1]-> {}) | b has G",
"Go#g(11) : Go -[[g(11)]]-> {}",
"Fo#f(10) : Fo -[[f(10)]]-> (Go -[[g(11)]]-> {})",
"f (@Fo {}) : Go -[[g(11)]]-> {}",
],
@r###"
Fo#f(7) : Fo -[[f(7)]]-> (b -[[] + b:g(4):1]-> {}) | b has G
Go#g(8) : Go -[[g(8)]]-> {}
Fo#f(7) : Fo -[[f(7)]]-> (Go -[[g(8)]]-> {})
f (@Fo {}) : Go -[[g(8)]]-> {}
"###
);
}
@ -7164,12 +7158,12 @@ mod solve_expr {
{foo, it}
"#
),
&[
"Fo#f(10) : Fo -[[f(10)]]-> ({} -[[] + b:g(8):1]-> b) | b has G",
"Go#g(11) : {} -[[g(11)]]-> Go",
"Fo#f(10) : Fo -[[f(10)]]-> ({} -[[g(11)]]-> Go)",
"f (@Fo {}) : {} -[[g(11)]]-> Go",
],
@r###"
Fo#f(7) : Fo -[[f(7)]]-> ({} -[[] + b:g(4):1]-> b) | b has G
Go#g(8) : {} -[[g(8)]]-> Go
Fo#f(7) : Fo -[[f(7)]]-> ({} -[[g(8)]]-> Go)
f (@Fo {}) : {} -[[g(8)]]-> Go
"###
);
}
@ -7198,26 +7192,26 @@ mod solve_expr {
# ^
"#
),
&[
"Fo#f(10) : Fo -[[f(10)]]-> (b -[[] + b:g(8):1]-> {}) | b has G",
"Go#g(11) : Go -[[g(11)]]-> {}",
// TODO SERIOUS: Let generalization is broken here, and this is NOT correct!!
// Two problems:
// - 1. `{}` always has its rank adjusted to the toplevel, which forces the rest
// of the type to the toplevel, but that is NOT correct here!
// - 2. During solving lambda set compaction cannot happen until an entire module
// is solved, which forces resolved-but-not-yet-compacted lambdas in
// unspecialized lambda sets to pull the rank into a lower, non-generalized
// rank. Special-casing for that is a TERRIBLE HACK that interferes very
// poorly with (1)
//
// We are BLOCKED on https://github.com/rtfeldman/roc/issues/3207 to make this work
// correctly!
// See also https://github.com/rtfeldman/roc/pull/3175, a separate, but similar problem.
"h : Go -[[g(11)]]-> {}",
"Fo#f(10) : Fo -[[f(10)]]-> (Go -[[g(11)]]-> {})",
"h : Go -[[g(11)]]-> {}",
],
// TODO SERIOUS: Let generalization is broken here, and this is NOT correct!!
// Two problems:
// - 1. `{}` always has its rank adjusted to the toplevel, which forces the rest
// of the type to the toplevel, but that is NOT correct here!
// - 2. During solving lambda set compaction cannot happen until an entire module
// is solved, which forces resolved-but-not-yet-compacted lambdas in
// unspecialized lambda sets to pull the rank into a lower, non-generalized
// rank. Special-casing for that is a TERRIBLE HACK that interferes very
// poorly with (1)
//
// We are BLOCKED on https://github.com/rtfeldman/roc/issues/3207 to make this work
// correctly!
// See also https://github.com/rtfeldman/roc/pull/3175, a separate, but similar problem.
@r###"
Fo#f(7) : Fo -[[f(7)]]-> (b -[[] + b:g(4):1]-> {}) | b has G
Go#g(8) : Go -[[g(8)]]-> {}
h : Go -[[g(8)]]-> {}
Fo#f(7) : Fo -[[f(7)]]-> (Go -[[g(8)]]-> {})
h : Go -[[g(8)]]-> {}
"###
);
}
@ -7246,13 +7240,13 @@ mod solve_expr {
h
"#
),
&[
"Fo#f(10) : Fo -[[f(10)]]-> (b -[[] + b:g(8):1]-> {}) | b has G",
"Go#g(11) : Go -[[g(11)]]-> {}",
"main : b -[[] + b:g(8):1]-> {} | b has G",
"h : b -[[] + b:g(8):1]-> {} | b has G",
"Fo#f(10) : Fo -[[f(10)]]-> (b -[[] + b:g(8):1]-> {}) | b has G",
],
@r###"
Fo#f(7) : Fo -[[f(7)]]-> (b -[[] + b:g(4):1]-> {}) | b has G
Go#g(8) : Go -[[g(8)]]-> {}
main : b -[[] + b:g(4):1]-> {} | b has G
h : b -[[] + b:g(4):1]-> {} | b has G
Fo#f(7) : Fo -[[f(7)]]-> (b -[[] + b:g(4):1]-> {}) | b has G
"###
);
}
@ -7279,11 +7273,11 @@ mod solve_expr {
# ^
"#
),
&[
"Fo#f(10) : Fo, b -[[f(10)]]-> ({} -[[13(13) b]]-> ({} -[[] + b:g(8):2]-> {})) | b has G",
"Go#g(11) : Go -[[g(11)]]-> ({} -[[14(14)]]-> {})",
"Fo#f(10) : Fo, Go -[[f(10)]]-> ({} -[[13(13) Go]]-> ({} -[[14(14)]]-> {}))",
],
@r###"
Fo#f(7) : Fo, b -[[f(7)]]-> ({} -[[13(13) b]]-> ({} -[[] + b:g(4):2]-> {})) | b has G
Go#g(8) : Go -[[g(8)]]-> ({} -[[14(14)]]-> {})
Fo#f(7) : Fo, Go -[[f(7)]]-> ({} -[[13(13) Go]]-> ({} -[[14(14)]]-> {}))
"###
);
}