@@ -71,14 +71,59 @@ func TestSplitTypes(t *testing.T) {
7171 }
7272}
7373
74+ func TestSplitUint64 (t * testing.T ) {
75+ tests := []struct {
76+ input string
77+ val uint64
78+ rest string
79+ err error
80+ }{
81+ {"01" , 1 , "" , nil },
82+ {"7FFF" , 0x7F , "FF" , nil },
83+ {"80FF" , 0 , "FF" , nil },
84+ {"81FAFF" , 0xFA , "FF" , nil },
85+ {"82FAFAFF" , 0xFAFA , "FF" , nil },
86+ {"83FAFAFAFF" , 0xFAFAFA , "FF" , nil },
87+ {"84FAFAFAFAFF" , 0xFAFAFAFA , "FF" , nil },
88+ {"85FAFAFAFAFAFF" , 0xFAFAFAFAFA , "FF" , nil },
89+ {"86FAFAFAFAFAFAFF" , 0xFAFAFAFAFAFA , "FF" , nil },
90+ {"87FAFAFAFAFAFAFAFF" , 0xFAFAFAFAFAFAFA , "FF" , nil },
91+ {"88FAFAFAFAFAFAFAFAFF" , 0xFAFAFAFAFAFAFAFA , "FF" , nil },
92+
93+ // errors
94+ {"" , 0 , "" , io .ErrUnexpectedEOF },
95+ {"00" , 0 , "00" , ErrCanonInt },
96+ {"81" , 0 , "81" , ErrValueTooLarge },
97+ {"8100" , 0 , "8100" , ErrCanonSize },
98+ {"8200FF" , 0 , "8200FF" , ErrCanonInt },
99+ {"8103FF" , 0 , "8103FF" , ErrCanonSize },
100+ {"89FAFAFAFAFAFAFAFAFAFF" , 0 , "89FAFAFAFAFAFAFAFAFAFF" , errUintOverflow },
101+ }
102+
103+ for i , test := range tests {
104+ val , rest , err := SplitUint64 (unhex (test .input ))
105+ if val != test .val {
106+ t .Errorf ("test %d: val mismatch: got %x, want %x (input %q)" , i , val , test .val , test .input )
107+ }
108+ if ! bytes .Equal (rest , unhex (test .rest )) {
109+ t .Errorf ("test %d: rest mismatch: got %x, want %s (input %q)" , i , rest , test .rest , test .input )
110+ }
111+ if err != test .err {
112+ t .Errorf ("test %d: error mismatch: got %q, want %q" , i , err , test .err )
113+ }
114+ }
115+ }
116+
74117func TestSplit (t * testing.T ) {
75118 tests := []struct {
76119 input string
77120 kind Kind
78121 val , rest string
79122 err error
80123 }{
124+ {input : "00FFFF" , kind : Byte , val : "00" , rest : "FFFF" },
81125 {input : "01FFFF" , kind : Byte , val : "01" , rest : "FFFF" },
126+ {input : "7FFFFF" , kind : Byte , val : "7F" , rest : "FFFF" },
82127 {input : "80FFFF" , kind : String , val : "" , rest : "FFFF" },
83128 {input : "C3010203" , kind : List , val : "010203" },
84129
0 commit comments