emit: allow to emit Null

This commit is contained in:
Evgenii Stratonikov 2020-08-04 12:03:31 +03:00
parent e5d973d3a4
commit a3f419f8df
2 changed files with 7 additions and 3 deletions

View file

@ -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)))

View file

@ -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) {