Kouhei Sutou
null+****@clear*****
Sun Jan 26 22:13:39 JST 2014
Kouhei Sutou 2014-01-26 22:13:39 +0900 (Sun, 26 Jan 2014) New Revision: 8345a4bf5a143e864c2abf1eed490e2609c50cd0 https://github.com/groonga/groonga/commit/8345a4bf5a143e864c2abf1eed490e2609c50cd0 Message: Adjust "&&" behavior to ECMAScript "x && y" returns false if "x" or "y" is false value, "y" if both "x" and "y" is not false value. Before: 29 && "string value" -> 1 null && true -> 0 After: 29 && "string value" -> 29 (changed) null && true -> false (changed) The commit message of c007a6819aa3840054297b061b35066deaf173f1 (supports "x || y") is wrong. "x || y" returns 1 or 0 not true or false. Added files: test/command/suite/select/filter/logical_operation/and/all_not_false.expected test/command/suite/select/filter/logical_operation/and/all_not_false.test test/command/suite/select/filter/logical_operation/and/false.expected test/command/suite/select/filter/logical_operation/and/false.test test/command/suite/select/filter/logical_operation/and/null.expected test/command/suite/select/filter/logical_operation/and/null.test Modified files: lib/expr.c Modified: lib/expr.c (+14 -7) =================================================================== --- lib/expr.c 2014-01-26 22:05:25 +0900 (3f5d9fa) +++ lib/expr.c 2014-01-26 22:13:39 +0900 (cd55c69) @@ -3137,17 +3137,24 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs) { grn_obj *x, *y; unsigned int x_boolean, y_boolean; - int result; + grn_obj *result = NULL; POP2ALLOC1(x, y, res); GRN_TRUEP(ctx, x, x_boolean); - GRN_TRUEP(ctx, y, y_boolean); - if (x_boolean && y_boolean) { - result = 1; + if (x_boolean) { + GRN_TRUEP(ctx, y, y_boolean); + if (y_boolean) { + result = y; + } + } + if (result) { + if (res != result) { + grn_obj_reinit(ctx, res, result->header.domain, 0); + grn_obj_cast(ctx, result, res, GRN_FALSE); + } } else { - result = 0; + grn_obj_reinit(ctx, res, GRN_DB_BOOL, 0); + GRN_BOOL_SET(ctx, res, GRN_FALSE); } - grn_obj_reinit(ctx, res, GRN_DB_INT32, 0); - GRN_INT32_SET(ctx, res, result); } code++; break; Added: test/command/suite/select/filter/logical_operation/and/all_not_false.expected (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/all_not_false.expected 2014-01-26 22:13:39 +0900 (b6f8c71) @@ -0,0 +1,11 @@ +table_create Users TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Users name COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +load --table Users +[ +{"name": "Alice"} +] +[[0,0.0,0.0],1] +select Users --output_columns '_id, "not false" && 29 && name' --command_version 2 +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["","null"]],[1,"Alice"]]]] Added: test/command/suite/select/filter/logical_operation/and/all_not_false.test (+11 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/all_not_false.test 2014-01-26 22:13:39 +0900 (adf8e48) @@ -0,0 +1,11 @@ +table_create Users TABLE_NO_KEY +column_create Users name COLUMN_SCALAR ShortText + +load --table Users +[ +{"name": "Alice"} +] + +select Users \ + --output_columns '_id, "not false" && 29 && name' \ + --command_version 2 Added: test/command/suite/select/filter/logical_operation/and/false.expected (+9 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/false.expected 2014-01-26 22:13:39 +0900 (5cf9f18) @@ -0,0 +1,9 @@ +table_create Records TABLE_NO_KEY +[[0,0.0,0.0],true] +load --table Records +[ +[] +] +[[0,0.0,0.0],1] +select Records --output_columns '_id, false && "not false"' --command_version 2 +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["","null"]],[1,false]]]] Added: test/command/suite/select/filter/logical_operation/and/false.test (+10 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/false.test 2014-01-26 22:13:39 +0900 (8c6a386) @@ -0,0 +1,10 @@ +table_create Records TABLE_NO_KEY + +load --table Records +[ +[] +] + +select Records \ + --output_columns '_id, false && "not false"' \ + --command_version 2 Added: test/command/suite/select/filter/logical_operation/and/null.expected (+9 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/null.expected 2014-01-26 22:13:39 +0900 (c5e4b85) @@ -0,0 +1,9 @@ +table_create Records TABLE_NO_KEY +[[0,0.0,0.0],true] +load --table Records +[ +[] +] +[[0,0.0,0.0],1] +select Records --output_columns '_id, null && "not false"' --command_version 2 +[[0,0.0,0.0],[[[1],[["_id","UInt32"],["","null"]],[1,false]]]] Added: test/command/suite/select/filter/logical_operation/and/null.test (+10 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/filter/logical_operation/and/null.test 2014-01-26 22:13:39 +0900 (16b5010) @@ -0,0 +1,10 @@ +table_create Records TABLE_NO_KEY + +load --table Records +[ +[] +] + +select Records \ + --output_columns '_id, null && "not false"' \ + --command_version 2 -------------- next part -------------- HTML����������������������������...Download