a suprising amount of test cases

This commit is contained in:
2025-11-12 13:41:49 -07:00
parent 5c57c87775
commit 151385c8a7

View File

@@ -161,8 +161,11 @@ impl Grid {
continue; continue;
} }
} else { } else {
// we are at the end of the row, so idk if it matters anymore, as there won't be a next() if is_escaped {
todo!() is_escaped = false;
} else {
continue;
}
} }
} else { } else {
// not inside quotes, must be escaping another one // not inside quotes, must be escaping another one
@@ -179,8 +182,11 @@ impl Grid {
continue; continue;
} }
} else { } else {
// single quote at the end of a line, is odd // not inside quotes, EOL
todo!()
if is_escaped {
is_escaped = false;
}
} }
} }
} }
@@ -585,13 +591,29 @@ fn sum_function() {
#[test] #[test]
fn parse_csv() { fn parse_csv() {
//standard parsing
assert_eq!(Grid::parse_csv_line("1,2,3"), vec![Some("1".to_string()), Some("2".to_string()), Some("3".to_string())]); assert_eq!(Grid::parse_csv_line("1,2,3"), vec![Some("1".to_string()), Some("2".to_string()), Some("3".to_string())]);
// comma in a cell
assert_eq!(Grid::parse_csv_line("1,\",\",3"), vec![Some("1".to_string()), Some(",".to_string()), Some("3".to_string())]); assert_eq!(Grid::parse_csv_line("1,\",\",3"), vec![Some("1".to_string()), Some(",".to_string()), Some("3".to_string())]);
// quotes in a cell
assert_eq!(Grid::parse_csv_line("1,she said \"\"wow\"\",3"), vec![Some("1".to_string()), Some("she said \"wow\"".to_string()), Some("3".to_string())]); assert_eq!(Grid::parse_csv_line("1,she said \"\"wow\"\",3"), vec![Some("1".to_string()), Some("she said \"wow\"".to_string()), Some("3".to_string())]);
// quotes and comma in cell
assert_eq!(Grid::parse_csv_line("1,\"she said \"\"hello, world\"\"\",3"), vec![Some("1".to_string()), Some("she said \"hello, world\"".to_string()), Some("3".to_string())]); assert_eq!(Grid::parse_csv_line("1,\"she said \"\"hello, world\"\"\",3"), vec![Some("1".to_string()), Some("she said \"hello, world\"".to_string()), Some("3".to_string())]);
assert_eq!(Grid::parse_csv_line("1,she said \"\"hello world\"\"\"\",3"), vec![Some("1".to_string()), Some("she said \"hello world\"\"".to_string()), Some("3".to_string())]); // ending with a quote
assert_eq!(Grid::parse_csv_line("1,she said \"\"hello world\"\""), vec![Some("1".to_string()), Some("she said \"hello world\"".to_string())]);
// ending with a quote with a comma
assert_eq!(Grid::parse_csv_line("1,\"she said \"\"hello, world\"\"\""), vec![Some("1".to_string()), Some("she said \"hello, world\"".to_string())]);
// starting with a quote
assert_eq!(Grid::parse_csv_line("\"\"hello world\"\" is what she said,1"), vec![Some("\"hello world\" is what she said".to_string()), Some("1".to_string())]);
// starting with a quote with a comma
assert_eq!(Grid::parse_csv_line("\"\"\"hello, world\"\" is what she said\",1"), vec![Some("\"hello, world\" is what she said".to_string()), Some("1".to_string())]);
} }