mirror of
https://github.com/nushell/nushell
synced 2024-12-26 04:53:09 +00:00
Display rows in the same table regardless of their column order given they are equal. (#1392)
This commit is contained in:
parent
71615f77a7
commit
4fd9974204
2 changed files with 42 additions and 4 deletions
|
@ -72,13 +72,21 @@ fn table(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream,
|
||||||
Some(a) => {
|
Some(a) => {
|
||||||
if !new_input.is_empty() {
|
if !new_input.is_empty() {
|
||||||
if let Some(descs) = new_input.get(0) {
|
if let Some(descs) = new_input.get(0) {
|
||||||
|
|
||||||
let descs = descs.data_descriptors();
|
let descs = descs.data_descriptors();
|
||||||
let compare = a.data_descriptors();
|
let descs_size = descs.len();
|
||||||
if descs != compare {
|
|
||||||
|
let a_descs = a.data_descriptors();
|
||||||
|
|
||||||
|
let mut compare = a_descs;
|
||||||
|
compare.extend(descs.into_iter());
|
||||||
|
compare.dedup();
|
||||||
|
|
||||||
|
if !compare.is_empty() {
|
||||||
|
new_input.push_back(a);
|
||||||
|
} else {
|
||||||
delay_slot = Some(a);
|
delay_slot = Some(a);
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
new_input.push_back(a);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new_input.push_back(a);
|
new_input.push_back(a);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
||||||
|
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||||
use nu_test_support::nu;
|
use nu_test_support::nu;
|
||||||
|
use nu_test_support::playground::Playground;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn doesnt_break_on_utf8() {
|
fn doesnt_break_on_utf8() {
|
||||||
|
@ -8,3 +10,31 @@ fn doesnt_break_on_utf8() {
|
||||||
|
|
||||||
assert_eq!(actual, "ö", "'{}' should contain ö", actual);
|
assert_eq!(actual, "ö", "'{}' should contain ö", actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn visualize_one_table_given_rows_with_same_columns_regardless_of_their_order_per_row() {
|
||||||
|
Playground::setup("visualize_table_test_1", |dirs, sandbox| {
|
||||||
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||||
|
"unordered_columns.txt",
|
||||||
|
r#"
|
||||||
|
[
|
||||||
|
{"name":"Andrés", "rusty_luck": 1 },
|
||||||
|
{"rusty_luck": 1, "name": "Jonathan"},
|
||||||
|
]
|
||||||
|
"#,
|
||||||
|
)]);
|
||||||
|
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(), "open unordered_columns.txt | from-json"
|
||||||
|
);
|
||||||
|
|
||||||
|
let name_column_indices: Vec<_> = actual.match_indices("name").collect();
|
||||||
|
let rusty_luck_column_indices: Vec<_> = actual.match_indices("rusty_luck").collect();
|
||||||
|
|
||||||
|
for (index, (name_index, _)) in name_column_indices.iter().enumerate() {
|
||||||
|
let (rusty_luck_index, _) = rusty_luck_column_indices[index];
|
||||||
|
|
||||||
|
assert!(name_index < &rusty_luck_index);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue