nushell/crates/nu-command/tests/commands/length.rs
Solomon 8b19399b13
support binary input in length (#14224)
Closes #13874

# User-Facing Changes

`length` now supports binary input:

```nushell
> random binary 1kb | length
1000
```
2024-11-04 03:39:24 +00:00

36 lines
853 B
Rust

use nu_test_support::fs::Stub::FileWithContent;
use nu_test_support::nu;
use nu_test_support::playground::Playground;
#[test]
fn length_columns_in_cal_table() {
let actual = nu!("cal --as-table | columns | length");
assert_eq!(actual.out, "7");
}
#[test]
fn length_columns_no_rows() {
let actual = nu!("echo [] | length");
assert_eq!(actual.out, "0");
}
#[test]
fn length_fails_on_echo_record() {
let actual = nu!("echo {a:1 b:2} | length");
assert!(actual.err.contains("only_supports_this_input_type"));
}
#[test]
fn length_byte_stream() {
Playground::setup("length_bytes", |dirs, sandbox| {
sandbox.mkdir("length_bytes");
sandbox.with_files(&[FileWithContent("data.txt", "😀")]);
let actual = nu!(cwd: dirs.test(), "open data.txt | length");
assert_eq!(actual.out, "4");
});
}