mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
Adds new tests and updates old ones.
New tests are added to test for additional cases that might be trickier to handle with the new logic. Old tests are updated where their expectations are no longer expected to hold true. For instance: previously, lines would be treated separately, allowing any index offset between columns on different rows, as long as they had the same row index as decided by a separator. When this is no longer the case, some things need to be adjusted.
This commit is contained in:
parent
2c6a9e9e48
commit
a0ed6ea3c8
1 changed files with 66 additions and 9 deletions
|
@ -171,9 +171,9 @@ mod tests {
|
|||
|
||||
a b
|
||||
|
||||
1 2
|
||||
1 2
|
||||
|
||||
3 4
|
||||
3 4
|
||||
"#;
|
||||
let result = string_to_table(input, false, 1);
|
||||
assert_eq!(
|
||||
|
@ -185,6 +185,20 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_deals_with_single_column_input() {
|
||||
let input = r#"
|
||||
a
|
||||
1
|
||||
2
|
||||
"#;
|
||||
let result = string_to_table(input, false, 1);
|
||||
assert_eq!(
|
||||
result,
|
||||
Some(vec![vec![owned("a", "1")], vec![owned("a", "2")]])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_ignores_headers_when_headerless() {
|
||||
let input = r#"
|
||||
|
@ -206,15 +220,15 @@ mod tests {
|
|||
fn it_returns_none_given_an_empty_string() {
|
||||
let input = "";
|
||||
let result = string_to_table(input, true, 1);
|
||||
assert_eq!(result, None);
|
||||
assert!(result.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_allows_a_predefined_number_of_spaces() {
|
||||
let input = r#"
|
||||
column a column b
|
||||
entry 1 entry number 2
|
||||
3 four
|
||||
entry 1 entry number 2
|
||||
3 four
|
||||
"#;
|
||||
|
||||
let result = string_to_table(input, false, 3);
|
||||
|
@ -239,12 +253,55 @@ mod tests {
|
|||
|
||||
let trimmed = |s: &str| s.trim() == s;
|
||||
|
||||
let result = string_to_table(input, false, 2).unwrap();
|
||||
assert!(result
|
||||
.iter()
|
||||
.all(|row| row.iter().all(|(a, b)| trimmed(a) && trimmed(b))))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_keeps_empty_columns() {
|
||||
let input = r#"
|
||||
colA col B col C
|
||||
val2 val3
|
||||
val4 val 5 val 6
|
||||
val7 val8
|
||||
"#;
|
||||
|
||||
let result = string_to_table(input, false, 2).unwrap();
|
||||
assert_eq!(
|
||||
true,
|
||||
result
|
||||
.iter()
|
||||
.all(|row| row.iter().all(|(a, b)| trimmed(a) && trimmed(b)))
|
||||
result,
|
||||
vec![
|
||||
vec![
|
||||
owned("colA", ""),
|
||||
owned("col B", "val2"),
|
||||
owned("col C", "val3")
|
||||
],
|
||||
vec![
|
||||
owned("colA", "val4"),
|
||||
owned("col B", "val 5"),
|
||||
owned("col C", "val 6")
|
||||
],
|
||||
vec![
|
||||
owned("colA", "val7"),
|
||||
owned("col B", ""),
|
||||
owned("col C", "val8")
|
||||
],
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn it_drops_trailing_values() {
|
||||
let input = r#"
|
||||
colA col B
|
||||
val1 val2 trailing value that should be ignored
|
||||
"#;
|
||||
|
||||
let result = string_to_table(input, false, 2).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
vec![vec![owned("colA", "val1"), owned("col B", "val2"),],]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue