Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/csplit/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub fn get_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
fn extract_patterns(args: &[String]) -> Result<Vec<Pattern>, CsplitError> {
let mut patterns = Vec::with_capacity(args.len());
let to_match_reg =
Regex::new(r"^(/(?P<UPTO>.+)/|%(?P<SKIPTO>.+)%)(?P<OFFSET>[\+-]?\d+)?$").unwrap();
let execute_ntimes_reg = Regex::new(r"^\{(?P<TIMES>\d+)|\*\}$").unwrap();
Regex::new(r"^(/(?P<UPTO>.+)/|%(?P<SKIPTO>.+)%)(?P<OFFSET>[\+-]?[0-9]+)?$").unwrap();
let execute_ntimes_reg = Regex::new(r"^\{(?P<TIMES>[0-9]+)|\*\}$").unwrap();
let mut iter = args.iter().peekable();

while let Some(arg) = iter.next() {
Expand Down
18 changes: 18 additions & 0 deletions tests/by-util/test_csplit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ fn test_up_to_line_sequence() {
assert_eq!(at.read("xx02"), generate(25, 51));
}

#[test]
fn test_up_to_line_with_non_ascii_repeat() {
// we use a different error message than GNU
new_ucmd!()
.args(&["numbers50.txt", "10", "{𝟚}"])
.fails()
.stderr_contains("invalid pattern");
}

#[test]
fn test_up_to_match() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down Expand Up @@ -167,6 +176,15 @@ fn test_up_to_match_offset_repeat_twice() {
assert_eq!(at.read("xx03"), generate(32, 51));
}

#[test]
fn test_up_to_match_non_ascii_offset() {
// we use a different error message than GNU
new_ucmd!()
.args(&["numbers50.txt", "/9$/𝟚"])
.fails()
.stderr_contains("invalid pattern");
}

#[test]
fn test_up_to_match_negative_offset() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading