Skip to content

Commit

Permalink
frontend: Add more tests for exhaustiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Dec 1, 2024
1 parent 7ffb5fc commit d2cd063
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions dora-frontend/src/exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,81 @@ fn check_coverage(
sa.report(file_id, node.expr.span(), msg);
}
}

#[cfg(test)]
mod tests {
use crate::tests::err;
use crate::ErrorMessage;

#[test]
fn test_missing_arm() {
err(
"
enum Foo { A, B, C }
fn f(x: Foo) {
match x {
Foo::A => {}
Foo::B => {}
}
}
",
(4, 23),
ErrorMessage::MatchUncoveredVariant,
);
}

#[test]
fn test_duplicate_arm() {
err(
"
enum Foo { A, B, C }
fn f(x: Foo) {
match x {
Foo::A => {}
Foo::B => {}
Foo::B => {}
Foo::C => {}
}
}
",
(7, 21),
ErrorMessage::MatchUnreachablePattern,
);
}

#[test]
fn test_duplicate_arm_after_underscore() {
err(
"
enum Foo { A, B, C }
fn f(x: Foo) {
match x {
Foo::A => {}
_ => {}
Foo::C => {}
}
}
",
(7, 21),
ErrorMessage::MatchUnreachablePattern,
);
}

#[test]
fn test_duplicate_arm_after_var() {
err(
"
enum Foo { A, B, C }
fn f(x: Foo) {
match x {
Foo::A => {}
v => {}
Foo::C => {}
}
}
",
(7, 21),
ErrorMessage::MatchUnreachablePattern,
);
}
}

0 comments on commit d2cd063

Please sign in to comment.