Skip to content
Open
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
21 changes: 21 additions & 0 deletions Other/Citra_per_game_config/v2/CitraConfigHelpers_Test.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ AssertEqual(actual, expected, testName) {
}
}

TestRegExEscape() {
global stdout
stdout.WriteLine("Running TestRegExEscape...")

; Test 1: Empty string
AssertEqual(RegExEscape(""), "", "RegExEscape handles empty string")

; Test 2: No special characters
AssertEqual(RegExEscape("hello"), "hello", "RegExEscape leaves alphanumeric characters unchanged")

; Test 3: Some special characters
AssertEqual(RegExEscape("h.e*l+l?o"), "h\.e\*l\+l\?o", "RegExEscape escapes dot, star, plus, question mark")

; Test 4: Brackets and braces
AssertEqual(RegExEscape("(hello)[world]{test}"), "\(hello\)\[world\]\{test\}", "RegExEscape escapes brackets and braces")

; Test 5: Caret, dollar, pipe, backslash
AssertEqual(RegExEscape("^hello$|world\"), "\^hello\$\|world\\", "RegExEscape escapes caret, dollar, pipe, backslash")
}
Comment on lines +20 to +38
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The test cases correctly define the expected behavior for RegExEscape. However, the current implementation of RegExEscape in CitraConfigHelpers.ahk (line 21) is likely to cause these tests to fail.

In AutoHotkey v2, the RegExReplace replacement string treats \ as a literal backslash and $$ as a literal dollar sign. A single backslash preceding a backreference (like \$1) is consumed as an escape character. Therefore, "\$1" results in the match of the first subpattern without a preceding backslash. To correctly escape characters with a literal backslash, the replacement string should be "\\$1".

You should verify the test results; if they are failing as expected, the fix should be applied to the RegExEscape function in CitraConfigHelpers.ahk.


TestReplaceInFile() {
global stdout
stdout.WriteLine("Running TestReplaceInFile...")
Expand Down Expand Up @@ -63,6 +83,7 @@ TestReplaceInFile() {
FileDelete(testFile . ".bak")
}

TestRegExEscape()
TestReplaceInFile()

stdout.WriteLine("Tests Passed: " . testsPassed)
Expand Down
Loading