nushell/crates/nu-command/tests/commands/inspect.rs
Solomon 071faae772
fix inspect and explore panics on empty records (#13893)
# Description

Fixes a couple panics:

```
> {} | inspect
Error:   x Main thread panicked.
  |-> at crates/nu-command/src/debug/inspect_table.rs:87:15
  `-> attempt to divide by zero
```

```
> {} | explore
# see an empty column, press Down
Error:   x Main thread panicked.
  |-> at crates/nu-explore/src/views/cursor/mod.rs:39:9
  `-> attempt to subtract with overflow
```

# User-Facing Changes

`{} | inspect` now outputs an empty table:

```
╭─────────────┬────────╮
│ description │ record │
├─────────────┴────────┤
│                      │
├──────────────────────┤
```

`{} | explore` opens the help menu.

Both match the empty list behavior.

# Tests

I'm not sure how to test `explore`, as it waits for interaction.
2024-09-25 07:48:16 -05:00

20 lines
429 B
Rust

use nu_test_support::nu;
#[test]
fn inspect_with_empty_pipeline() {
let actual = nu!("inspect");
assert!(actual.err.contains("no input value was piped in"));
}
#[test]
fn inspect_with_empty_list() {
let actual = nu!("[] | inspect");
assert!(actual.out.contains("empty list"));
}
#[test]
fn inspect_with_empty_record() {
let actual = nu!("{} | inspect");
assert!(actual.out.contains("empty record"));
}