[Groonga-commit] groonga/gcs [master] bq: throw exception for unknown group operator

Back to archive index

null+****@clear***** null+****@clear*****
2012年 8月 6日 (月) 13:07:04 JST


Kouhei Sutou	2012-08-06 13:07:04 +0900 (Mon, 06 Aug 2012)

  New Revision: d6882185b7af2da7441c350d1f70918026a8bb38
  https://github.com/groonga/gcs/commit/d6882185b7af2da7441c350d1f70918026a8bb38

  Log:
    bq: throw exception for unknown group operator

  Modified files:
    lib/bq-translator.js
    test/bq-translator.test.js

  Modified: lib/bq-translator.js (+3 -2)
===================================================================
--- lib/bq-translator.js    2012-08-06 13:04:25 +0900 (0319443)
+++ lib/bq-translator.js    2012-08-06 13:07:04 +0900 (7630c0c)
@@ -65,6 +65,7 @@ BooleanQueryTranslator.prototype = {
       if (/^[a-z]$/.test(character)) {
         operator += character;
       } else if (character == " ") {
+        var operatorEndOffset = this.offset;
         this.skipSpaces();
         var expression;
         switch (operator) {
@@ -81,8 +82,8 @@ BooleanQueryTranslator.prototype = {
           expression = this.translateGroupSetOperation("||");
           break;
         default:
-          // TODO: report error: unknown operator
-          return "";
+          this.offset = operatorEndOffset;
+          this.throwTranslateError("unknown operator: <" + operator + ">");
           break;
         }
         this.skipSpaces();

  Modified: test/bq-translator.test.js (+4 -0)
===================================================================
--- test/bq-translator.test.js    2012-08-06 13:04:25 +0900 (139712e)
+++ test/bq-translator.test.js    2012-08-06 13:07:04 +0900 (bb6e0d7)
@@ -126,6 +126,10 @@ suite('BoolanQueryTranslator', function() {
                  "and f1:'k1' f2:'k2')",
                  "|a|nd f1:'k1' f2:'k2')",
                  "not started with <(>");
+  testGroupError("unknown operator",
+                 "(nonexistent f1:'k1' f2:'k2')",
+                 "(nonexistent| |f1:'k1' f2:'k2')",
+                 "unknown operator: <nonexistent>");
 
   testExpression("value only: stirng: and: space",
                  "'keyword1 keyword2' 'other keyword'",
-------------- next part --------------
HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B...
Download 



Groonga-commit メーリングリストの案内
Back to archive index