mirror of
https://github.com/nushell/nushell.git
synced 2024-12-23 23:49:44 +01:00
Rename count
to length
(#3166)
* update docs to refer to length instead of count * rename count to length * change all occurrences of 'count' to 'length' in tests * format length command
This commit is contained in:
parent
6cf8df8685
commit
c13fe83784
@ -23,7 +23,6 @@ pub(crate) mod clip;
|
||||
pub(crate) mod compact;
|
||||
pub(crate) mod config;
|
||||
pub(crate) mod constants;
|
||||
pub(crate) mod count;
|
||||
pub(crate) mod cp;
|
||||
pub(crate) mod date;
|
||||
pub(crate) mod debug;
|
||||
@ -72,6 +71,7 @@ pub(crate) mod insert;
|
||||
pub(crate) mod into_int;
|
||||
pub(crate) mod keep;
|
||||
pub(crate) mod last;
|
||||
pub(crate) mod length;
|
||||
pub(crate) mod let_;
|
||||
pub(crate) mod let_env;
|
||||
pub(crate) mod lines;
|
||||
@ -154,7 +154,6 @@ pub(crate) use compact::Compact;
|
||||
pub(crate) use config::{
|
||||
Config, ConfigClear, ConfigGet, ConfigLoad, ConfigPath, ConfigRemove, ConfigSet, ConfigSetInto,
|
||||
};
|
||||
pub(crate) use count::Count;
|
||||
pub(crate) use cp::Cpy;
|
||||
pub(crate) use date::{Date, DateFormat, DateListTimeZone, DateNow, DateToTable, DateToTimeZone};
|
||||
pub(crate) use debug::Debug;
|
||||
@ -212,6 +211,7 @@ pub(crate) use insert::Command as Insert;
|
||||
pub(crate) use into_int::IntoInt;
|
||||
pub(crate) use keep::{Keep, KeepUntil, KeepWhile};
|
||||
pub(crate) use last::Last;
|
||||
pub(crate) use length::Length;
|
||||
pub(crate) use let_::Let;
|
||||
pub(crate) use let_env::LetEnv;
|
||||
pub(crate) use lines::Lines;
|
||||
|
@ -57,7 +57,7 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
|
||||
whole_stream_command(Sleep),
|
||||
// Statistics
|
||||
whole_stream_command(Size),
|
||||
whole_stream_command(Count),
|
||||
whole_stream_command(Length),
|
||||
whole_stream_command(Benchmark),
|
||||
// Metadata
|
||||
whole_stream_command(Tags),
|
||||
|
@ -4,21 +4,21 @@ use nu_engine::WholeStreamCommand;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Signature, UntaggedValue, Value};
|
||||
|
||||
pub struct Count;
|
||||
pub struct Length;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CountArgs {
|
||||
pub struct LengthArgs {
|
||||
column: bool,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl WholeStreamCommand for Count {
|
||||
impl WholeStreamCommand for Length {
|
||||
fn name(&self) -> &str {
|
||||
"count"
|
||||
"length"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build("count").switch(
|
||||
Signature::build("length").switch(
|
||||
"column",
|
||||
"Calculate number of columns in table",
|
||||
Some('c'),
|
||||
@ -31,10 +31,10 @@ impl WholeStreamCommand for Count {
|
||||
|
||||
async fn run(&self, args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
let (CountArgs { column }, input) = args.process().await?;
|
||||
let (LengthArgs { column }, input) = args.process().await?;
|
||||
let rows: Vec<Value> = input.collect().await;
|
||||
|
||||
let count = if column {
|
||||
let length = if column {
|
||||
if rows.is_empty() {
|
||||
0
|
||||
} else {
|
||||
@ -42,8 +42,8 @@ impl WholeStreamCommand for Count {
|
||||
UntaggedValue::Row(dictionary) => dictionary.length(),
|
||||
_ => {
|
||||
return Err(ShellError::labeled_error(
|
||||
"Cannot obtain column count",
|
||||
"cannot obtain column count",
|
||||
"Cannot obtain column length",
|
||||
"cannot obtain column length",
|
||||
tag,
|
||||
));
|
||||
}
|
||||
@ -53,19 +53,21 @@ impl WholeStreamCommand for Count {
|
||||
rows.len()
|
||||
};
|
||||
|
||||
Ok(OutputStream::one(UntaggedValue::int(count).into_value(tag)))
|
||||
Ok(OutputStream::one(
|
||||
UntaggedValue::int(length).into_value(tag),
|
||||
))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Count the number of entries in a list",
|
||||
example: "echo [1 2 3 4 5] | count",
|
||||
example: "echo [1 2 3 4 5] | length",
|
||||
result: Some(vec![UntaggedValue::int(5).into()]),
|
||||
},
|
||||
Example {
|
||||
description: "Count the number of columns in the calendar table",
|
||||
example: "cal | count -c",
|
||||
example: "cal | length -c",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
@ -74,13 +76,13 @@ impl WholeStreamCommand for Count {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Count;
|
||||
use super::Length;
|
||||
use super::ShellError;
|
||||
|
||||
#[test]
|
||||
fn examples_work_as_expected() -> Result<(), ShellError> {
|
||||
use crate::examples::test as test_examples;
|
||||
|
||||
test_examples(Count {})
|
||||
test_examples(Length {})
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ fn cal_friday_the_thirteenths_in_2015() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 2015 | default friday 0 | where friday == 13 | count
|
||||
cal --full-year 2015 | default friday 0 | where friday == 13 | length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -45,7 +45,7 @@ fn cal_rows_in_2020() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal --full-year 2020 | count
|
||||
cal --full-year 2020 | length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -25,7 +25,7 @@ fn discards_rows_where_given_column_is_empty() {
|
||||
open los_tres_amigos.json
|
||||
| get amigos
|
||||
| compact rusty_luck
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -41,7 +41,7 @@ fn discards_empty_rows_by_default() {
|
||||
echo "[1,2,3,14,null]"
|
||||
| from json
|
||||
| compact
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -26,7 +26,7 @@ fn adds_row_data_if_column_missing() {
|
||||
| get amigos
|
||||
| default rusty_luck 1
|
||||
| where rusty_luck == 1
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -13,7 +13,7 @@ fn columns() {
|
||||
]
|
||||
| drop column
|
||||
| get
|
||||
| count
|
||||
| length
|
||||
"#)
|
||||
);
|
||||
|
||||
@ -62,7 +62,7 @@ fn rows() {
|
||||
|
||||
#[test]
|
||||
fn more_rows_than_table_has() {
|
||||
let actual = nu!(cwd: ".", "date | drop 50 | count");
|
||||
let actual = nu!(cwd: ".", "date | drop 50 | length");
|
||||
|
||||
assert_eq!(actual.out, "0");
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fn reports_emptiness() {
|
||||
| get are_empty
|
||||
| empty? check
|
||||
| where check
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -17,7 +17,7 @@ fn gets_first_rows_by_amount() {
|
||||
r#"
|
||||
ls
|
||||
| first 3
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -40,7 +40,7 @@ fn gets_all_rows_if_amount_higher_than_all_rows() {
|
||||
r#"
|
||||
ls
|
||||
| first 99
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -58,7 +58,7 @@ fn gets_first_row_when_no_amount_given() {
|
||||
r#"
|
||||
ls
|
||||
| first
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -71,7 +71,7 @@ fn flatten_row_column_explicitly() {
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten people | where name == Andres | count"
|
||||
"open katz.json | flatten people | where name == Andres | length"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "1");
|
||||
@ -105,7 +105,7 @@ fn flatten_row_columns_having_same_column_names_flats_separately() {
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten | flatten people city | get city_name | count"
|
||||
"open katz.json | flatten | flatten people city | get city_name | length"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
@ -139,7 +139,7 @@ fn flatten_table_columns_explicitly() {
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.json | flatten city | where people.name == Katz | count"
|
||||
"open katz.json | flatten city | where people.name == Katz | length"
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
|
@ -89,7 +89,7 @@ fn column_paths_are_either_double_quoted_or_regular_unquoted_words_separated_by_
|
||||
r#"
|
||||
open sample.toml
|
||||
| get package."9999"
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -21,7 +21,7 @@ fn groups() {
|
||||
open los_tres_caballeros.csv
|
||||
| group-by rusty_at
|
||||
| get "10/11/2013"
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn help_commands_count() {
|
||||
fn help_commands_length() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
help commands | count
|
||||
help commands | length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -16,11 +16,11 @@ fn help_commands_count() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_generate_docs_count() {
|
||||
fn help_generate_docs_length() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
help generate_docs | flatten | count
|
||||
help generate_docs | flatten | length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -27,7 +27,7 @@ fn gets_last_rows_by_amount() {
|
||||
r#"
|
||||
ls
|
||||
| last 3
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -45,7 +45,7 @@ fn gets_last_row_when_no_amount_given() {
|
||||
r#"
|
||||
ls
|
||||
| last
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -58,7 +58,7 @@ fn requests_more_rows_than_table_has() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
date | last 50 | count
|
||||
date | last 50 | length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn count_columns_in_cal_table() {
|
||||
fn length_columns_in_cal_table() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
cal | count -c
|
||||
cal | length -c
|
||||
"#
|
||||
));
|
||||
|
||||
@ -13,11 +13,11 @@ fn count_columns_in_cal_table() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn count_columns_no_rows() {
|
||||
fn length_columns_no_rows() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo [] | count -c
|
||||
echo [] | length -c
|
||||
"#
|
||||
));
|
||||
|
@ -42,7 +42,7 @@ fn lines_multi_value_split() {
|
||||
open sample-simple.json
|
||||
| get first second
|
||||
| lines
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -15,7 +15,7 @@ fn lists_regular_files() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -37,7 +37,7 @@ fn lists_regular_files_using_asterisk_wildcard() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls *.txt
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -59,7 +59,7 @@ fn lists_regular_files_using_question_mark_wildcard() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls *.??.txt
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -88,7 +88,7 @@ fn lists_all_files_in_directories_from_stream() {
|
||||
r#"
|
||||
echo dir_a dir_b
|
||||
| each { ls $it }
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -105,7 +105,7 @@ fn does_not_fail_if_glob_matches_empty_directory() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls dir_a
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -142,7 +142,7 @@ fn list_files_from_two_parents_up_using_multiple_dots() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test().join("foo/bar"),
|
||||
r#"
|
||||
ls ... | count
|
||||
ls ... | length
|
||||
"#
|
||||
);
|
||||
|
||||
@ -165,7 +165,7 @@ fn lists_hidden_file_when_explicitly_specified() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls .testdotfile
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -199,7 +199,7 @@ fn lists_all_hidden_files_when_glob_contains_dot() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls **/.*
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -236,7 +236,7 @@ fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls **/*
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -259,7 +259,7 @@ fn lists_files_including_starting_with_dot() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
ls -a
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -70,7 +70,7 @@ fn show_created_paths() {
|
||||
pipeline(
|
||||
r#"
|
||||
mkdir -s dir_1 dir_2 dir_3
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -5,7 +5,6 @@ mod autoenv_untrust;
|
||||
mod cal;
|
||||
mod cd;
|
||||
mod compact;
|
||||
mod count;
|
||||
mod cp;
|
||||
mod def;
|
||||
mod default;
|
||||
@ -28,6 +27,7 @@ mod insert;
|
||||
mod into_int;
|
||||
mod keep;
|
||||
mod last;
|
||||
mod length;
|
||||
mod lines;
|
||||
mod ls;
|
||||
mod math;
|
||||
|
@ -28,7 +28,7 @@ fn selects_many_rows() {
|
||||
ls
|
||||
| get name
|
||||
| nth 1 0
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -5,7 +5,7 @@ fn rolls_4_roll() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
random dice -d 4 -s 10 | count
|
||||
random dice -d 4 -s 10 | length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -36,7 +36,7 @@ fn selects_some_rows() {
|
||||
ls
|
||||
| get name
|
||||
| range 1..2
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -23,7 +23,7 @@ fn changes_the_column_name() {
|
||||
| wrap name
|
||||
| rename mosqueteros
|
||||
| get mosqueteros
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -53,7 +53,7 @@ fn keeps_remaining_original_names_given_less_new_names_than_total_original_names
|
||||
| default hit "arepa!"
|
||||
| rename mosqueteros
|
||||
| get hit
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -76,7 +76,7 @@ fn allows_if_given_unknown_column_name_is_missing() {
|
||||
[Yehuda Katz 10/11/2013 A]
|
||||
]
|
||||
| select rrusty_at first_name
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -22,7 +22,7 @@ fn splits() {
|
||||
| group-by rusty_at
|
||||
| split-by type
|
||||
| get A."10/11/2013"
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -19,7 +19,7 @@ fn to_row() {
|
||||
| lines
|
||||
| str trim
|
||||
| split row ","
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -22,7 +22,7 @@ fn removes_duplicate_rows() {
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
| uniq
|
||||
| count
|
||||
| length
|
||||
|
||||
"#
|
||||
));
|
||||
@ -52,7 +52,7 @@ fn uniq_values() {
|
||||
open los_tres_caballeros.csv
|
||||
| select type
|
||||
| uniq
|
||||
| count
|
||||
| length
|
||||
|
||||
"#
|
||||
));
|
||||
@ -117,7 +117,7 @@ fn nested_json_structures() {
|
||||
r#"
|
||||
open nested_json_structures.json
|
||||
| uniq
|
||||
| count
|
||||
| length
|
||||
|
||||
"#
|
||||
));
|
||||
@ -133,7 +133,7 @@ fn uniq_when_keys_out_of_order() {
|
||||
echo '[{"a": "a", "b": [1,2,3]},{"b": [1,2,3], "a": "a"}]'
|
||||
| from json
|
||||
| uniq
|
||||
| count
|
||||
| length
|
||||
|
||||
"#
|
||||
));
|
||||
|
@ -145,7 +145,7 @@ fn contains_operator() {
|
||||
| where table_name == strings
|
||||
| get table_values
|
||||
| where x =~ ell
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -158,7 +158,7 @@ fn contains_operator() {
|
||||
| where table_name == strings
|
||||
| get table_values
|
||||
| where x !~ ell
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -44,11 +44,11 @@ fn correct_precedence_alias_def_custom() {
|
||||
fn multiple_reports_for_alias_def_custom() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def ls [] {echo def}; alias ls = echo alias; which -a ls | count"
|
||||
"def ls [] {echo def}; alias ls = echo alias; which -a ls | length"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert!(count >= 3);
|
||||
let length: i32 = actual.out.parse().unwrap();
|
||||
assert!(length >= 3);
|
||||
}
|
||||
|
||||
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
|
||||
@ -61,11 +61,11 @@ fn multiple_reports_for_alias_def_custom() {
|
||||
fn multiple_reports_of_multiple_alias() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"alias xaz = echo alias1; def helper [] {alias xaz = echo alias2; which -a xaz}; helper | count"
|
||||
"alias xaz = echo alias1; def helper [] {alias xaz = echo alias2; which -a xaz}; helper | length"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(count, 2);
|
||||
let length: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(length, 2);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
@ -73,11 +73,11 @@ fn multiple_reports_of_multiple_alias() {
|
||||
fn multiple_reports_of_multiple_defs() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def xaz [] {echo def1}; def helper [] { def xaz [] { echo def2 }; which -a xaz }; helper | count"
|
||||
"def xaz [] {echo def1}; def helper [] { def xaz [] { echo def2 }; which -a xaz }; helper | length"
|
||||
);
|
||||
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(count, 2);
|
||||
let length: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(length, 2);
|
||||
}
|
||||
|
||||
//Fails due to ParserScope::add_definition
|
||||
@ -88,9 +88,9 @@ fn multiple_reports_of_multiple_defs() {
|
||||
fn def_only_seen_once() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
"def xaz [] {echo def1}; which -a xaz | count"
|
||||
"def xaz [] {echo def1}; which -a xaz | length"
|
||||
);
|
||||
//count is 2. One custom_command (def) one built in ("wrongly" added)
|
||||
let count: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(count, 1);
|
||||
//length is 2. One custom_command (def) one built in ("wrongly" added)
|
||||
let length: i32 = actual.out.parse().unwrap();
|
||||
assert_eq!(length, 1);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ fn infers_types() {
|
||||
r#"
|
||||
open los_cuatro_mosqueteros.csv
|
||||
| where rusty_luck > 0
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -120,7 +120,7 @@ fn from_csv_text_to_table() {
|
||||
open los_tres_caballeros.txt
|
||||
| from csv
|
||||
| get rusty_luck
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -147,7 +147,7 @@ fn from_csv_text_with_separator_to_table() {
|
||||
open los_tres_caballeros.txt
|
||||
| from csv --separator ';'
|
||||
| get rusty_luck
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -174,7 +174,7 @@ fn from_csv_text_with_tab_separator_to_table() {
|
||||
open los_tres_caballeros.txt
|
||||
| from csv --separator '\t'
|
||||
| get rusty_luck
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -200,7 +200,7 @@ fn from_csv_text_skipping_headers_to_table() {
|
||||
open los_tres_amigos.txt
|
||||
| from csv --noheaders
|
||||
| get Column3
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -48,7 +48,7 @@ fn infers_types() {
|
||||
r#"
|
||||
open calendar.ics
|
||||
| get events
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -36,7 +36,7 @@ fn from_json_text_to_table() {
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"open katz.txt | from json | get katz | get rusty_luck | count "
|
||||
"open katz.txt | from json | get katz | get rusty_luck | length "
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
|
@ -97,7 +97,7 @@ fn from_tsv_text_to_table() {
|
||||
open los_tres_amigos.txt
|
||||
| from tsv
|
||||
| get rusty_luck
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
@ -123,7 +123,7 @@ fn from_tsv_text_skipping_headers_to_table() {
|
||||
open los_tres_amigos.txt
|
||||
| from tsv --noheaders
|
||||
| get Column3
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -35,7 +35,7 @@ fn infers_types() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open contacts.vcf
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# count
|
||||
# length
|
||||
|
||||
Obtain the row or column count of a table.
|
||||
|
||||
@ -36,31 +36,31 @@ Obtain the row or column count of a table.
|
||||
────┴────────────────────┴──────┴──────────┴──────────────
|
||||
```
|
||||
|
||||
By default, `count` will return the number of rows in a table
|
||||
By default, `length` will return the number of rows in a table
|
||||
|
||||
```shell
|
||||
> ls | count
|
||||
> ls | length
|
||||
20
|
||||
```
|
||||
|
||||
The `-c` flag will produce a count of the columns in the table
|
||||
|
||||
```shell
|
||||
> ls | count -c
|
||||
> ls | length -c
|
||||
4
|
||||
```
|
||||
|
||||
```shell
|
||||
> ls | where type == File | count
|
||||
> ls | where type == File | length
|
||||
11
|
||||
```
|
||||
|
||||
```shell
|
||||
> ls | where type == Dir | count
|
||||
> ls | where type == Dir | length
|
||||
9
|
||||
```
|
||||
|
||||
```shell
|
||||
> ls | where size > 2KB | count
|
||||
> ls | where size > 2KB | length
|
||||
4
|
||||
```
|
4
tests/fixtures/formats/script_multiline.nu
vendored
4
tests/fixtures/formats/script_multiline.nu
vendored
@ -1,2 +1,2 @@
|
||||
echo [1 4] | count
|
||||
echo [2 3 5] | count
|
||||
echo [1 4] | length
|
||||
echo [2 3 5] | length
|
||||
|
@ -207,7 +207,7 @@ fn given_a_trusted_directory_with_entry_scripts_when_entering_a_subdirectory_ent
|
||||
let actual = Trusted::in_path(&dirs, || {
|
||||
nu!(cwd: dirs.test(), r#"
|
||||
cd time_to_cook_arepas
|
||||
ls | where name == "hello.txt" | count
|
||||
ls | where name == "hello.txt" | length
|
||||
"#)
|
||||
});
|
||||
|
||||
@ -238,7 +238,7 @@ fn given_a_trusted_directory_with_exit_scripts_when_entering_a_subdirectory_exit
|
||||
let actual = Trusted::in_path(&dirs, || {
|
||||
nu!(cwd: dirs.test(), r#"
|
||||
cd time_to_cook_arepas
|
||||
ls | where name == "bye.txt" | count
|
||||
ls | where name == "bye.txt" | length
|
||||
"#)
|
||||
});
|
||||
|
||||
|
@ -126,7 +126,7 @@ mod it_evaluation {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
nu --testbin repeater c 8197 | lines | count
|
||||
nu --testbin repeater c 8197 | lines | length
|
||||
"#
|
||||
);
|
||||
|
||||
@ -165,7 +165,7 @@ mod stdin_evaluation {
|
||||
cwd: ".",
|
||||
pipeline(r#"
|
||||
nu --testbin nonu "where's the nuline?"
|
||||
| count
|
||||
| length
|
||||
"#
|
||||
));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user