Navigation Menu

Skip to content

Commit

Permalink
bq: throw exception for missing group close parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent d688218 commit 4bbf88e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
16 changes: 10 additions & 6 deletions lib/bq-translator.js
Expand Up @@ -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);
Expand All @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion test/bq-translator.test.js
Expand Up @@ -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'",
Expand Down

0 comments on commit 4bbf88e

Please sign in to comment.