mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Update tests
This commit is contained in:
parent
ae906ca7b3
commit
21e14589b0
3 changed files with 105 additions and 37 deletions
|
@ -666,10 +666,16 @@ mod test {
|
||||||
|
|
||||||
When it failed, these variables had these values:
|
When it failed, these variables had these values:
|
||||||
|
|
||||||
a : [Err Str, Ok Str]
|
a : [
|
||||||
|
Err Str,
|
||||||
|
Ok Str,
|
||||||
|
]
|
||||||
a = Ok "Astra mortemque praestare gradatim"
|
a = Ok "Astra mortemque praestare gradatim"
|
||||||
|
|
||||||
b : [Err Str, Ok Str]
|
b : [
|
||||||
|
Err Str,
|
||||||
|
Ok Str,
|
||||||
|
]
|
||||||
b = Err "Profundum et fundamentum"
|
b = Err "Profundum et fundamentum"
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
|
|
|
@ -3571,7 +3571,8 @@ fn diff_tag_union<'b>(
|
||||||
// We've removed all the tags that they had in common, so the remaining entries in tags2
|
// We've removed all the tags that they had in common, so the remaining entries in tags2
|
||||||
// are ones that appear on the right only.
|
// are ones that appear on the right only.
|
||||||
let tags_in_right_only = tags2;
|
let tags_in_right_only = tags2;
|
||||||
|
let any_tags_in_common =
|
||||||
|
!same_tags_different_payloads.is_empty() || same_tags_same_payloads > 0;
|
||||||
let both = same_tags_different_payloads
|
let both = same_tags_different_payloads
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(to_overlap_docs);
|
.map(to_overlap_docs);
|
||||||
|
@ -3623,17 +3624,38 @@ fn diff_tag_union<'b>(
|
||||||
tags_diff.right_able.extend(diff.right_able);
|
tags_diff.right_able.extend(diff.right_able);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut left_tags_omitted = same_tags_same_payloads;
|
let left_tags_omitted;
|
||||||
let mut right_tags_omitted = same_tags_same_payloads;
|
let right_tags_omitted;
|
||||||
|
|
||||||
if !all_tags_shared {
|
if !any_tags_in_common {
|
||||||
|
// If they have no tags in common, we shouldn't omit any tags,
|
||||||
|
// because that would result in an unhelpful diff of
|
||||||
|
// […] on one side and another […] on the other side!
|
||||||
|
|
||||||
|
left_tags_omitted = 0;
|
||||||
|
right_tags_omitted = 0;
|
||||||
|
|
||||||
|
for (tag, tag_doc, args, able) in left {
|
||||||
|
tags_diff.left.push((tag, tag_doc, args));
|
||||||
|
tags_diff.left_able.extend(able);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tag, tag_doc, args, able) in right {
|
||||||
|
tags_diff.right.push((tag, tag_doc, args));
|
||||||
|
tags_diff.right_able.extend(able);
|
||||||
|
}
|
||||||
|
|
||||||
|
tags_diff.status.merge(Status::Different(Vec::new()));
|
||||||
|
} else if !all_tags_shared {
|
||||||
// If either tag union is open, omit the tags in the other. In other words,
|
// If either tag union is open, omit the tags in the other. In other words,
|
||||||
// if one tag union is a pattern match which has _ ->, don't list the tags
|
// if one tag union is a pattern match which has _ ->, don't list the tags
|
||||||
// which fall under that catch-all pattern because they won't be helpful.
|
// which fall under that catch-all pattern because they won't be helpful.
|
||||||
// By omitting them, we'll only show the tags that are actually matched.
|
// By omitting them, we'll only show the tags that are actually matched.
|
||||||
if ext2_is_open {
|
if ext2_is_open {
|
||||||
left_tags_omitted += left.len();
|
left_tags_omitted = same_tags_same_payloads + left.len();
|
||||||
} else {
|
} else {
|
||||||
|
left_tags_omitted = same_tags_same_payloads;
|
||||||
|
|
||||||
for (tag, tag_doc, args, able) in left {
|
for (tag, tag_doc, args, able) in left {
|
||||||
tags_diff.left.push((tag, tag_doc, args));
|
tags_diff.left.push((tag, tag_doc, args));
|
||||||
tags_diff.left_able.extend(able);
|
tags_diff.left_able.extend(able);
|
||||||
|
@ -3641,8 +3663,10 @@ fn diff_tag_union<'b>(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ext1_is_open {
|
if ext1_is_open {
|
||||||
right_tags_omitted += right.len();
|
right_tags_omitted = same_tags_same_payloads + right.len();
|
||||||
} else {
|
} else {
|
||||||
|
right_tags_omitted = same_tags_same_payloads;
|
||||||
|
|
||||||
for (tag, tag_doc, args, able) in right {
|
for (tag, tag_doc, args, able) in right {
|
||||||
tags_diff.right.push((tag, tag_doc, args));
|
tags_diff.right.push((tag, tag_doc, args));
|
||||||
tags_diff.right_able.extend(able);
|
tags_diff.right_able.extend(able);
|
||||||
|
@ -3650,6 +3674,9 @@ fn diff_tag_union<'b>(
|
||||||
}
|
}
|
||||||
|
|
||||||
tags_diff.status.merge(Status::Different(Vec::new()));
|
tags_diff.status.merge(Status::Different(Vec::new()));
|
||||||
|
} else {
|
||||||
|
left_tags_omitted = same_tags_same_payloads;
|
||||||
|
right_tags_omitted = same_tags_same_payloads;
|
||||||
}
|
}
|
||||||
|
|
||||||
tags_diff.left.sort_by(|a, b| a.0.cmp(&b.0));
|
tags_diff.left.sort_by(|a, b| a.0.cmp(&b.0));
|
||||||
|
@ -4056,8 +4083,8 @@ mod report_text {
|
||||||
alloc.text("[]")
|
alloc.text("[]")
|
||||||
} else {
|
} else {
|
||||||
alloc
|
alloc
|
||||||
.text("[ ")
|
.text("[")
|
||||||
.append(alloc.ellipsis().append(alloc.text(" ]")))
|
.append(alloc.ellipsis().append(alloc.text("]")))
|
||||||
}
|
}
|
||||||
.append(ext_doc)
|
.append(ext_doc)
|
||||||
} else if entries.len() == 1 {
|
} else if entries.len() == 1 {
|
||||||
|
|
|
@ -1461,7 +1461,10 @@ mod test_reporting {
|
||||||
|
|
||||||
But `f` needs its 1st argument to be:
|
But `f` needs its 1st argument to be:
|
||||||
|
|
||||||
[Green, Red]
|
[
|
||||||
|
Green,
|
||||||
|
Red,
|
||||||
|
]
|
||||||
|
|
||||||
Tip: Seems like a tag typo. Maybe `Blue` should be `Red`?
|
Tip: Seems like a tag typo. Maybe `Blue` should be `Red`?
|
||||||
|
|
||||||
|
@ -1495,7 +1498,10 @@ mod test_reporting {
|
||||||
|
|
||||||
But `f` needs its 1st argument to be:
|
But `f` needs its 1st argument to be:
|
||||||
|
|
||||||
[Green Str, Red (Int *)]
|
[
|
||||||
|
Green Str,
|
||||||
|
Red (Int *),
|
||||||
|
]
|
||||||
|
|
||||||
Tip: Seems like a tag typo. Maybe `Blue` should be `Red`?
|
Tip: Seems like a tag typo. Maybe `Blue` should be `Red`?
|
||||||
|
|
||||||
|
@ -2528,11 +2534,11 @@ mod test_reporting {
|
||||||
|
|
||||||
This `a` value is a:
|
This `a` value is a:
|
||||||
|
|
||||||
[A]
|
[…]
|
||||||
|
|
||||||
But the type annotation on `f` says it should be:
|
But the type annotation on `f` says it should be:
|
||||||
|
|
||||||
[A, B]
|
[B, …]
|
||||||
|
|
||||||
Tip: Looks like a closed tag union does not have the `B` tag.
|
Tip: Looks like a closed tag union does not have the `B` tag.
|
||||||
|
|
||||||
|
@ -2562,11 +2568,15 @@ mod test_reporting {
|
||||||
|
|
||||||
This `a` value is a:
|
This `a` value is a:
|
||||||
|
|
||||||
[A]
|
[…]
|
||||||
|
|
||||||
But the type annotation on `f` says it should be:
|
But the type annotation on `f` says it should be:
|
||||||
|
|
||||||
[A, B, C]
|
[
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
…
|
||||||
|
]
|
||||||
|
|
||||||
Tip: Looks like a closed tag union does not have the `B` and `C` tags.
|
Tip: Looks like a closed tag union does not have the `B` and `C` tags.
|
||||||
|
|
||||||
|
@ -2631,11 +2641,11 @@ mod test_reporting {
|
||||||
|
|
||||||
This `x` value is a:
|
This `x` value is a:
|
||||||
|
|
||||||
[Left {}, Right Str]
|
[Right Str, …]
|
||||||
|
|
||||||
But you are trying to use it as:
|
But you are trying to use it as:
|
||||||
|
|
||||||
[Left *]
|
[…]
|
||||||
|
|
||||||
Tip: Looks like a closed tag union does not have the `Right` tag.
|
Tip: Looks like a closed tag union does not have the `Right` tag.
|
||||||
|
|
||||||
|
@ -3380,7 +3390,13 @@ mod test_reporting {
|
||||||
|
|
||||||
This `Cons` tag application has the type:
|
This `Cons` tag application has the type:
|
||||||
|
|
||||||
[Cons {} [Cons Str [Cons {} a, Nil]b as a, Nil]b, Nil]b
|
[
|
||||||
|
Cons {} [
|
||||||
|
Cons Str [Cons {} a, Nil]b as a,
|
||||||
|
Nil,
|
||||||
|
]b,
|
||||||
|
Nil,
|
||||||
|
]b
|
||||||
|
|
||||||
But the type annotation on `x` says it should be:
|
But the type annotation on `x` says it should be:
|
||||||
|
|
||||||
|
@ -3417,8 +3433,20 @@ mod test_reporting {
|
||||||
|
|
||||||
This `ACons` tag application has the type:
|
This `ACons` tag application has the type:
|
||||||
|
|
||||||
[ACons (Int Signed64) [BCons (Int Signed64) [ACons Str [BCons I64 [ACons I64 (BList I64 I64),
|
[
|
||||||
ANil]b as ∞, BNil]c, ANil]b, BNil]c, ANil]b
|
ACons (Int Signed64) [
|
||||||
|
BCons (Int Signed64) [
|
||||||
|
ACons Str [
|
||||||
|
BCons I64 [ACons I64 (BList I64 I64),
|
||||||
|
ANil]b as ∞,
|
||||||
|
BNil,
|
||||||
|
]c,
|
||||||
|
ANil,
|
||||||
|
]b,
|
||||||
|
BNil,
|
||||||
|
]c,
|
||||||
|
ANil,
|
||||||
|
]b
|
||||||
|
|
||||||
But the type annotation on `x` says it should be:
|
But the type annotation on `x` says it should be:
|
||||||
|
|
||||||
|
@ -7946,11 +7974,11 @@ In roc, functions are always written as a lambda, like{}
|
||||||
|
|
||||||
This `v` value is a:
|
This `v` value is a:
|
||||||
|
|
||||||
F [A, B, C]
|
F [C, …]
|
||||||
|
|
||||||
But the branch patterns have type:
|
But the branch patterns have type:
|
||||||
|
|
||||||
F [A, B]
|
F […]
|
||||||
|
|
||||||
The branches must be cases of the `when` condition's type!
|
The branches must be cases of the `when` condition's type!
|
||||||
|
|
||||||
|
@ -8976,26 +9004,30 @@ In roc, functions are always written as a lambda, like{}
|
||||||
foo
|
foo
|
||||||
"#
|
"#
|
||||||
),
|
),
|
||||||
@r#"
|
@r###"
|
||||||
── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─
|
── TYPE MISMATCH ───────────────────────────────────────── /code/proj/Main.roc ─
|
||||||
|
|
||||||
The branches of this `when` expression don't match the condition:
|
The branches of this `when` expression don't match the condition:
|
||||||
|
|
||||||
6│> when bool is
|
6│> when bool is
|
||||||
7│ True -> "true"
|
7│ True -> "true"
|
||||||
8│ False -> "false"
|
8│ False -> "false"
|
||||||
9│ Wat -> "surprise!"
|
9│ Wat -> "surprise!"
|
||||||
|
|
||||||
This `bool` value is a:
|
This `bool` value is a:
|
||||||
|
|
||||||
Bool
|
Bool
|
||||||
|
|
||||||
But the branch patterns have type:
|
But the branch patterns have type:
|
||||||
|
|
||||||
[False, True, Wat]
|
[
|
||||||
|
False,
|
||||||
|
True,
|
||||||
|
Wat,
|
||||||
|
]
|
||||||
|
|
||||||
The branches must be cases of the `when` condition's type!
|
The branches must be cases of the `when` condition's type!
|
||||||
"#
|
"###
|
||||||
);
|
);
|
||||||
|
|
||||||
// from https://github.com/roc-lang/roc/commit/1372737f5e53ee5bb96d7e1b9593985e5537023a
|
// from https://github.com/roc-lang/roc/commit/1372737f5e53ee5bb96d7e1b9593985e5537023a
|
||||||
|
@ -12119,7 +12151,10 @@ I recommend using camelCase. It's the standard style in Roc code!
|
||||||
|
|
||||||
The `when` condition is a list of type:
|
The `when` condition is a list of type:
|
||||||
|
|
||||||
List [A, B]
|
List [
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
]
|
||||||
|
|
||||||
But the branch patterns have type:
|
But the branch patterns have type:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue