add in the Value List to the sort-by Ordering (#4464)
This commit is contained in:
parent
7a3aeaf080
commit
06f5affc0b
|
@ -282,6 +282,7 @@ Arbitrary Order of Values:
|
||||||
Ints
|
Ints
|
||||||
Strings
|
Strings
|
||||||
Bools
|
Bools
|
||||||
|
Lists
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result<Ordering, ShellError> {
|
pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result<Ordering, ShellError> {
|
||||||
|
@ -305,6 +306,9 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result<Orderi
|
||||||
CompareValues::Booleans(*left, *right).compare()
|
CompareValues::Booleans(*left, *right).compare()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Not sure how to compare and sort lists
|
||||||
|
(Value::List { .. }, Value::List { .. }) => Ordering::Equal,
|
||||||
|
|
||||||
// Floats will always come before Ints
|
// Floats will always come before Ints
|
||||||
(Value::Float { .. }, Value::Int { .. }) => Ordering::Less,
|
(Value::Float { .. }, Value::Int { .. }) => Ordering::Less,
|
||||||
(Value::Int { .. }, Value::Float { .. }) => Ordering::Greater,
|
(Value::Int { .. }, Value::Float { .. }) => Ordering::Greater,
|
||||||
|
@ -317,6 +321,10 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result<Orderi
|
||||||
(Value::Float { .. }, Value::Bool { .. }) => Ordering::Less,
|
(Value::Float { .. }, Value::Bool { .. }) => Ordering::Less,
|
||||||
(Value::Bool { .. }, Value::Float { .. }) => Ordering::Greater,
|
(Value::Bool { .. }, Value::Float { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
|
// Floats will always come before Lists
|
||||||
|
(Value::Float { .. }, Value::List { .. }) => Ordering::Less,
|
||||||
|
(Value::List { .. }, Value::Float { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
// Ints will always come before strings
|
// Ints will always come before strings
|
||||||
(Value::Int { .. }, Value::String { .. }) => Ordering::Less,
|
(Value::Int { .. }, Value::String { .. }) => Ordering::Less,
|
||||||
(Value::String { .. }, Value::Int { .. }) => Ordering::Greater,
|
(Value::String { .. }, Value::Int { .. }) => Ordering::Greater,
|
||||||
|
@ -325,10 +333,22 @@ pub fn coerce_compare(left: &Value, right: &Value, call: &Call) -> Result<Orderi
|
||||||
(Value::Int { .. }, Value::Bool { .. }) => Ordering::Less,
|
(Value::Int { .. }, Value::Bool { .. }) => Ordering::Less,
|
||||||
(Value::Bool { .. }, Value::Int { .. }) => Ordering::Greater,
|
(Value::Bool { .. }, Value::Int { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
|
// Ints will always come before Lists
|
||||||
|
(Value::Int { .. }, Value::List { .. }) => Ordering::Less,
|
||||||
|
(Value::List { .. }, Value::Int { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
// Strings will always come before Bools
|
// Strings will always come before Bools
|
||||||
(Value::String { .. }, Value::Bool { .. }) => Ordering::Less,
|
(Value::String { .. }, Value::Bool { .. }) => Ordering::Less,
|
||||||
(Value::Bool { .. }, Value::String { .. }) => Ordering::Greater,
|
(Value::Bool { .. }, Value::String { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
|
// Strings will always come before Lists
|
||||||
|
(Value::String { .. }, Value::List { .. }) => Ordering::Less,
|
||||||
|
(Value::List { .. }, Value::String { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
|
// Bools will always come before Lists
|
||||||
|
(Value::Bool { .. }, Value::List { .. }) => Ordering::Less,
|
||||||
|
(Value::List { .. }, Value::Bool { .. }) => Ordering::Greater,
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
let description = format!("not able to compare {:?} with {:?}\n", left, right);
|
let description = format!("not able to compare {:?} with {:?}\n", left, right);
|
||||||
return Err(ShellError::TypeMismatch(description, call.head));
|
return Err(ShellError::TypeMismatch(description, call.head));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user