mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Share code between validation and step
This commit is contained in:
parent
0a80b543b4
commit
6fbafad3ff
2 changed files with 108 additions and 62 deletions
|
@ -6,10 +6,30 @@ fn one_plus_one() {
|
|||
let mut state = ReplState::new();
|
||||
let input = "1 + 1";
|
||||
|
||||
assert_validates(input);
|
||||
assert_step(input, &mut state, Ok("2 : Num * # TODOval1"));
|
||||
assert_done(&state);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete_annotation() {
|
||||
let mut state = ReplState::new();
|
||||
let input = "x : Str";
|
||||
|
||||
assert_incomplete(input);
|
||||
assert_step(input, &mut state, Ok(""));
|
||||
assert_done(&state);
|
||||
}
|
||||
|
||||
fn assert_validates(input: &str) {
|
||||
assert!(matches!(validate(input), Ok(ValidationResult::Valid(None))));
|
||||
}
|
||||
|
||||
fn assert_incomplete(input: &str) {
|
||||
assert!(matches!(validate(input), Ok(ValidationResult::Incomplete)));
|
||||
}
|
||||
|
||||
/// step the given input, then check the Result vs the trimmed input with ANSI escape codes stripped.
|
||||
fn assert_step(input: &str, state: &mut ReplState, expected_step_result: Result<&str, i32>) {
|
||||
match state.step(input) {
|
||||
Ok(string) => {
|
||||
|
@ -25,3 +45,13 @@ fn assert_step(input: &str, state: &mut ReplState, expected_step_result: Result<
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_done(state: &ReplState) {
|
||||
assert_eq!(
|
||||
state.pending_src,
|
||||
String::new(),
|
||||
"pending_src was not empty; it was {:?}",
|
||||
state.pending_src
|
||||
);
|
||||
assert!(!state.prev_line_blank, "prev_line_blank was true");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue