Skip to content

Commit

Permalink
Merge pull request #56 from kzys/fix-panic
Browse files Browse the repository at this point in the history
Handle multiple patterns with submatches
  • Loading branch information
dmcgowan authored Nov 7, 2022
2 parents 14832cc + 82a18e9 commit 168a8ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/go-fix-acronym/rewrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func rewriteNode(pattern *regexp.Regexp, node ast.Node) {
}

for i := 0; i < len(match); i += 2 {
if match[i] == -1 {
continue
}
result += ident.Name[copied:match[i]]
result += strings.ToUpper(ident.Name[match[i]:match[i+1]])
copied = match[i+1]
Expand Down
17 changes: 16 additions & 1 deletion cmd/go-fix-acronym/rewrite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func testRewrite(t *testing.T, input, expected string, c config) {
}
}

func TestRewriteSimple(t *testing.T) {
func TestRewrite(t *testing.T) {
testcases := []struct {
name string
input string
Expand Down Expand Up @@ -81,6 +81,21 @@ func TestRewriteSimple(t *testing.T) {
func KernelTime_100Ns() {}
func RuntimeNSAndNsAndSomeSuffix() {}`,
},
{
name: "Multiple submatches",
c: config{acronyms: []string{"(Id|Vm)$", "[a-z](Ns)$"}},
input: `package main
func Vm() {}
func Time_100Ns() {}
func RuntimeNs() {}
`,
expected: `package main
func VM() {}
func Time_100Ns() {}
func RuntimeNS() {}`,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
Expand Down

0 comments on commit 168a8ea

Please sign in to comment.