Skip to content

Commit

Permalink
move pattern desugar tests to test_mono
Browse files Browse the repository at this point in the history
  • Loading branch information
mulias committed Nov 27, 2023
1 parent d924125 commit 0ccc713
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 48 deletions.
48 changes: 0 additions & 48 deletions crates/compiler/can/tests/test_can.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,54 +1231,6 @@ mod test_can {
assert_eq!(problems, Vec::new());
}

#[test]
fn optional_field_with_binary_op() {
let src = indoc!(
r#"
{ bar ? 1 + 1 } = {}
bar
"#
);
let arena = Bump::new();
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);

assert_eq!(problems, Vec::new());
}

#[test]
fn nested_optional_field_with_binary_op() {
let src = indoc!(
r#"
when { x: ([{}], "foo") } is
{ x: ([{ bar ? 1 + 1 }], _) } -> bar
"#
);
let arena = Bump::new();
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);

assert_eq!(problems, Vec::new());
}

#[test]
fn multiline_record_pattern() {
let src = indoc!(
r#"
x = { a: 1, b: 2, c: 3 }
{
a,
b,
c,
} = x
a + b + c
"#
);
let arena = Bump::new();
let CanExprOut { problems, .. } = can_expr_with(&arena, test_home(), src);

assert_eq!(problems, Vec::new());
}

#[test]
fn issue_2534() {
let src = indoc!(
Expand Down
15 changes: 15 additions & 0 deletions crates/compiler/test_mono/generated/multiline_record_pattern.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
procedure Num.19 (#Attr.2, #Attr.3):
let Num.292 : I64 = lowlevel NumAdd #Attr.2 #Attr.3;
ret Num.292;

procedure Test.0 ():
let Test.7 : I64 = 1i64;
let Test.8 : I64 = 2i64;
let Test.9 : I64 = 3i64;
let Test.1 : {I64, I64, I64} = Struct {Test.7, Test.8, Test.9};
let Test.2 : I64 = StructAtIndex 0 Test.1;
let Test.3 : I64 = StructAtIndex 1 Test.1;
let Test.4 : I64 = StructAtIndex 2 Test.1;
let Test.6 : I64 = CallByName Num.19 Test.2 Test.3;
let Test.5 : I64 = CallByName Num.19 Test.6 Test.4;
ret Test.5;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
procedure Num.19 (#Attr.2, #Attr.3):
let Num.291 : I64 = lowlevel NumAdd #Attr.2 #Attr.3;
ret Num.291;

procedure Test.0 ():
let Test.17 : {} = Struct {};
let Test.15 : List {} = Array [Test.17];
let Test.16 : Str = "foo";
let Test.14 : {List {}, Str} = Struct {Test.15, Test.16};
let Test.10 : List {} = StructAtIndex 0 Test.14;
dec Test.16;
let Test.11 : U64 = lowlevel ListLen Test.10;
dec Test.10;
let Test.12 : U64 = 1i64;
let Test.13 : Int1 = lowlevel Eq Test.11 Test.12;
if Test.13 then
let Test.5 : I64 = 1i64;
let Test.6 : I64 = 1i64;
let Test.2 : I64 = CallByName Num.19 Test.5 Test.6;
ret Test.2;
else
let Test.7 : I64 = 0i64;
ret Test.7;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
procedure Num.19 (#Attr.2, #Attr.3):
let Num.291 : I64 = lowlevel NumAdd #Attr.2 #Attr.3;
ret Num.291;

procedure Test.0 ():
let Test.5 : {} = Struct {};
let Test.3 : I64 = 1i64;
let Test.4 : I64 = 1i64;
let Test.1 : I64 = CallByName Num.19 Test.3 Test.4;
ret Test.1;
31 changes: 31 additions & 0 deletions crates/compiler/test_mono/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,37 @@ fn optional_when() {
"#
}

#[mono_test]
fn optional_field_with_binary_op() {
r#"
{ bar ? 1 + 1 } = {}
bar
"#
}

#[mono_test]
fn nested_optional_field_with_binary_op() {
r#"
when { x: ([{}], "foo") } is
{ x: ([{ bar ? 1 + 1 }], _) } -> bar
_ -> 0
"#
}

#[mono_test]
fn multiline_record_pattern() {
r#"
x = { a: 1, b: 2, c: 3 }
{
a,
b,
c,
} = x
a + b + c
"#
}

#[mono_test]
fn nested_pattern_match() {
r#"
Expand Down

0 comments on commit 0ccc713

Please sign in to comment.