Require column name(s) in sort-by (#7041)

This commit is contained in:
Reilly Wood
2022-11-09 14:16:51 -08:00
committed by GitHub
parent da8f6c5682
commit 2201bd9b09
4 changed files with 63 additions and 111 deletions

View 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);
}

View File

@ -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"));
}