-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f94bf1b
commit decf642
Showing
4 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ethfull | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
func sanitizeABIStructName(rustABIStructName string) string { | ||
reg := regexp.MustCompile("_+") | ||
|
||
result := reg.ReplaceAllStringFunc(rustABIStructName, func(s string) string { | ||
count := len(s) | ||
|
||
replacement := strings.Repeat("_u", count-1) + "_" | ||
|
||
return replacement | ||
}) | ||
|
||
return result | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ethfull | ||
|
||
import ( | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestSanitizeStructABI(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
inputStructAbiName string | ||
expectedName string | ||
}{ | ||
{ | ||
inputStructAbiName: "foo_bar", | ||
expectedName: "foo_bar", | ||
}, | ||
{ | ||
inputStructAbiName: "foo___bar", | ||
expectedName: "foo_u_u_bar", | ||
}, | ||
{ | ||
inputStructAbiName: "__foo_bar", | ||
expectedName: "_u_foo_bar", | ||
}, | ||
{ | ||
inputStructAbiName: "foobar__", | ||
expectedName: "foobar_u_", | ||
}, | ||
{ | ||
inputStructAbiName: "__foobar", | ||
expectedName: "_u_foobar", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.inputStructAbiName, func(t *testing.T) { | ||
result := sanitizeABIStructName(c.inputStructAbiName) | ||
require.Equal(t, c.expectedName, result) | ||
}) | ||
} | ||
} |
This file contains 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