aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/sqlvm/runtime/instructions_op_test.go
diff options
context:
space:
mode:
authorMeng-Ying Yang <garfield@dexon.org>2019-04-08 10:32:36 +0800
committerJhih-Ming Huang <jm.huang@cobinhood.com>2019-05-06 10:44:05 +0800
commitc07255382a10bdeaf7d5d2411e9c7c4cdc937694 (patch)
tree2a0fbb3fb3d6e0f546ee4cb09912c36bdb487953 /core/vm/sqlvm/runtime/instructions_op_test.go
parent64c440d58f8eea970487b39bf231696932464159 (diff)
downloaddexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar.gz
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar.bz2
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar.lz
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar.xz
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.tar.zst
dexon-c07255382a10bdeaf7d5d2411e9c7c4cdc937694.zip
core: vm: sqlvm: add opConcat
Add `opConcat` supports dynamic bytes (string) concating.
Diffstat (limited to 'core/vm/sqlvm/runtime/instructions_op_test.go')
-rw-r--r--core/vm/sqlvm/runtime/instructions_op_test.go80
1 files changed, 80 insertions, 0 deletions
diff --git a/core/vm/sqlvm/runtime/instructions_op_test.go b/core/vm/sqlvm/runtime/instructions_op_test.go
index e0550006f..6c10a2e87 100644
--- a/core/vm/sqlvm/runtime/instructions_op_test.go
+++ b/core/vm/sqlvm/runtime/instructions_op_test.go
@@ -1321,6 +1321,86 @@ func (s *instructionSuite) TestOpMod() {
s.run(testcases, opMod)
}
+func (s *instructionSuite) TestOpConcat() {
+ testcases := []opTestcase{
+ {
+ "Concat bytes",
+ Instruction{
+ Op: CONCAT,
+ Input: []*Operand{
+ makeOperand(
+ false,
+ []ast.DataType{
+ ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0), ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0),
+ },
+ []Tuple{
+ {&Raw{Bytes: []byte("abc-1")}, &Raw{Bytes: []byte("xyz-1")}},
+ {&Raw{Bytes: []byte("abc-2")}, &Raw{Bytes: []byte("xyz-2")}},
+ },
+ ),
+ makeOperand(
+ false,
+ []ast.DataType{
+ ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0), ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0),
+ },
+ []Tuple{
+ {&Raw{Bytes: []byte("ABC-1")}, &Raw{Bytes: []byte("XYZ-1")}},
+ {&Raw{Bytes: []byte("ABC-2")}, &Raw{Bytes: []byte("XYZ-2")}},
+ },
+ ),
+ },
+ Output: 0,
+ },
+ makeOperand(
+ false,
+ []ast.DataType{
+ ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0), ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0),
+ },
+ []Tuple{
+ {&Raw{Bytes: []byte("abc-1ABC-1")}, &Raw{Bytes: []byte("xyz-1XYZ-1")}},
+ {&Raw{Bytes: []byte("abc-2ABC-2")}, &Raw{Bytes: []byte("xyz-2XYZ-2")}},
+ },
+ ),
+ nil,
+ },
+ {
+ "Invalid concat",
+ Instruction{
+ Op: CONCAT,
+ Input: []*Operand{
+ makeOperand(
+ false,
+ []ast.DataType{
+ ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0), ast.ComposeDataType(ast.DataTypeMajorBool, 0),
+ },
+ []Tuple{
+ {&Raw{Bytes: []byte("abc-1")}, rawTrue},
+ },
+ ),
+ makeOperand(
+ false,
+ []ast.DataType{
+ ast.ComposeDataType(ast.DataTypeMajorDynamicBytes, 0), ast.ComposeDataType(ast.DataTypeMajorBool, 0),
+ },
+ []Tuple{
+ {&Raw{Bytes: []byte("ABC-1")}, rawFalse},
+ },
+ ),
+ },
+ Output: 0,
+ },
+ makeOperand(
+ false,
+ []ast.DataType{},
+ []Tuple{},
+ ),
+ errors.ErrorCodeInvalidDataType,
+ },
+ }
+
+ s.run(testcases, opConcat)
+}
+
func (s *instructionSuite) TestOpLt() {
testcases := []opTestcase{
{