Move exhaustiveness_problem to repl state test

This commit is contained in:
Richard Feldman 2022-10-30 07:17:53 -04:00
parent e0e25a48bf
commit fcfd9fa709
No known key found for this signature in database
GPG Key ID: F1F21AA5B1D9E43B
2 changed files with 56 additions and 34 deletions

View File

@ -1,3 +1,4 @@
use indoc::indoc;
use roc_repl_cli::repl_state::{is_incomplete, ReplState, TIPS};
// These are tests of the REPL state machine. They work without actually
@ -29,6 +30,47 @@ fn persisted_defs() {
complete("val1 + x + y", &mut state, Ok(("15 : Num *", "val2")));
}
#[test]
fn exhaustiveness_problem() {
let mut input = "t : [A, B, C]".to_string();
incomplete(&mut input);
input.push_str("t = A");
incomplete(&mut input);
let mut state = ReplState::new();
complete(&input, &mut state, Ok(("A : [A]*", "t")));
input.push_str("when t is");
incomplete(&mut input);
input.push_str(" A -> 1");
incomplete(&mut input);
const EXPECTED_ERROR: &str = indoc!(
r#"
UNSAFE PATTERN
This when does not cover all the possibilities:
7> when t is
8> A -> "a"
Other possibilities include:
B
C
I would have to crash if I saw one of those! Add branches for them!
"#
);
error(&input, &mut state, EXPECTED_ERROR.to_string());
}
#[test]
fn tips() {
assert!(!is_incomplete(""));
@ -54,7 +96,7 @@ fn multiline_def() {
todo!("x =\n1");
}
/// validate and step the given input, then check the Result vs the input
/// validate and step the given input, then check the Result vs the output
/// with ANSI escape codes stripped.
fn complete(input: &str, state: &mut ReplState, expected_step_result: Result<(&str, &str), i32>) {
assert!(!is_incomplete(input));
@ -92,3 +134,16 @@ fn incomplete(input: &mut String) {
// remember the input (with a newline appended) for next time.
input.push('\n');
}
/// validate and step the given input, then check the given string vs the output
/// with ANSI escape codes stripped.
fn error(input: &str, state: &mut ReplState, expected_step_result: String) {
assert!(!is_incomplete(input));
let escaped = state.step(input).map(|string| {
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap().into())
.unwrap()
});
assert_eq!(Ok(expected_step_result), escaped);
}

View File

@ -936,39 +936,6 @@ fn parse_problem() {
);
}
#[cfg(not(feature = "wasm"))] // TODO: mismatch is due to terminal control codes!
#[test]
fn exhaustiveness_problem() {
expect_failure(
indoc!(
r#"
t : [A, B, C]
t = A
when t is
A -> "a"
"#
),
indoc!(
r#"
UNSAFE PATTERN
This when does not cover all the possibilities:
7> when t is
8> A -> "a"
Other possibilities include:
B
C
I would have to crash if I saw one of those! Add branches for them!
"#
),
);
}
#[cfg(not(feature = "wasm"))]
#[test]
fn issue_2343_complete_mono_with_shadowed_vars() {