-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Starke
committed
Sep 25, 2023
1 parent
9d2838c
commit ef4fc67
Showing
5 changed files
with
51 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::io::{BufReader, Cursor, BufRead}; | ||
use lazy_regex::regex; | ||
use assert_cmd::Command; | ||
|
||
/// tests if the result of `mactime2` is a stable sort, i.e. if pos(a)<=pos(b) then sorted_pos(a) <= sorted_pos(b) | ||
#[test] | ||
fn is_stable_sorted() { | ||
let mut cmd = Command::cargo_bin("mactime2").unwrap(); | ||
|
||
let sample_bodyfile = | ||
"0|a|1703937|d/drwxr-xr-x|0|0|4096|1661774613|1661774613|1661774613|1661774613 | ||
0|b|11|d/drwx------|0|0|16384|1661774613|1661774613|1661774613|1661774613 | ||
0|c|11|d/drwx------|0|0|16384|1661774613|1661774613|1661774613|1661774613"; | ||
|
||
let result = cmd | ||
.arg("-d") | ||
.arg("-b") | ||
.arg("-") | ||
.write_stdin(sample_bodyfile) | ||
.ok(); | ||
assert!(result.is_ok()); | ||
|
||
let reader = BufReader::new(Cursor::new(result.unwrap().stdout)); | ||
let lines: Vec<_> = reader | ||
.lines() | ||
.map_while(Result::ok) | ||
.map(name_of) | ||
.collect(); | ||
assert_eq!(lines.len(), 3); | ||
assert_eq!(lines[0].as_ref().unwrap(), "a"); | ||
assert_eq!(lines[1].as_ref().unwrap(), "b"); | ||
assert_eq!(lines[2].as_ref().unwrap(), "c"); | ||
} | ||
|
||
fn name_of(line: String) -> Option<String> { | ||
let re = regex!(r#""(?P<name>[^"]*)""#); | ||
let result = re.captures_iter(&line); | ||
for c in result { | ||
if let Some(name) = c.name("name") { | ||
return Some(name.as_str().to_owned()) | ||
} | ||
} | ||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod help; | ||
mod autocomplete; | ||
mod is_sorted; | ||
mod is_sorted; | ||
mod is_stable_sorting; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.