emit: allow to emit Null
This commit is contained in:
parent
e5d973d3a4
commit
a3f419f8df
2 changed files with 7 additions and 3 deletions
|
@ -79,8 +79,11 @@ func Array(w *io.BinWriter, es ...interface{}) {
|
||||||
case bool:
|
case bool:
|
||||||
Bool(w, e)
|
Bool(w, e)
|
||||||
default:
|
default:
|
||||||
w.Err = errors.New("unsupported type")
|
if es[i] != nil {
|
||||||
return
|
w.Err = errors.New("unsupported type")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
Opcode(w, opcode.PUSHNULL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Int(w, int64(len(es)))
|
Int(w, int64(len(es)))
|
||||||
|
|
|
@ -142,7 +142,7 @@ func TestBytes(t *testing.T) {
|
||||||
func TestEmitArray(t *testing.T) {
|
func TestEmitArray(t *testing.T) {
|
||||||
t.Run("good", func(t *testing.T) {
|
t.Run("good", func(t *testing.T) {
|
||||||
buf := io.NewBufBinWriter()
|
buf := io.NewBufBinWriter()
|
||||||
Array(buf.BinWriter, int64(1), "str", true, []byte{0xCA, 0xFE})
|
Array(buf.BinWriter, nil, int64(1), "str", true, []byte{0xCA, 0xFE})
|
||||||
require.NoError(t, buf.Err)
|
require.NoError(t, buf.Err)
|
||||||
|
|
||||||
res := buf.Bytes()
|
res := buf.Bytes()
|
||||||
|
@ -154,6 +154,7 @@ func TestEmitArray(t *testing.T) {
|
||||||
assert.EqualValues(t, 3, res[6])
|
assert.EqualValues(t, 3, res[6])
|
||||||
assert.EqualValues(t, []byte("str"), res[7:10])
|
assert.EqualValues(t, []byte("str"), res[7:10])
|
||||||
assert.EqualValues(t, opcode.PUSH1, res[10])
|
assert.EqualValues(t, opcode.PUSH1, res[10])
|
||||||
|
assert.EqualValues(t, opcode.PUSHNULL, res[11])
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("empty", func(t *testing.T) {
|
t.Run("empty", func(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue