group by to table empty (#16219)

- fixes #16217

# Description

> `group-by --to-table` does not always return a table (a list)
> ```nushell
> [] | group-by --to-table something
> #=> ╭──────────────╮
> #=> │ empty record │
> #=> ╰──────────────╯
> ```

Fixed:
```nushell
[] | group-by --to-table something
#=> ╭────────────╮
#=> │ empty list │
#=> ╰────────────╯
```

# Tests + Formatting
+1 test

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
Bahex
2025-07-22 15:07:55 +03:00
committed by GitHub
parent 324aaef0af
commit b0687606f7
2 changed files with 17 additions and 3 deletions

View File

@ -68,9 +68,18 @@ fn errors_if_column_not_found() {
#[test]
fn group_by_on_empty_list_returns_empty_record() {
let actual = nu!("[[a b]; [1 2]] | where false | group-by a");
let actual = nu!("[[a b]; [1 2]] | where false | group-by a | to nuon --raw");
let expected = r#"{}"#;
assert!(actual.err.is_empty());
assert!(actual.out.contains("empty record"));
assert_eq!(actual.out, expected);
}
#[test]
fn group_by_to_table_on_empty_list_returns_empty_list() {
let actual = nu!("[[a b]; [1 2]] | where false | group-by --to-table a | to nuon --raw");
let expected = r#"[]"#;
assert!(actual.err.is_empty());
assert_eq!(actual.out, expected);
}
#[test]