2024-11-04 04:39:24 +01:00
|
|
|
use nu_test_support::fs::Stub::FileWithContent;
|
2023-07-17 18:43:51 +02:00
|
|
|
use nu_test_support::nu;
|
2024-11-04 04:39:24 +01:00
|
|
|
use nu_test_support::playground::Playground;
|
2020-08-16 05:16:49 +02:00
|
|
|
|
|
|
|
#[test]
|
2021-03-13 22:46:40 +01:00
|
|
|
fn length_columns_in_cal_table() {
|
2024-06-22 14:41:29 +02:00
|
|
|
let actual = nu!("cal --as-table | columns | length");
|
2020-08-16 05:16:49 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "7");
|
|
|
|
}
|
2020-08-19 04:16:35 +02:00
|
|
|
|
|
|
|
#[test]
|
2021-03-13 22:46:40 +01:00
|
|
|
fn length_columns_no_rows() {
|
2023-08-23 23:03:26 +02:00
|
|
|
let actual = nu!("echo [] | length");
|
2020-08-19 04:16:35 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "0");
|
|
|
|
}
|
2023-08-23 23:03:26 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn length_fails_on_echo_record() {
|
|
|
|
let actual = nu!("echo {a:1 b:2} | length");
|
|
|
|
|
2023-08-24 22:48:05 +02:00
|
|
|
assert!(actual.err.contains("only_supports_this_input_type"));
|
2023-08-23 23:03:26 +02:00
|
|
|
}
|
2024-11-04 04:39:24 +01:00
|
|
|
|
|
|
|
#[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");
|
|
|
|
});
|
|
|
|
}
|