Remove the whole #var1 thing

This commit is contained in:
Richard Feldman 2023-09-17 01:00:15 -04:00
parent f4937e72cc
commit 074401fbdf
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
11 changed files with 39 additions and 185 deletions

View file

@ -126,19 +126,13 @@ pub fn expect_success(input: &str, expected: &str) {
assert_multiline_str_eq!("", out.stderr.as_str());
// Don't consider the auto variable name (e.g. "# val1") at the end.
// The state.rs tests do that!
let mut iter = out.stdout.lines().rev();
let line = iter.next().unwrap();
let comment_index = line.rfind('#').unwrap_or(line.len());
let line_without_comment = line[0..comment_index].trim_end();
// Sometimes the "# val1" wraps around to its own line; if this happens,
// we just use the preceding line instead.
if line_without_comment.is_empty() {
if line.is_empty() {
assert_multiline_str_eq!(expected, iter.next().unwrap().trim_end());
} else {
assert_multiline_str_eq!(expected, line_without_comment);
assert_multiline_str_eq!(expected, line);
}
assert!(out.status.success());

View file

@ -14,27 +14,16 @@ use target_lexicon::Triple;
#[test]
fn one_plus_one() {
complete("1 + 1", &mut ReplState::new(), "2 : Num *", "val1");
}
#[test]
fn generated_expr_names() {
let mut state = ReplState::new();
complete("2 * 3", &mut state, "6 : Num *", "val1");
complete("4 - 1", &mut state, "3 : Num *", "val2");
complete("val1 + val2", &mut state, "9 : Num *", "val3");
complete("1 + (val2 * val3)", &mut state, "28 : Num *", "val4");
complete("1 + 1", &mut ReplState::new(), "2 : Num *");
}
#[test]
fn persisted_defs() {
let mut state = ReplState::new();
complete("x = 5", &mut state, "5 : Num *", "x");
complete("7 - 3", &mut state, "4 : Num *", "val1");
complete("y = 6", &mut state, "6 : Num *", "y");
complete("val1 + x + y", &mut state, "15 : Num *", "val2");
complete("x = 5", &mut state, "5 : Num *");
complete("7 - 3", &mut state, "4 : Num *");
complete("y = 6", &mut state, "6 : Num *");
}
#[test]
@ -45,7 +34,7 @@ fn annotated_body() {
input.push_str("t = A");
complete(&input, &mut ReplState::new(), "A : [A, B, C]", "t");
complete(&input, &mut ReplState::new(), "A : [A, B, C]");
}
#[test]
@ -60,7 +49,7 @@ fn exhaustiveness_problem() {
input.push_str("t = A");
complete(&input, &mut state, "A : [A, B, C]", "t");
complete(&input, &mut state, "A : [A, B, C]");
}
// Run a `when` on it that isn't exhaustive
@ -118,7 +107,7 @@ fn standalone_annotation() {
/// 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_start: &str, expected_end: &str) {
fn complete(input: &str, state: &mut ReplState, expected_start: &str) {
assert!(!is_incomplete(input));
let arena = Bump::new();
let target = Triple::host();
@ -127,15 +116,10 @@ fn complete(input: &str, state: &mut ReplState, expected_start: &str, expected_e
let repl_helper = ReplHelper::default();
let mut editor = Editor::<ReplHelper>::new();
editor.set_helper(Some(repl_helper));
let dimensions = editor.dimensions();
match action {
ReplAction::Eval {
opt_mono,
problems,
opt_var_name,
} => {
let string = evaluate(opt_mono, problems, opt_var_name, &target, dimensions);
ReplAction::Eval { opt_mono, problems } => {
let string = evaluate(opt_mono, problems, &target);
let escaped =
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap())
.unwrap();
@ -143,12 +127,6 @@ fn complete(input: &str, state: &mut ReplState, expected_start: &str, expected_e
let comment_index = escaped.rfind('#').unwrap_or(escaped.len());
assert_eq!(expected_start, (escaped[0..comment_index].trim()));
assert_eq!(
expected_end,
// +1 because we want to skip over the '#' itself
(escaped[comment_index + 1..].trim())
);
}
_ => {
panic!("Unexpected action: {:?}", action);
@ -175,15 +153,10 @@ fn error(input: &str, state: &mut ReplState, expected_step_result: String) {
let repl_helper = ReplHelper::default();
let mut editor = Editor::<ReplHelper>::new();
editor.set_helper(Some(repl_helper));
let dimensions = editor.dimensions();
match action {
ReplAction::Eval {
opt_mono,
problems,
opt_var_name,
} => {
let string = evaluate(opt_mono, problems, opt_var_name, &target, dimensions);
ReplAction::Eval { opt_mono, problems } => {
let string = evaluate(opt_mono, problems, &target);
let escaped =
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap())
.unwrap();

View file

@ -588,11 +588,7 @@ fn multiline_string_non_wasm() {
);
assert_multiline_str_eq!("", out.stderr.as_str());
// Don't consider the auto variable name ("# val1") at the end.
// The state.rs tests do that!
assert_multiline_str_eq!(expected, out.stdout.replace("# val1", "").trim());
assert_multiline_str_eq!(expected, out.stdout.trim());
assert!(out.status.success());
}
@ -1409,9 +1405,6 @@ fn interpolation_with_nested_interpolation() {
Enter an expression to evaluate, or a definition (like x = 1) to use in future expressions.
Unless there was a compile-time error, expressions get automatically named so you can refer to them later.
For example, if you see # val1 after an output, you can now refer to that expression as val1 in future expressions.
Tips:
- ctrl-v + ctrl-j makes a newline

View file

@ -160,12 +160,8 @@ pub fn expect(input: &'static str, expected: &str) {
// We need to get rid of HTML tags, and we can be quite specific about it!
// If we ever write more complex test cases, we might need regex here.
let without_html = raw_output
.replace("<span class='color-magenta'> : </span>", " : ")
.replace("<span class='color-green'> # val1</span>", "");
let without_html = raw_output.replace("<span class='color-magenta'> : </span>", " : ");
// Whitespace that was originally in front of the `# val1` is now at the end,
// and there's other whitespace at both ends too. Trim it all.
let clean_output = without_html.trim();
assert_eq!(clean_output, expected);