diff --git a/src/box/tuple_update.cc b/src/box/tuple_update.cc index 5e9a83b6ac1d2edd6eb2543bcdc9dd6faef18340..bb25f2897a71a9f4a66a4939b25fcae63e262811 100644 --- a/src/box/tuple_update.cc +++ b/src/box/tuple_update.cc @@ -294,9 +294,9 @@ do_op_arith(struct tuple_update *update, struct update_op *op, case '+': arg->val += val; break; case '&': arg->val &= val; break; case '^': arg->val ^= val; break; - case '|': arg->val |= val; - case '-': - default: arg->val = val - arg->val; break; + case '|': arg->val |= val; break; + case '-': arg->val = val - arg->val; break; + default: assert(false); /* checked by update_read_ops */ } op->new_field_len = mp_sizeof_uint(arg->val); } diff --git a/test/box/update.result b/test/box/update.result index 55e0a8fe226c4b3de3121ca067352f943660893b..8b5a6c36f6adc5d3f9f57c670f94becc58e2e1ad 100644 --- a/test/box/update.result +++ b/test/box/update.result @@ -32,6 +32,54 @@ s:update({1000005}, {{'#', 0, 1}}) s:truncate() --- ... +-- test arithmetic +s:insert{1, 0} +--- +- [1, 0] +... +s:update(1, {{'+', 1, 10}}) +--- +- [1, 10] +... +s:update(1, {{'+', 1, 15}}) +--- +- [1, 25] +... +s:update(1, {{'-', 1, 5}}) +--- +- [1, 20] +... +s:update(1, {{'-', 1, 20}}) +--- +- [1, 0] +... +s:update(1, {{'|', 1, 0x9}}) +--- +- [1, 9] +... +s:update(1, {{'|', 1, 0x6}}) +--- +- [1, 15] +... +s:update(1, {{'&', 1, 0xabcde}}) +--- +- [1, 14] +... +s:update(1, {{'&', 1, 0x2}}) +--- +- [1, 2] +... +s:update(1, {{'^', 1, 0xa2}}) +--- +- [1, 160] +... +s:update(1, {{'^', 1, 0xa2}}) +--- +- [1, 2] +... +s:truncate() +--- +... -- test delete multiple fields s:insert{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} --- diff --git a/test/box/update.test.lua b/test/box/update.test.lua index 4d532c3a0a04928340c549ea3a2def192d6ff699..24c367851987078e51f0dbb0ba7e3ede68a0684a 100644 --- a/test/box/update.test.lua +++ b/test/box/update.test.lua @@ -10,6 +10,20 @@ s:update({1000004}, {{'#', 0, 1}}) s:update({1000005}, {{'#', 0, 1}}) s:truncate() +-- test arithmetic +s:insert{1, 0} +s:update(1, {{'+', 1, 10}}) +s:update(1, {{'+', 1, 15}}) +s:update(1, {{'-', 1, 5}}) +s:update(1, {{'-', 1, 20}}) +s:update(1, {{'|', 1, 0x9}}) +s:update(1, {{'|', 1, 0x6}}) +s:update(1, {{'&', 1, 0xabcde}}) +s:update(1, {{'&', 1, 0x2}}) +s:update(1, {{'^', 1, 0xa2}}) +s:update(1, {{'^', 1, 0xa2}}) +s:truncate() + -- test delete multiple fields s:insert{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} s:update({0}, {{'#', 42, 1}})