ajusted test_ignore_int to work with latest changes

This commit is contained in:
Anton-4 2021-08-25 20:10:10 +02:00
parent 1c1568929a
commit 9e2a5ccc02
3 changed files with 61 additions and 24 deletions

View File

@ -194,6 +194,7 @@ pub mod test_ed_model {
use crate::ui::text::caret_w_select::test_caret_w_select::convert_selection_to_dsl;
use crate::ui::text::caret_w_select::CaretPos;
use crate::ui::text::lines::SelectableLines;
use crate::ui::text::text_pos::TextPos;
use crate::ui::ui_error::UIResult;
use bumpalo::Bump;
use ed_model::EdModel;
@ -262,7 +263,6 @@ pub mod test_ed_model {
code_arena: &'a Bump,
) -> Result<EdModel<'a>, String> {
let code_lines_vec: Vec<String> = (*code_lines).iter().map(|s| s.to_string()).collect();
let caret_w_select = convert_dsl_to_selection(&code_lines_vec)?;
*clean_code_str = [HELLO_WORLD, clean_code_str.as_str()].join("\n");
@ -290,7 +290,15 @@ pub mod test_ed_model {
code_arena,
)?;
ed_model.set_caret(caret_w_select.caret_pos);
// adjust for header and main function
let nr_hello_world_lines = HELLO_WORLD.matches('\n').count() - 1;
let caret_w_select = convert_dsl_to_selection(&code_lines_vec)?;
let adjusted_caret_pos = TextPos {
line: caret_w_select.caret_pos.line + nr_hello_world_lines,
column: caret_w_select.caret_pos.column,
};
ed_model.set_caret(adjusted_caret_pos);
Ok(ed_model)
}

View File

@ -1117,11 +1117,9 @@ pub mod test_ed_update {
#[test]
fn test_ignore_basic() -> Result<(), String> {
// space is added because Blank is inserted
assert_insert(&[""], &[""], 'a')?;
assert_insert(&[""], &[""], ';')?;
assert_insert(&[""], &[""], '-')?;
assert_insert(&[""], &[""], '_')?;
assert_insert(&[""], &[""], ';')?;
assert_insert(&[""], &[""], '-')?;
assert_insert(&[""], &[""], '_')?;
Ok(())
}
@ -1153,30 +1151,60 @@ pub mod test_ed_update {
Ok(())
}
fn merge_strings(strings: Vec<&str>) -> String {
strings
.iter()
.map(|&some_str| some_str.to_owned())
.collect::<Vec<String>>()
.join("")
}
#[test]
fn test_ignore_int() -> Result<(), String> {
assert_insert_seq_ignore(&["┃0"], "{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["┃7"], "{}()[]-><-_\"azAZ:@")?;
// type val >> this will output "val = ". So we move the caret right three times to able to enter input
let prefix = "val🡲🡲🡲";
let ignore_these = "{}()[]-><-_\"azAZ:@";
assert_insert_seq_ignore(&["0┃"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["8┃"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["20┃"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["83┃"], ",{}()[]-><-_\"azAZ:@")?;
let wrap_f = |some_str: &str| merge_strings(vec![prefix, some_str, ignore_these]);
assert_insert_seq_ignore(&["1┃0"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["8┃4"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq(&[""], &["val = ┃0"], &wrap_f("0🡰"))?;
assert_insert_seq(&[""], &["val = ┃7"], &wrap_f("7🡰"))?;
assert_insert_seq_ignore(&["┃10"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["┃84"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq(&[""], &["val = 0┃"], &wrap_f("0"))?;
assert_insert_seq(&[""], &["val = 8┃"], &wrap_f("8"))?;
assert_insert_seq(&[""], &["val = 20┃"], &wrap_f("20"))?;
assert_insert_seq(&[""], &["val = 83┃"], &wrap_f("83"))?;
assert_insert_seq_ignore(&["129┃96"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq_ignore(&["97┃684"], ",{}()[]-><-_\"azAZ:@")?;
assert_insert_seq(&[""], &["val = 1┃0"], &wrap_f("10🡰"))?;
assert_insert_seq(&[""], &["val = 8┃4"], &wrap_f("84🡰"))?;
assert_insert_ignore(&["0┃"], '0')?;
assert_insert_ignore(&["0┃"], '9')?;
assert_insert_ignore(&["┃0"], '0')?;
assert_insert_ignore(&["┃1234"], '0')?;
assert_insert_ignore(&["┃100"], '0')?;
assert_insert_seq(&[""], &["val = ┃10"], &wrap_f("10🡰🡰"))?;
assert_insert_seq(&[""], &["val = ┃84"], &wrap_f("84🡰🡰"))?;
assert_insert_seq(&[""], &["val = 129┃96"], &wrap_f("12996🡰🡰"))?;
assert_insert_seq(&[""], &["val = 97┃684"], &wrap_f("97684🡰🡰🡰"))?;
// adding numbers after 0 is invalid
assert_insert_seq(
&[""],
&["val = 0┃"],
&merge_strings(vec![prefix, "0", "09"]),
)?;
assert_insert_seq(
&[""],
&["val = ┃0"],
&merge_strings(vec![prefix, "0🡰", "0"]),
)?;
assert_insert_seq(
&[""],
&["val = ┃1234"],
&merge_strings(vec![prefix, "1234🡰🡰🡰🡰", "0"]),
)?;
assert_insert_seq(
&[""],
&["val = ┃100"],
&merge_strings(vec![prefix, "100🡰🡰🡰", "0"]),
)?;
Ok(())
}

View File

@ -16,4 +16,5 @@ app "test-app"
provides [ main ] to base
main = "Hello, world!"
"#;