mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:55:07 +02:00
Require column name(s) in sort-by (#7041)
This commit is contained in:
48
crates/nu-command/tests/commands/sort.rs
Normal file
48
crates/nu-command/tests/commands/sort.rs
Normal file
@ -0,0 +1,48 @@
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
|
||||
#[test]
|
||||
fn by_invalid_types() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| echo ["foo" 1]
|
||||
| sort
|
||||
| to json -r
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[1,"foo"]"#;
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_primitive_values() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| lines
|
||||
| skip 1
|
||||
| first 6
|
||||
| sort
|
||||
| first
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "authors = [\"The Nushell Project Developers\"]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_different_types() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
[a, 1, b, 2, c, 3, [4, 5, 6], d, 4, [1, 2, 3]] | sort | to json --raw
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[1,2,3,4,"a","b","c","d",[1,2,3],[4,5,6]]"#;
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
@ -43,39 +43,6 @@ fn by_invalid_column() {
|
||||
assert!(actual.err.contains("value originates here"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn by_invalid_types() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| echo ["foo" 1]
|
||||
| sort-by
|
||||
| to json -r
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[1,"foo"]"#;
|
||||
assert_eq!(actual.out, json_output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_primitive_values() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
open cargo_sample.toml --raw
|
||||
| lines
|
||||
| skip 1
|
||||
| first 6
|
||||
| sort-by
|
||||
| first
|
||||
"#
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "authors = [\"The Nushell Project Developers\"]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_sort_by_name_sensitive() {
|
||||
let actual = nu!(
|
||||
@ -142,14 +109,13 @@ fn ls_sort_by_type_name_insensitive() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sort_different_types() {
|
||||
fn no_column_specified_fails() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
[a, 1, b, 2, c, 3, [4, 5, 6], d, 4, [1, 2, 3]] | sort-by | to json --raw
|
||||
[2 0 1] | sort-by
|
||||
"#
|
||||
));
|
||||
|
||||
let json_output = r#"[1,2,3,4,"a","b","c","d",[1,2,3],[4,5,6]]"#;
|
||||
assert_eq!(actual.out, json_output);
|
||||
assert!(actual.err.contains("missing parameter"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user