nu-table/ Do footer_inheritance by accouting for rows rather then a f… (#14380)

So it's my take on the comments in #14060 

The change could be seen in this test.
Looks like it works :) but I haven't done a lot of testing.


0b1af77415/crates/nu-command/tests/commands/table.rs (L3032-L3062)

```nushell
$env.config.table.footer_inheritance = true;
$env.config.footer_mode = 7;
[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4] [5]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80
```

```text
╭───┬──────┬───────────────────────╮
│ # │  a   │           b           │
├───┼──────┼───────────────────────┤
│ 0 │ kv   │ ╭───┬───────────────╮ │
│   │      │ │   │ ╭───┬───────╮ │ │
│   │      │ │ 0 │ │ # │ field │ │ │
│   │      │ │   │ ├───┼───────┤ │ │
│   │      │ │   │ │ 0 │     0 │ │ │
│   │      │ │   │ │ 1 │     1 │ │ │
│   │      │ │   │ │ 2 │     2 │ │ │
│   │      │ │   │ │ 3 │     3 │ │ │
│   │      │ │   │ │ 4 │     4 │ │ │
│   │      │ │   │ │ 5 │     5 │ │ │
│   │      │ │   │ ╰───┴───────╯ │ │
│   │      │ ╰───┴───────────────╯ │
│ 1 │ data │                     0 │
│ 2 │ data │                     0 │
├───┼──────┼───────────────────────┤
│ # │  a   │           b           │
╰───┴──────┴───────────────────────╯
```

Maybe it will also solve the issue you @fdncred encountered.

close #14060
cc: @NotTheDr01ds
This commit is contained in:
Maxim Zhiburt
2024-11-20 00:31:28 +03:00
committed by GitHub
parent 9cffbdb42a
commit b6ce907928
7 changed files with 170 additions and 65 deletions

View File

@ -2941,3 +2941,123 @@ fn table_footer_inheritance() {
assert_eq!(actual.out.match_indices("x2").count(), 1);
assert_eq!(actual.out.match_indices("x3").count(), 1);
}
#[test]
fn table_footer_inheritance_kv_rows() {
let actual = nu!(
concat!(
"$env.config.table.footer_inheritance = true;",
"$env.config.footer_mode = 7;",
"[[a b]; ['kv' {0: 0, 1: 1, 2: 2, 3: 3, 4: 4} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
)
);
assert_eq!(
actual.out,
"╭───┬──────┬───────────╮\
│ # │ a │ b │\
├───┼──────┼───────────┤\
│ 0 │ kv │ ╭───┬───╮ │\
│ │ │ │ 0 │ 0 │ │\
│ │ │ │ 1 │ 1 │ │\
│ │ │ │ 2 │ 2 │ │\
│ │ │ │ 3 │ 3 │ │\
│ │ │ │ 4 │ 4 │ │\
│ │ │ ╰───┴───╯ │\
│ 1 │ data │ 0 │\
│ 2 │ data │ 0 │\
╰───┴──────┴───────────╯"
);
let actual = nu!(
concat!(
"$env.config.table.footer_inheritance = true;",
"$env.config.footer_mode = 7;",
"[[a b]; ['kv' {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
)
);
assert_eq!(
actual.out,
"╭───┬──────┬───────────╮\
│ # │ a │ b │\
├───┼──────┼───────────┤\
│ 0 │ kv │ ╭───┬───╮ │\
│ │ │ │ 0 │ 0 │ │\
│ │ │ │ 1 │ 1 │ │\
│ │ │ │ 2 │ 2 │ │\
│ │ │ │ 3 │ 3 │ │\
│ │ │ │ 4 │ 4 │ │\
│ │ │ │ 5 │ 5 │ │\
│ │ │ ╰───┴───╯ │\
│ 1 │ data │ 0 │\
│ 2 │ data │ 0 │\
├───┼──────┼───────────┤\
│ # │ a │ b │\
╰───┴──────┴───────────╯"
);
}
#[test]
fn table_footer_inheritance_list_rows() {
let actual = nu!(
concat!(
"$env.config.table.footer_inheritance = true;",
"$env.config.footer_mode = 7;",
"[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
)
);
assert_eq!(
actual.out,
"╭───┬──────┬───────────────────────╮\
│ # │ a │ b │\
├───┼──────┼───────────────────────┤\
│ 0 │ kv │ ╭───┬───────────────╮ │\
│ │ │ │ │ ╭───┬───────╮ │ │\
│ │ │ │ 0 │ │ # │ field │ │ │\
│ │ │ │ │ ├───┼───────┤ │ │\
│ │ │ │ │ │ 0 │ 0 │ │ │\
│ │ │ │ │ │ 1 │ 1 │ │ │\
│ │ │ │ │ │ 2 │ 2 │ │ │\
│ │ │ │ │ │ 3 │ 3 │ │ │\
│ │ │ │ │ │ 4 │ 4 │ │ │\
│ │ │ │ │ ╰───┴───────╯ │ │\
│ │ │ ╰───┴───────────────╯ │\
│ 1 │ data │ 0 │\
│ 2 │ data │ 0 │\
╰───┴──────┴───────────────────────╯"
);
let actual = nu!(
concat!(
"$env.config.table.footer_inheritance = true;",
"$env.config.footer_mode = 7;",
"[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4] [5]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
)
);
assert_eq!(
actual.out,
"╭───┬──────┬───────────────────────╮\
│ # │ a │ b │\
├───┼──────┼───────────────────────┤\
│ 0 │ kv │ ╭───┬───────────────╮ │\
│ │ │ │ │ ╭───┬───────╮ │ │\
│ │ │ │ 0 │ │ # │ field │ │ │\
│ │ │ │ │ ├───┼───────┤ │ │\
│ │ │ │ │ │ 0 │ 0 │ │ │\
│ │ │ │ │ │ 1 │ 1 │ │ │\
│ │ │ │ │ │ 2 │ 2 │ │ │\
│ │ │ │ │ │ 3 │ 3 │ │ │\
│ │ │ │ │ │ 4 │ 4 │ │ │\
│ │ │ │ │ │ 5 │ 5 │ │ │\
│ │ │ │ │ ╰───┴───────╯ │ │\
│ │ │ ╰───┴───────────────╯ │\
│ 1 │ data │ 0 │\
│ 2 │ data │ 0 │\
├───┼──────┼───────────────────────┤\
│ # │ a │ b │\
╰───┴──────┴───────────────────────╯"
);
}