mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Sort primitives explictly. (#2016)
* Sort primitives explictly. * Write backing up test.
This commit is contained in:
parent
fcbaefed52
commit
b0c30098e4
@ -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| {
|
||||
|
@ -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")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user