more cleanup

int
This commit is contained in:
rigel rozanski
2017-07-07 01:27:29 -04:00
parent 82c0f98235
commit 1821f8bd7a
5 changed files with 6 additions and 53 deletions
-23
View File
@@ -1,23 +0,0 @@
package commands
import "encoding/hex"
// Returns true for non-empty hex-string prefixed with "0x"
func isHex(s string) bool {
if len(s) > 2 && s[:2] == "0x" {
_, err := hex.DecodeString(s[2:])
if err != nil {
return false
}
return true
}
return false
}
// StripHex remove the first two hex bytes
func StripHex(s string) string {
if isHex(s) {
return s[2:]
}
return s
}
-24
View File
@@ -1,24 +0,0 @@
package commands
import (
"encoding/hex"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHex(t *testing.T) {
assert := assert.New(t)
//test isHex
hexNoPrefix := hex.EncodeToString([]byte("foobar"))
hexWPrefix := "0x" + hexNoPrefix
str := "foobar"
strWPrefix := "0xfoobar"
assert.True(isHex(hexWPrefix), "isHex not identifying hex with 0x prefix")
assert.False(isHex(hexNoPrefix), "isHex shouldn't identify hex without 0x prefix")
assert.False(isHex(str), "isHex shouldn't identify non-hex string")
assert.False(isHex(strWPrefix), "isHex shouldn't identify non-hex string with 0x prefix")
assert.True(StripHex(hexWPrefix) == hexNoPrefix, "StripHex doesn't remove first two characters")
}