[Groonga-commit] groonga/gcs [master] bq: throw exception for missing group close parenthesis

Back to archive index

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


Kouhei Sutou	2012-08-06 13:12:44 +0900 (Mon, 06 Aug 2012)

  New Revision: 4bbf88e9ccfcf4e20402a56cb0288e1816ae6926
  https://github.com/groonga/gcs/commit/4bbf88e9ccfcf4e20402a56cb0288e1816ae6926

  Log:
    bq: throw exception for missing group close parenthesis

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

  Modified: lib/bq-translator.js (+10 -6)
===================================================================
--- lib/bq-translator.js    2012-08-06 13:07:04 +0900 (7630c0c)
+++ lib/bq-translator.js    2012-08-06 13:12:44 +0900 (d1d360e)
@@ -39,9 +39,14 @@ BooleanQueryTranslator.prototype = {
   throwTranslateError: function(detail) {
     var message = "";
     message += "<";
-    message += this.query.substring(0, this.offset);
-    message += "|" + this.query[this.offset] + "|";
-    message += this.query.substring(this.offset + 1);
+    if (this.offset == this.query.length) {
+      message += this.query;
+      message += "||";
+    } else {
+      message += this.query.substring(0, this.offset);
+      message += "|" + this.query[this.offset] + "|";
+      message += this.query.substring(this.offset + 1);
+    }
     message += ">";
     message += ": " + detail;
     throw new Error(message);
@@ -55,7 +60,7 @@ BooleanQueryTranslator.prototype = {
   },
   translateGroup: function() {
     if (this.query[this.offset] != "(") {
-      this.throwTranslateError("not started with <(>");
+      this.throwTranslateError("open parenthesis is missing");
     }
 
     this.offset++;
@@ -88,8 +93,7 @@ BooleanQueryTranslator.prototype = {
         }
         this.skipSpaces();
         if (this.query[this.offset] != ")") {
-          // TODO: report error: have garbage
-          return "";
+          this.throwTranslateError("close parenthesis is missing");
         }
         this.offset++;
         return expression;

  Modified: test/bq-translator.test.js (+5 -1)
===================================================================
--- test/bq-translator.test.js    2012-08-06 13:07:04 +0900 (bb6e0d7)
+++ test/bq-translator.test.js    2012-08-06 13:12:44 +0900 (5ee55dd)
@@ -125,11 +125,15 @@ suite('BoolanQueryTranslator', function() {
   testGroupError("missing open parentheis",
                  "and f1:'k1' f2:'k2')",
                  "|a|nd f1:'k1' f2:'k2')",
-                 "not started with <(>");
+                 "open parenthesis is missing");
   testGroupError("unknown operator",
                  "(nonexistent f1:'k1' f2:'k2')",
                  "(nonexistent| |f1:'k1' f2:'k2')",
                  "unknown operator: <nonexistent>");
+  testGroupError("missing close parentheis",
+                 "(and f1:'k1' f2:'k2'",
+                 "(and f1:'k1' f2:'k2'||",
+                 "close parenthesis is missing");
 
   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