File tree Expand file tree Collapse file tree 2 files changed +77
-0
lines changed
tools/generators/ethereum Expand file tree Collapse file tree 2 files changed +77
-0
lines changed Original file line number Diff line number Diff line change @@ -275,10 +275,18 @@ func buildEventInfo(eventsByName map[string]abi.Event) []eventInfo {
275275}
276276
277277func uppercaseFirst (str string ) string {
278+ if len (str ) == 0 {
279+ return str
280+ }
281+
278282 return strings .ToUpper (str [0 :1 ]) + str [1 :]
279283}
280284
281285func lowercaseFirst (str string ) string {
286+ if len (str ) == 0 {
287+ return str
288+ }
289+
282290 return strings .ToLower (str [0 :1 ]) + str [1 :]
283291}
284292
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import "testing"
4+
5+ func TestLowercaseFirst (t * testing.T ) {
6+ var tests = map [string ]struct {
7+ input string
8+ expected string
9+ }{
10+ "empty string" : {
11+ input : "" ,
12+ expected : "" ,
13+ },
14+ "first lower case" : {
15+ input : "helloWorld" ,
16+ expected : "helloWorld" ,
17+ },
18+ "first upper case" : {
19+ input : "HelloWorld" ,
20+ expected : "helloWorld" ,
21+ },
22+ }
23+
24+ for testName , test := range tests {
25+ t .Run (testName , func (t * testing.T ) {
26+ actual := lowercaseFirst (test .input )
27+ if actual != test .expected {
28+ t .Errorf (
29+ "unexpected output\n expected: [%v]\n actual: [%v]" ,
30+ test .expected ,
31+ actual ,
32+ )
33+ }
34+ })
35+ }
36+ }
37+
38+ func TestUppercaseFirst (t * testing.T ) {
39+ var tests = map [string ]struct {
40+ input string
41+ expected string
42+ }{
43+ "empty string" : {
44+ input : "" ,
45+ expected : "" ,
46+ },
47+ "first upper case" : {
48+ input : "HelloWorld" ,
49+ expected : "HelloWorld" ,
50+ },
51+ "first lower case" : {
52+ input : "helloWorld" ,
53+ expected : "HelloWorld" ,
54+ },
55+ }
56+
57+ for testName , test := range tests {
58+ t .Run (testName , func (t * testing.T ) {
59+ actual := uppercaseFirst (test .input )
60+ if actual != test .expected {
61+ t .Errorf (
62+ "unexpected output\n expected: [%v]\n actual: [%v]" ,
63+ test .expected ,
64+ actual ,
65+ )
66+ }
67+ })
68+ }
69+ }
You can’t perform that action at this time.
0 commit comments