mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-25 18:51:39 +00:00
autofile
cli
clist
common
LICENSE
array.go
async.go
bit_array.go
bit_array_test.go
bytes.go
bytes_test.go
byteslice.go
cmap.go
cmap_test.go
colors.go
date.go
date_test.go
errors.go
heap.go
int.go
int_test.go
io.go
kvpair.go
math.go
net.go
net_test.go
os.go
os_test.go
random.go
random_test.go
repeat_timer.go
repeat_timer_test.go
service.go
service_test.go
string.go
string_test.go
throttle_timer.go
throttle_timer_test.go
types.pb.go
types.proto
word.go
db
events
flowrate
log
merkle
pubsub
test
version
.editorconfig
.gitignore
CHANGELOG.md
CODEOWNERS
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
circle.yml
glide.lock
glide.yaml
merge.sh
test.sh
IsHex should also successfully decode strings prefixed with 0X instead of only 0x strings. Also add tests generally for IsHex.
33 lines
791 B
Go
33 lines
791 B
Go
package common
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStringInSlice(t *testing.T) {
|
|
assert.True(t, StringInSlice("a", []string{"a", "b", "c"}))
|
|
assert.False(t, StringInSlice("d", []string{"a", "b", "c"}))
|
|
assert.True(t, StringInSlice("", []string{""}))
|
|
assert.False(t, StringInSlice("", []string{}))
|
|
}
|
|
|
|
func TestIsHex(t *testing.T) {
|
|
notHex := []string{
|
|
"", " ", "a", "x", "0", "0x", "0X", "0x ", "0X ", "0X a",
|
|
"0xf ", "0x f", "0xp", "0x-",
|
|
"0xf", "0XBED", "0xF", "0xbed", // Odd lengths
|
|
}
|
|
for _, v := range notHex {
|
|
assert.False(t, IsHex(v), "%q is not hex", v)
|
|
}
|
|
hex := []string{
|
|
"0x00", "0x0a", "0x0F", "0xFFFFFF", "0Xdeadbeef", "0x0BED",
|
|
"0X12", "0X0A",
|
|
}
|
|
for _, v := range hex {
|
|
assert.True(t, IsHex(v), "%q is hex", v)
|
|
}
|
|
}
|