|
| 1 | +"""Tests for the escape_regex_special_chars function in common.py""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from common import escape_regex_special_chars |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + "input_text, expected_output", |
| 9 | + [ |
| 10 | + # Special regex characters that should be escaped |
| 11 | + ("file.name", "file\\.name"), |
| 12 | + ("file*name", "file\\*name"), |
| 13 | + ("file+name", "file\\+name"), |
| 14 | + ("file?name", "file\\?name"), |
| 15 | + ("file(name)", "file\\(name\\)"), |
| 16 | + ("file[name]", "file\\[name\\]"), |
| 17 | + ("file{name}", "file\\{name\\}"), |
| 18 | + ("file^name", "file\\^name"), |
| 19 | + ("file$name", "file\\$name"), |
| 20 | + ("file|name", "file\\|name"), |
| 21 | + |
| 22 | + # Normal text (no special characters) |
| 23 | + ("normal_text", "normal_text"), |
| 24 | + ("hello world", "hello\\ world"), |
| 25 | + |
| 26 | + # Edge cases |
| 27 | + ("", ""), |
| 28 | + ("a", "a"), |
| 29 | + ("123", "123"), |
| 30 | + ], |
| 31 | +) |
| 32 | +def test_escape_regex_special_chars(input_text, expected_output): |
| 33 | + """Test that escape_regex_special_chars correctly escapes regex special characters.""" |
| 34 | + result = escape_regex_special_chars(input_text) |
| 35 | + assert result == expected_output |
| 36 | + |
0 commit comments