aboutsummaryrefslogtreecommitdiffstats
path: root/common/hexutil/hexutil_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-02-23 00:59:59 +0800
committerFelix Lange <fjl@twurst.com>2017-03-02 21:05:46 +0800
commitd304da380382245190f33878363696cd151201a9 (patch)
treeae1791944e79a9ea741fb447a6346309e4b016c7 /common/hexutil/hexutil_test.go
parent357d00cdb1625e4a715e0b3928ef7bd3656a8d95 (diff)
downloaddexon-d304da380382245190f33878363696cd151201a9.tar
dexon-d304da380382245190f33878363696cd151201a9.tar.gz
dexon-d304da380382245190f33878363696cd151201a9.tar.bz2
dexon-d304da380382245190f33878363696cd151201a9.tar.lz
dexon-d304da380382245190f33878363696cd151201a9.tar.xz
dexon-d304da380382245190f33878363696cd151201a9.tar.zst
dexon-d304da380382245190f33878363696cd151201a9.zip
common/hexutil: implement TextMarshaler, TextUnmarshaler
This commit makes the wrapper types more generally applicable. encoding.TextMarshaler is supported by most codec implementations (e.g. for yaml). The tests now ensure that package json actually recognizes the custom marshaler implementation irrespective of how it is implemented. The Uint type has new tests, too. These are tricky because uint size depends on the CPU word size. Turns out that there was one incorrect case where decoding returned ErrUint64Range instead of ErrUintRange.
Diffstat (limited to 'common/hexutil/hexutil_test.go')
-rw-r--r--common/hexutil/hexutil_test.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/common/hexutil/hexutil_test.go b/common/hexutil/hexutil_test.go
index d18f08833..6a92a385c 100644
--- a/common/hexutil/hexutil_test.go
+++ b/common/hexutil/hexutil_test.go
@@ -28,9 +28,10 @@ type marshalTest struct {
}
type unmarshalTest struct {
- input string
- want interface{}
- wantErr error
+ input string
+ want interface{}
+ wantErr error // if set, decoding must fail on any platform
+ wantErr32bit error // if set, decoding must fail on 32bit platforms (used for Uint tests)
}
var (
@@ -55,6 +56,13 @@ var (
{uint64(0x1122334455667788), "0x1122334455667788"},
}
+ encodeUintTests = []marshalTest{
+ {uint(0), "0x0"},
+ {uint(1), "0x1"},
+ {uint(0xff), "0xff"},
+ {uint(0x11223344), "0x11223344"},
+ }
+
decodeBytesTests = []unmarshalTest{
// invalid
{input: ``, wantErr: ErrEmptyString},