mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 17:25:15 +02:00
Rename calc
to math eval
and allow it to optionally take an expression as an argument (#2195)
* Rename `calc` to `math eval` and allow it to optionally take the expression as an argument * Moved calc tests to math eval Also added 2 tests and changed 1 test * Move calc docs to math eval
This commit is contained in:
@ -1,49 +0,0 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn calculates_two_plus_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "2 + 2" | calc
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("4.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calculates_two_to_the_power_six() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "2 ^ 6" | calc
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("64.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calculates_three_multiplied_by_five() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "3 * 5" | calc
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("15.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn calculates_twenty_four_divided_by_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "24 / 2" | calc
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("12.0"));
|
||||
}
|
73
crates/nu-cli/tests/commands/math/eval.rs
Normal file
73
crates/nu-cli/tests/commands/math/eval.rs
Normal file
@ -0,0 +1,73 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn evaluates_two_plus_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval "2 + 2"
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("4.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_two_to_the_power_four() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "2 ^ 4" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("16.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_three_multiplied_by_five() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "3 * 5" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("15.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_twenty_four_divided_by_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "24 / 2" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("12.0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_twenty_eight_minus_seven() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "28 - 7" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("21"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_pi() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval pi
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("3.14"));
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
mod avg;
|
||||
mod eval;
|
||||
mod median;
|
||||
mod sum;
|
||||
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
|
@ -4,7 +4,6 @@ mod autoenv;
|
||||
mod autoenv_trust;
|
||||
mod autoenv_untrust;
|
||||
mod cal;
|
||||
mod calc;
|
||||
mod cd;
|
||||
mod compact;
|
||||
mod cp;
|
||||
|
Reference in New Issue
Block a user