forked from extern/nushell
Remove math eval
command (#7284)
Reasoning: Most missing math commands are implemented with #7258. The `meval` crate itself declares that it doesn't strive to stringent standards (https://docs.rs/meval/latest/meval/#related-projects). For example no particular special casing or transformations are performed to ensure numerical stability. It uses the same rust `std` library functions we use or have access to (and `f64`). While the command call syntax in nushell may be a bit more verbose, having a single source of truth and common commands is beneficial. Furthermore the `math` commands can themselves implement broadcasting over lists (or table columns). Closes #7073 Removed dependencies: - `meval` - `nom 1.2.4` (duplicate) User-Facing Changes: Scripts using `math eval` will break. We remove a further `eval` like behavior to get results through runtime evaluation (albeit limited in scope) Tests: - Updated tests that internally used `math eval`. - Removed one test that primarily used `math eval` to obtain a result from `str join`
This commit is contained in:
committed by
GitHub
parent
429127793f
commit
9bc4e6794d
@ -1,85 +0,0 @@
|
||||
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'));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_two_to_the_power_four() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "2 ^ 4" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("16"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_three_multiplied_by_five() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "3 * 5" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("15"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_twenty_four_divided_by_two() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
echo "24 / 2" | math eval
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("12"));
|
||||
}
|
||||
|
||||
#[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"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn evaluates_tau() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
math eval tau
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.out.contains("6.28"));
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
mod avg;
|
||||
mod eval;
|
||||
mod median;
|
||||
mod round;
|
||||
mod sqrt;
|
||||
|
@ -8,7 +8,7 @@ fn reduce_table_column() {
|
||||
echo "[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]"
|
||||
| from json
|
||||
| get total
|
||||
| reduce -f 20 { |it, acc| $it + (math eval $"($acc)^1.05")}
|
||||
| reduce -f 20 { |it, acc| $it + $acc ** 1.05}
|
||||
| into string -d 1
|
||||
"#
|
||||
)
|
||||
@ -23,7 +23,7 @@ fn reduce_table_column_with_path() {
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
[{month:2,total:30}, {month:3,total:10}, {month:4,total:3}, {month:5,total:60}]
|
||||
| reduce -f 20 { |it, acc| $it.total + (math eval $"($acc)^1.05")}
|
||||
| reduce -f 20 { |it, acc| $it.total + $acc ** 1.05}
|
||||
| into string -d 1
|
||||
"#
|
||||
)
|
||||
|
@ -38,16 +38,3 @@ fn construct_a_path() {
|
||||
|
||||
assert_eq!(actual.out, "sample.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sum_one_to_four() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
1..4 | each { |it| $it } | into string | str join "+" | math eval
|
||||
"#
|
||||
)
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("10"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user