Sort primitives explictly. (#2016)

* Sort primitives explictly.

* Write backing up test.
This commit is contained in:
Andrés N. Robalino 2020-06-19 23:34:36 -05:00 committed by GitHub
parent fcbaefed52
commit b0c30098e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -1,4 +1,5 @@
use crate::commands::WholeStreamCommand;
use crate::data::base::coerce_compare;
use crate::prelude::*;
use nu_errors::ShellError;
use nu_protocol::{Signature, SyntaxShape, UntaggedValue, Value};
@ -112,7 +113,7 @@ pub fn sort(
value: UntaggedValue::Primitive(_),
..
} => {
vec.sort();
vec.sort_by(|a, b| coerce_compare(a, b).expect("Unimplemented BUG: What about primitives that don't have an order defined?").compare());
}
_ => {
let calc_key = |item: &Value| {

View File

@ -27,3 +27,17 @@ fn median_numbers_with_odd_rows() {
assert_eq!(actual.out, "10.5")
}
#[test]
fn median_mixed_numbers() {
let actual = nu!(
cwd: ".", pipeline(
r#"
echo [-11.5 -13.5 10]
| math median
| echo $it
"#
));
assert_eq!(actual.out, "-11.5")
}