Skip to content

Commit

Permalink
Add a few destructuring smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ospencer committed Apr 15, 2022
1 parent d81b138 commit 7765b9b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions compiler/test/suites/pattern_matching.re
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,51 @@ describe("pattern matching", ({test, testSkip}) => {
|},
"Expected `=>` followed by an expression.",
);

// destructuring
assertRun(
"destructure_constant",
{|
let 1 | _ = 5
print("ok")
|},
"ok\n",
);
assertRun(
"destructure_singleton_adt",
{|
enum NumWrapper { NumWrapper(Number) }
let NumWrapper(a) = NumWrapper(5)
print(a)
|},
"5\n",
);
assertRun(
"destructure_adt",
{|
enum Foo { A(Number), B(Number) }
let A(val1) | B(val1) = A(5)
let A(val2) | B(val2) = B(6)
print(val1)
print(val2)
|},
"5\n6\n",
);
assertRun(
"destructure_tuple",
{|
let (a, b) = (3, 4)
print(a + b)
|},
"7\n",
);
assertRun(
"destructure_record",
{|
record Rec { a: Number, b: Number }
let {a, b} = { a: 3, b: 4 }
print(a + b)
|},
"7\n",
);
});

0 comments on commit 7765b9b

Please sign in to comment.