1
0
Fork 0
mirror of https://github.com/imjasonh/testscript-rs synced 2026-07-09 01:26:40 +00:00
testscript-rs/tests/unicode_handling.rs
copilot-swe-agent[bot] 48254a93e1 Add explicit Unicode mode to all regex patterns for proper Unicode handling
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
2025-10-12 15:08:50 +00:00

188 lines
5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Tests for Unicode handling in stdout/stderr pattern matching
use std::fs;
use tempfile::TempDir;
use testscript_rs::testscript;
#[test]
fn test_unicode_stdout_exact_match() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test with Unicode checkmark
let test_content = r#"exec echo "Success ✓"
stdout "Success ✓"
"#;
let test_file = testdata_dir.join("unicode_stdout_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Unicode stdout exact match should work: {:?}",
result
);
}
#[test]
fn test_unicode_stderr_exact_match() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test with Unicode checkmark in stderr
let test_content = r#"exec sh -c 'echo "Error ✗" >&2'
stderr "Error ✗"
"#;
let test_file = testdata_dir.join("unicode_stderr_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Unicode stderr exact match should work: {:?}",
result
);
}
#[test]
fn test_unicode_regex_match() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test with Unicode in regex pattern
let test_content = r#"exec echo "Success ✓ completed"
stdout "Success .* completed"
"#;
let test_file = testdata_dir.join("unicode_regex_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Unicode in regex pattern should work: {:?}",
result
);
}
#[test]
fn test_multiple_unicode_chars() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test with multiple Unicode characters
let test_content = r#"exec echo "Tests: ✓ ✗ ⚠ "
stdout "Tests: ✓ ✗ ⚠ "
"#;
let test_file = testdata_dir.join("multi_unicode_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Multiple Unicode characters should work: {:?}",
result
);
}
#[test]
fn test_emoji_in_output() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test with emoji
let test_content = r#"exec echo "Status: 🎉 Success!"
stdout "Status: 🎉 Success!"
"#;
let test_file = testdata_dir.join("emoji_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(result.is_ok(), "Emoji in output should work: {:?}", result);
}
#[test]
fn test_unicode_with_special_chars() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test Unicode with characters that trigger regex mode
let test_content = r#"exec echo "Result: ✓ (success)"
stdout "Result: ✓ \(success\)"
"#;
let test_file = testdata_dir.join("unicode_special_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Unicode with regex special chars should work: {:?}",
result
);
}
#[test]
fn test_dot_matches_unicode_in_regex() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test if . in regex matches Unicode characters
let test_content = r#"exec echo "A✓B"
stdout "A.B"
"#;
let test_file = testdata_dir.join("dot_unicode_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Dot in regex should match Unicode character: {:?}",
result
);
}
#[test]
fn test_grep_with_unicode() {
let temp_dir = TempDir::new().unwrap();
let testdata_dir = temp_dir.path().join("testdata");
fs::create_dir(&testdata_dir).unwrap();
// Test grep command with Unicode content
let test_content = r#"grep "Success.*✓" test.txt
stdout "test.txt:1: Success ✓"
-- test.txt --
Success ✓
"#;
let test_file = testdata_dir.join("grep_unicode_test.txt");
fs::write(&test_file, test_content).unwrap();
let result = testscript::run(testdata_dir.to_string_lossy()).execute();
assert!(
result.is_ok(),
"Grep with Unicode should work: {:?}",
result
);
}