mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Add first ReplState test
This commit is contained in:
parent
a6c1667d37
commit
0a80b543b4
1 changed files with 27 additions and 0 deletions
27
crates/repl_test/src/state.rs
Normal file
27
crates/repl_test/src/state.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use roc_repl_cli::repl_state::{validate, ReplState};
|
||||||
|
use rustyline::validate::ValidationResult;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn one_plus_one() {
|
||||||
|
let mut state = ReplState::new();
|
||||||
|
let input = "1 + 1";
|
||||||
|
|
||||||
|
assert_step(input, &mut state, Ok("2 : Num * # TODOval1"));
|
||||||
|
assert!(matches!(validate(input), Ok(ValidationResult::Valid(None))));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn assert_step(input: &str, state: &mut ReplState, expected_step_result: Result<&str, i32>) {
|
||||||
|
match state.step(input) {
|
||||||
|
Ok(string) => {
|
||||||
|
let escaped = std::string::String::from_utf8(
|
||||||
|
strip_ansi_escapes::strip(string.trim()).unwrap().into(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(expected_step_result.map(str::to_string), Ok(escaped));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
assert_eq!(expected_step_result, Err(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue