-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for IsHexValid function
- Loading branch information
1 parent
97f99b8
commit 1e69fef
Showing
2 changed files
with
44 additions
and
3 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,41 @@ | ||
package types | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsHexValid(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
s string | ||
want bool | ||
}{ | ||
{ | ||
name: "valid hex without 0x prefix", | ||
s: "76616c69642068657820776974686f757420307820707265666978", | ||
want: true, | ||
}, | ||
{ | ||
name: "valid hex with 0x prefix", | ||
s: "0x76616c696420686578207769746820307820707265666978", | ||
want: true, | ||
}, | ||
{ | ||
name: "invalid hex without 0x prefix", | ||
s: "76616c696invalid07769746820307820707265666978", | ||
want: false, | ||
}, | ||
{ | ||
name: "invalid hex with 0x prefix", | ||
s: "0x76616c696invalid07769746820307820707265666978", | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
require.Equal(t, tt.want, IsHexValid(tt.s)) | ||
}) | ||
} | ||
} |