Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
add more tests
  • Loading branch information
notJoon committed Jun 9, 2024
commit d18841ea60c35285aa8bc6e01aa6c98fd112d1d1
28 changes: 25 additions & 3 deletions src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2667,14 +2667,36 @@ mod tests {
}

#[test]
fn test_non_ascii_utf8() {
let haystack = "아스키문자는 아닌데 UTF-8 문자열".as_bytes();
fn test_debug_output_various_unicode() {
let haystack =
"Hello, 😊 world! 안녕하세요? مرحبا بالعالم!".as_bytes();
let m = Match::new(haystack, 0, haystack.len());
let debug_str = format!("{:?}", m);

assert_eq!(
debug_str,
r#"Match { start: 0, end: 44, bytes: "아스키문자는 아닌데 UTF-8 문자열" }"#
r#"Match { start: 0, end: 62, bytes: "Hello, 😊 world! 안녕하세요? مرحبا بالعالم!" }"#
);
}

#[test]
fn test_debug_output_ascii_escape() {
let haystack = b"Hello,\tworld!\nThis is a \x1b[31mtest\x1b[0m.";
let m = Match::new(haystack, 0, haystack.len());
let debug_str = format!("{:?}", m);

assert_eq!(
debug_str,
r#"Match { start: 0, end: 38, bytes: "Hello,\tworld!\nThis is a \u{1b}[31mtest\u{1b}[0m." }"#
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some tests with non-ASCII UTF-8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added along with other tests.
d18841e


#[test]
fn test_debug_output_match_in_middle() {
let haystack = b"The quick brown fox jumps over the lazy dog.";
let m = Match::new(haystack, 16, 19);
let debug_str = format!("{:?}", m);

assert_eq!(debug_str, r#"Match { start: 16, end: 19, bytes: "fox" }"#);
}
}