mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
sort: support multiple input files
This commit is contained in:
parent
87455f998a
commit
3bc5a5f769
5 changed files with 48 additions and 20 deletions
|
@ -123,6 +123,7 @@ With no FILE, or when FILE is -, read standard input.", NAME, VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(files: Vec<String>, settings: &Settings) {
|
fn exec(files: Vec<String>, settings: &Settings) {
|
||||||
|
let mut lines = Vec::new();
|
||||||
for path in &files {
|
for path in &files {
|
||||||
let (reader, _) = match open(path) {
|
let (reader, _) = match open(path) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
|
@ -130,7 +131,6 @@ fn exec(files: Vec<String>, settings: &Settings) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let buf_reader = BufReader::new(reader);
|
let buf_reader = BufReader::new(reader);
|
||||||
let mut lines = Vec::new();
|
|
||||||
|
|
||||||
for line in buf_reader.lines() {
|
for line in buf_reader.lines() {
|
||||||
match line {
|
match line {
|
||||||
|
@ -140,6 +140,7 @@ fn exec(files: Vec<String>, settings: &Settings) {
|
||||||
_ => break
|
_ => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match settings.mode {
|
match settings.mode {
|
||||||
SortMode::Numeric => lines.sort_by(numeric_compare),
|
SortMode::Numeric => lines.sort_by(numeric_compare),
|
||||||
|
@ -160,7 +161,6 @@ fn exec(files: Vec<String>, settings: &Settings) {
|
||||||
print_sorted(iter, &settings.outfile)
|
print_sorted(iter, &settings.outfile)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse the beginning string into an f64, returning -inf instead of NaN on errors.
|
/// Parse the beginning string into an f64, returning -inf instead of NaN on errors.
|
||||||
fn permissive_f64_parse(a: &str) -> f64 {
|
fn permissive_f64_parse(a: &str) -> f64 {
|
||||||
|
|
9
tests/fixtures/sort/multiple_files.expected
vendored
Normal file
9
tests/fixtures/sort/multiple_files.expected
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
4
tests/fixtures/sort/multiple_files1.txt
vendored
Normal file
4
tests/fixtures/sort/multiple_files1.txt
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
3
|
||||||
|
7
|
||||||
|
2
|
||||||
|
5
|
5
tests/fixtures/sort/multiple_files2.txt
vendored
Normal file
5
tests/fixtures/sort/multiple_files2.txt
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
4
|
||||||
|
8
|
||||||
|
1
|
||||||
|
9
|
||||||
|
6
|
|
@ -52,6 +52,16 @@ fn test_version() {
|
||||||
test_helper("version", "-V");
|
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 out = ucmd.run().stdout;
|
||||||
|
assert_eq!(out, at.read("multiple_files.expected"));
|
||||||
|
}
|
||||||
|
|
||||||
fn test_helper(file_name: &str, args: &str) {
|
fn test_helper(file_name: &str, args: &str) {
|
||||||
let (at, mut ucmd) = testing(UTIL_NAME);
|
let (at, mut ucmd) = testing(UTIL_NAME);
|
||||||
ucmd.arg(args);
|
ucmd.arg(args);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue