Navigation Menu

Skip to content

Commit

Permalink
bq: throw exception for missing close parenthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent 7a21371 commit e087a1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
12 changes: 4 additions & 8 deletions lib/bq-translator.js
Expand Up @@ -91,12 +91,6 @@ BooleanQueryTranslator.prototype = {
this.throwTranslateError("unknown operator: <" + operator + ">");
break;
}
this.skipSpaces();
if (this.query[this.offset] != ")") {
this.throwTranslateError("close parenthesis is missing " +
"for operator: <" + operator + ">");
}
this.offset++;
return expression;
} else if (character == ")") {
this.throwTranslateError("operator is missing");
Expand All @@ -123,6 +117,7 @@ BooleanQueryTranslator.prototype = {
this.throwTranslateError("a garbage character after value: " +
"<" + character + ">");
}
this.offset++;
return expression;
} else if (character == ")") {
if (field.length == 0) {
Expand All @@ -137,8 +132,7 @@ BooleanQueryTranslator.prototype = {
}
}

// TODO: report error: missing close paren <)>
return "";
this.throwTranslateError("close parenthesis is missing: operator:<field>");
},
translateGroupFilter: function() {
var field = "";
Expand All @@ -154,6 +148,7 @@ BooleanQueryTranslator.prototype = {
// TODO: report error: have garbage
return "";
}
this.offset++;
return expression;
} else if (character == ")") {
// TODO: report error: field and value is missing
Expand All @@ -172,6 +167,7 @@ BooleanQueryTranslator.prototype = {
while (this.offset < this.query.length) {
this.skipSpaces();
if (this.query[this.offset] == ")") {
this.offset++;
return "(" + expressions.join(" " + setOperator + " ") + ")";
} else {
expressions.push(this.translateExpression());
Expand Down
13 changes: 9 additions & 4 deletions test/bq-translator.test.js
Expand Up @@ -130,10 +130,6 @@ suite('BoolanQueryTranslator', function() {
"(nonexistent f1:'k1' f2:'k2')",
"(nonexistent| |f1:'k1' f2:'k2')",
"unknown operator: <nonexistent>");
testGroupError("missing close parentheis: after operator",
"(and f1:'k1' f2:'k2'",
"(and f1:'k1' f2:'k2'||",
"close parenthesis is missing for operator: <and>");
testGroupError("missing close parentheis: in operator",
"(an",
"(an||",
Expand Down Expand Up @@ -163,6 +159,15 @@ suite('BoolanQueryTranslator', function() {
"(field fIeld 'value')",
"(field f|I|eld 'value')",
"invalid field character: <I>");
testGroupError("field: missing close parenthesis",
"(field ",
"(field ||",
"close parenthesis is missing: operator:<field>");

// testGroupError("and: missing close parentheis",
// "(and f1:'k1' f2:'k2'",
// "(and f1:'k1' f2:'k2'||",
// "close parenthesis is missing: operator:<and>");

testExpression("value only: stirng: and: space",
"'keyword1 keyword2' 'other keyword'",
Expand Down

0 comments on commit e087a1e

Please sign in to comment.