1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

Merge pull request #898 from palaviv/improve-sort

Improve sort
This commit is contained in:
Heather 2016-06-15 01:05:12 +04:00 committed by GitHub
commit 46c420bdf0
11 changed files with 153 additions and 22 deletions

8
tests/fixtures/sort/check_fail.txt vendored Normal file
View file

@ -0,0 +1,8 @@
1
2
3
4
6
5
9
8

View file

@ -0,0 +1,9 @@
1
2
3
4
5
6
7
8
9

View file

@ -0,0 +1,4 @@
3
7
2
5

View file

@ -0,0 +1,5 @@
4
8
1
9
6

View file

@ -0,0 +1,4 @@
1
2
3
4

View file

@ -0,0 +1,7 @@
4
2
4
3
3
2
1

4
tests/fixtures/sort/version.expected vendored Normal file
View file

@ -0,0 +1,4 @@
1.2.3-alpha
1.2.3-alpha2
1.12.4
11.2.3

4
tests/fixtures/sort/version.txt vendored Normal file
View file

@ -0,0 +1,4 @@
11.2.3
1.2.3-alpha2
1.2.3-alpha
1.12.4

View file

@ -42,11 +42,51 @@ fn test_default_unsorted_ints() {
test_helper("default_unsorted_ints", "");
}
#[test]
fn test_numeric_unique_ints() {
test_helper("numeric_unsorted_ints_unique", "-nu");
}
#[test]
fn test_version() {
test_helper("version", "-V");
}
#[test]
fn test_multiple_files() {
let (at, mut ucmd) = testing(UTIL_NAME);
ucmd.arg("-n");
ucmd.arg("multiple_files1.txt");
ucmd.arg("multiple_files2.txt");
let res = ucmd.run();
assert_eq!(res.success, true);
assert_eq!(res.stdout, at.read("multiple_files.expected"));
}
#[test]
fn test_check() {
let (_, mut ucmd) = testing(UTIL_NAME);
ucmd.arg("-c");
let res = ucmd.arg("check_fail.txt").run();
assert_eq!(res.success, false);
assert_eq!(res.stdout, "sort: disorder in line 4\n");
let (_, mut ucmd) = testing(UTIL_NAME);
ucmd.arg("-c");
let res = ucmd.arg("multiple_files.expected").run();
assert_eq!(res.success, true);
assert_eq!(res.stdout, "");
}
fn test_helper(file_name: &str, args: &str) {
let (at, mut ucmd) = testing(UTIL_NAME);
ucmd.arg(args);
let out = ucmd.arg(format!("{}{}", file_name, ".txt")).run().stdout;
let res = ucmd.arg(format!("{}{}", file_name, ".txt")).run();
assert_eq!(res.success, true);
let filename = format!("{}{}", file_name, ".expected");
assert_eq!(out, at.read(&filename));
assert_eq!(res.stdout, at.read(&filename));
}