mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 23:22:32 +02:00
Convert sum command into subcommand of the math command (#2004)
* Convert sum command into subcommand of the math command * Add bullet points to math.md documentation
This commit is contained in:
@ -4,7 +4,7 @@ use nu_test_support::nu;
|
||||
fn drop_rows() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | sum | echo $it"#
|
||||
r#"echo '[{"foo": 3}, {"foo": 8}, {"foo": 4}]' | from json | drop 2 | get foo | math sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
|
@ -5,7 +5,7 @@ fn each_works_separately() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
echo [1 2 3] | each { echo $it 10 | sum } | to json | echo $it
|
||||
echo [1 2 3] | each { echo $it 10 | math sum } | to json | echo $it
|
||||
"#
|
||||
));
|
||||
|
||||
|
@ -22,7 +22,7 @@ fn adds_value_provided_if_column_is_empty() {
|
||||
open likes.csv
|
||||
| empty? likes 1
|
||||
| get likes
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
@ -43,7 +43,7 @@ fn adds_value_provided_for_columns_that_are_empty() {
|
||||
{"boost": 1, "check": {}},
|
||||
{"boost": null, "check": ["" {} [] ""]}
|
||||
]
|
||||
|
||||
|
||||
"#,
|
||||
)]);
|
||||
|
||||
@ -53,7 +53,7 @@ fn adds_value_provided_for_columns_that_are_empty() {
|
||||
open checks.json
|
||||
| empty? boost check 1
|
||||
| get boost check
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -22,7 +22,7 @@ fn rows() {
|
||||
open caballeros.csv
|
||||
| keep 3
|
||||
| get lucky_code
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -41,7 +41,7 @@ fn condition_is_met() {
|
||||
| keep-until "Chicken Collection" == "Red Chickens"
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -41,7 +41,7 @@ fn condition_is_met() {
|
||||
| keep-while "Chicken Collection" != "Blue Chickens"
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -33,7 +33,7 @@ fn row() {
|
||||
| merge { open new_caballeros.csv }
|
||||
| where country in: ["Guayaquil Ecuador" "New Zealand"]
|
||||
| get luck
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -40,7 +40,7 @@ fn condition_is_met() {
|
||||
| skip-until "Chicken Collection" == "Red Chickens"
|
||||
| str to-int "31/04/2020"
|
||||
| get "31/04/2020"
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
|
@ -108,7 +108,7 @@ fn converts_to_decimal() {
|
||||
echo "3.1, 0.0415"
|
||||
| split row ","
|
||||
| str to-decimal
|
||||
| sum
|
||||
| math sum
|
||||
"#
|
||||
));
|
||||
|
||||
@ -130,7 +130,7 @@ fn sets() {
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open sample.toml
|
||||
| str set wykittenshell package.name
|
||||
| str set wykittenshell package.name
|
||||
| get package.name
|
||||
| echo $it
|
||||
"#
|
||||
|
@ -25,7 +25,7 @@ fn all() {
|
||||
open meals.json
|
||||
| get meals
|
||||
| get calories
|
||||
| sum
|
||||
| math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
@ -53,7 +53,7 @@ fn outputs_zero_with_no_input() {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
sum
|
||||
math sum
|
||||
| echo $it
|
||||
"#
|
||||
));
|
||||
@ -74,7 +74,7 @@ fn compute_sum_of_individual_row() -> Result<(), String> {
|
||||
for (column_name, expected_value) in answers_for_columns.iter() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
format!("open sample-ps-output.json | select {} | sum | get {}", column_name, column_name)
|
||||
format!("open sample-ps-output.json | select {} | math sum | get {}", column_name, column_name)
|
||||
);
|
||||
let result =
|
||||
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;
|
||||
@ -95,7 +95,7 @@ fn compute_sum_of_table() -> Result<(), String> {
|
||||
for (column_name, expected_value) in answers_for_columns.iter() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
format!("open sample-ps-output.json | select cpu mem virtual | sum | get {}", column_name)
|
||||
format!("open sample-ps-output.json | select cpu mem virtual | math sum | get {}", column_name)
|
||||
);
|
||||
let result =
|
||||
f64::from_str(&actual.out).map_err(|_| String::from("Failed to parse float."))?;
|
||||
@ -108,7 +108,7 @@ fn compute_sum_of_table() -> Result<(), String> {
|
||||
fn sum_of_a_row_containing_a_table_is_an_error() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats/",
|
||||
"open sample-sys-output.json | sum"
|
||||
"open sample-sys-output.json | math sum"
|
||||
);
|
||||
assert!(actual
|
||||
.err
|
||||
|
@ -14,7 +14,7 @@ fn filters_by_unit_size_comparison() {
|
||||
fn filters_with_nothing_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | get foo | compact | where $it > 1 | sum | echo $it"#
|
||||
r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | get foo | compact | where $it > 1 | math sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "7");
|
||||
@ -24,7 +24,7 @@ fn filters_with_nothing_comparison() {
|
||||
fn where_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name in: ["foo"] | get size | sum | echo $it"#
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name in: ["foo"] | get size | math sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "5");
|
||||
@ -34,7 +34,7 @@ fn where_in_table() {
|
||||
fn where_not_in_table() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name not-in: ["foo"] | get size | sum | echo $it"#
|
||||
r#"echo '[{"name": "foo", "size": 3}, {"name": "foo", "size": 2}, {"name": "bar", "size": 4}]' | from json | where name not-in: ["foo"] | get size | math sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
|
Reference in New Issue
Block a user