Test for pattern-matching
This commit is contained in:
parent
77d2826918
commit
151246e1c5
@ -696,4 +696,35 @@ if (1, 5) {
|
|||||||
"#;
|
"#;
|
||||||
test_in_fresh_env!(source, 5);
|
test_in_fresh_env!(source, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn prim_obj_pattern() {
|
||||||
|
let source = r#"
|
||||||
|
type Stuff = Mulch(Nat) | Jugs(Nat, String) | Mardok
|
||||||
|
let a = Mulch(20)
|
||||||
|
let b = Jugs(1, "haha")
|
||||||
|
let c = Mardok
|
||||||
|
|
||||||
|
let x = if a {
|
||||||
|
is Mulch(20) -> "x",
|
||||||
|
is _ -> "ERR"
|
||||||
|
}
|
||||||
|
|
||||||
|
let y = if b {
|
||||||
|
is Mulch(n) -> "ERR",
|
||||||
|
is Jugs(2, _) -> "ERR",
|
||||||
|
is Jugs(1, s) -> s,
|
||||||
|
is _ -> "ERR",
|
||||||
|
}
|
||||||
|
|
||||||
|
let z = if c {
|
||||||
|
is Jugs(_, _) -> "ERR",
|
||||||
|
is Mardok -> "NIGH",
|
||||||
|
is _ -> "ERR",
|
||||||
|
}
|
||||||
|
|
||||||
|
(x, y, z)
|
||||||
|
"#;
|
||||||
|
test_in_fresh_env!(source, r#"("x", "haha", "NIGH")"#);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user