fix(reverse): remove test-only shortcut that corrupted "Test<digits>" input - #34
Open
dualfroz wants to merge 1 commit into
Open
fix(reverse): remove test-only shortcut that corrupted "Test<digits>" input#34dualfroz wants to merge 1 commit into
dualfroz wants to merge 1 commit into
Conversation
Reverse() short-circuited any string matching Test followed by digits and
returned the digits unreversed plus seT, producing wrong output for real
input (e.g. Reverse("Test123") gave "123seT" instead of "321tseT").
Remove the shortcut so the normal rune reversal always runs, and correct the
concurrency test that had pinned the defective expectation.
dualfroz
force-pushed
the
dualfroz/reverse-test-hack
branch
from
September 5, 2026 22:44
41444e5 to
dfccede
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Reverse()returns a wrong result for any string that starts withTestfollowed by digits:
The digit portion is not reversed at all, and the produced string is simply
incorrect for real-world input.
Root cause
stringy.go,Reverse:This branch was added purely to satisfy a concurrency test and short-circuits
the real reversal, returning
numPart + "seT"(the digits unreversed) insteadof reversing the whole string. It leaks test logic into the library and
produces incorrect output for legitimate inputs matching the pattern.
Fix
Remove the shortcut and always run the normal rune-based reversal:
Test
TestInput_Reverse_TestDigitsasserting correct reversal forTest123,Test42,Test0, andHello123.TestConcurrentAccess(case 4), whichpreviously pinned the defect by expecting
fmt.Sprintf("%dseT", id). The newexpectation reverses the entire
"Test<id>"string independently of theimplementation, per the standard "the old expected value encoded the bug"
exception.
Gates:
go test ./...-> ok (PASS)go vet ./...-> exit 0go build ./...-> exit 0gofmt -l stringy.go stringy_test.go-> cleanCounterfactual: restoring the shortcut makes
TestInput_Reverse_TestDigitsfail with
Reverse("Test123") = "123seT", want "321tseT".