Navigation Menu

Skip to content

Commit

Permalink
q: support unterminated phrase check
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 3, 2012
1 parent a6cbcab commit bc11ffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/q-translator.js
Expand Up @@ -55,7 +55,7 @@ QueryTranslator.prototype = {
}
phrase += character;
}
this.throwTranslateError("phrase is unterminated");
this.throwTranslateError("phrase is unterminated: <" + phrase + ">");
},
translateTerm: function() {
this.skipSpaces(this.query, this);
Expand All @@ -76,8 +76,12 @@ QueryTranslator.prototype = {
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 += "||";
} else {
message += "|" + this.query[this.offset] + "|";
message += this.query.substring(this.offset + 1);
}
message += ">";
message += ": " + detail;
throw new Error(message);
Expand Down
4 changes: 4 additions & 0 deletions test/q-translator.test.js
Expand Up @@ -98,6 +98,10 @@ suite('QueryTranslator', function() {
'star wars"',
'|s|tar wars"',
"phrase must start with <\">");
testPhraseTermError("not terminated",
'"star wars',
'"star wars||',
"phrase is unterminated: <star wars>");

testTerm("a term",
" star wars",
Expand Down

0 comments on commit bc11ffb

Please sign in to comment.