Navigation Menu

Skip to content

Commit

Permalink
bq: throw exception for missing field value separator
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 6, 2012
1 parent d596d37 commit f18b72d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/bq-translator.js
Expand Up @@ -205,8 +205,7 @@ BooleanQueryTranslator.prototype = {
field = this.defaultField;
this.offset = startOffset;
} else {
// TODO: report error: field and value separator ":" is missing
return "";
this.throwTranslateError("field value separator is missing");
}
}
} else {
Expand Down
23 changes: 23 additions & 0 deletions test/bq-translator.test.js
Expand Up @@ -85,6 +85,24 @@ function testExpression(label, expression,
});
}

function testExpressionError(label, expression, context, detail) {
test('error: expression: ' + label + ': ' + '<' + expression + '>',
function() {
var translator = new BooleanQueryTranslator(expression);
translator.defaultField = "field";
var actualError;
assert.throw(function() {
try {
translator.translateExpression();
} catch (error) {
actualError = error;
throw error;
}
});
assert.equal(actualError.message, "<" + context + ">" + ": " + detail);
});
}

suite('BoolanQueryTranslator', function() {
testQuery("expression",
"type:'ModelName'",
Expand Down Expand Up @@ -235,4 +253,9 @@ suite('BoolanQueryTranslator', function() {
"field1:29 field2:75",
"field1:29".length,
"field1 == 29");

testExpressionError("missing field value separator",
"f1 'k1'",
"f1| |'k1'",
"field value separator is missing");
});

0 comments on commit f18b72d

Please sign in to comment.