mirror of
https://github.com/imjasonh/testscript-rs
synced 2026-07-07 00:33:38 +00:00
Add explicit Unicode mode to regex patterns for proper Unicode handling (#40)
This commit is contained in:
parent
2dfdbc818d
commit
d059265fa1
11 changed files with 40 additions and 4 deletions
|
|
@ -71,9 +71,9 @@ fn run(params: &mut RunParams, test_data_glob: &str) -> Result<()> {
|
|||
(".", test_data_glob)
|
||||
};
|
||||
|
||||
// Convert glob pattern to a simple matcher
|
||||
// Convert glob pattern to a simple matcher with Unicode support
|
||||
let pattern_regex = pattern.replace("*", ".*");
|
||||
let regex = regex::Regex::new(&format!("^{}$", pattern_regex))?;
|
||||
let regex = regex::Regex::new(&format!("(?u)^{}$", pattern_regex))?;
|
||||
|
||||
// Walk the directory and collect matching files
|
||||
for entry in WalkDir::new(base_dir).min_depth(1).max_depth(1) {
|
||||
|
|
|
|||
|
|
@ -218,7 +218,14 @@ impl TestEnvironment {
|
|||
|
||||
/// Search for a pattern in files (like grep)
|
||||
pub fn grep_files(&mut self, pattern: &str, files: &[String]) -> Result<()> {
|
||||
let regex = Regex::new(pattern)
|
||||
// Enable Unicode mode for proper Unicode character matching in grep patterns
|
||||
let pattern_with_flags = if pattern.starts_with("(?") {
|
||||
// Pattern already has flags, don't add more
|
||||
pattern.to_string()
|
||||
} else {
|
||||
format!("(?u){}", pattern)
|
||||
};
|
||||
let regex = Regex::new(&pattern_with_flags)
|
||||
.map_err(|e| Error::command_error("grep", format!("Invalid regex: {}", e)))?;
|
||||
|
||||
let mut _found_matches = false;
|
||||
|
|
|
|||
|
|
@ -236,7 +236,9 @@ impl TestEnvironment {
|
|||
|| expected_substituted.contains('*')
|
||||
|| expected_substituted.contains('.')
|
||||
{
|
||||
let regex_pattern = format!("(?s){}", expected_substituted); // (?s) enables DOTALL mode
|
||||
// Enable DOTALL mode (?s) for . to match newlines
|
||||
// Enable Unicode mode (?u) for proper Unicode character matching
|
||||
let regex_pattern = format!("(?su){}", expected_substituted);
|
||||
let regex = Regex::new(®ex_pattern)
|
||||
.map_err(|e| Error::command_error(output_type, format!("Invalid regex: {}", e)))?;
|
||||
|
||||
|
|
|
|||
3
testdata/unicode_dot_regex.txt
vendored
Normal file
3
testdata/unicode_dot_regex.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test if . in regex matches Unicode characters
|
||||
exec echo "A✓B"
|
||||
stdout "A.B"
|
||||
3
testdata/unicode_emoji.txt
vendored
Normal file
3
testdata/unicode_emoji.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test emoji in output
|
||||
exec echo "Status: 🎉 Success!"
|
||||
stdout "Status: 🎉 Success!"
|
||||
6
testdata/unicode_grep.txt
vendored
Normal file
6
testdata/unicode_grep.txt
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Test grep command with Unicode content
|
||||
grep "Success.*✓" test.txt
|
||||
stdout "test.txt:1: Success ✓"
|
||||
|
||||
-- test.txt --
|
||||
Success ✓
|
||||
3
testdata/unicode_multiple.txt
vendored
Normal file
3
testdata/unicode_multiple.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test multiple Unicode characters
|
||||
exec echo "Tests: ✓ ✗ ⚠ ℹ"
|
||||
stdout "Tests: ✓ ✗ ⚠ ℹ"
|
||||
3
testdata/unicode_regex.txt
vendored
Normal file
3
testdata/unicode_regex.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test Unicode in regex pattern
|
||||
exec echo "Success ✓ completed"
|
||||
stdout "Success .* completed"
|
||||
3
testdata/unicode_special_chars.txt
vendored
Normal file
3
testdata/unicode_special_chars.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test Unicode with regex special characters
|
||||
exec echo "Result: ✓ (success)"
|
||||
stdout "Result: ✓ \(success\)"
|
||||
3
testdata/unicode_stderr.txt
vendored
Normal file
3
testdata/unicode_stderr.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test Unicode checkmark in stderr exact match
|
||||
exec sh -c 'echo "Error ✗" >&2'
|
||||
stderr "Error ✗"
|
||||
3
testdata/unicode_stdout.txt
vendored
Normal file
3
testdata/unicode_stdout.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Test Unicode checkmark in stdout exact match
|
||||
exec echo "Success ✓"
|
||||
stdout "Success ✓"
|
||||
Loading…
Add table
Add a link
Reference in a new issue