null+****@clear*****
null+****@clear*****
2012年 8月 3日 (金) 22:28:58 JST
Kouhei Sutou 2012-08-03 22:28:58 +0900 (Fri, 03 Aug 2012) New Revision: 2dd4492044c03e50e177c82cd87ff40f03d67752 https://github.com/groonga/gcs/commit/2dd4492044c03e50e177c82cd87ff40f03d67752 Log: q: support phrase start character check Modified files: lib/q-translator.js test/q-translator.test.js Modified: lib/q-translator.js (+3 -2) =================================================================== --- lib/q-translator.js 2012-08-03 22:23:48 +0900 (2cad349) +++ lib/q-translator.js 2012-08-03 22:28:58 +0900 (0fc9657) @@ -36,8 +36,9 @@ QueryTranslator.prototype = { }, translatePhraseTerm: function() { if (this.query[this.offset] != '"') { - this.thorwTranslateError("phrase must start with <\">"); + this.throwTranslateError("phrase must start with <\">"); } + this.offset++; var phrase = ""; for (; this.offset < this.query.length; this.offset++) { @@ -54,7 +55,7 @@ QueryTranslator.prototype = { } phrase += character; } - this.thorwTranslateError("phrase is unterminated"); + this.throwTranslateError("phrase is unterminated"); }, translateTerm: function() { this.skipSpaces(this.query, this); Modified: test/q-translator.test.js (+22 -0) =================================================================== --- test/q-translator.test.js 2012-08-03 22:23:48 +0900 (2f2b650) +++ test/q-translator.test.js 2012-08-03 22:28:58 +0900 (a9ed9dc) @@ -41,6 +41,24 @@ function testPhraseTerm(label, phraseTerm, }); } +function testPhraseTermError(label, phraseTerm, context, detail) { + test('error: phrase term: ' + label + ': ' + + '<' + phraseTerm + '>', function() { + var translator = new QueryTranslator(phraseTerm); + translator.defaultField = "field"; + var actualError; + assert.throw(function() { + try { + translator.translatePhraseTerm(); + } catch (error) { + actualError = error; + throw error; + } + }); + assert.equal(actualError.message, "<" + context + ">" + ": " + detail); + }); +} + function testTerm(label, term, expectedOffset, expectedBooleanQuery) { test('term: ' + label + ': ' + '<' + term + '> -> <' + expectedBooleanQuery + '>', function() { @@ -76,6 +94,10 @@ suite('QueryTranslator', function() { '"star \\" wars" luke', '"star \\" wars"'.length, "'\"star \\\" wars\"'"); + testPhraseTermError("not start with <\">", + 'star wars"', + '|s|tar wars"', + "phrase must start with <\">"); testTerm("a term", " star wars", -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download