null+****@clear*****
null+****@clear*****
2012年 7月 10日 (火) 09:55:10 JST
Yoji SHIDARA 2012-07-10 09:55:10 +0900 (Tue, 10 Jul 2012) New Revision: 553aefdad5f6363dee64b39cb11dddaeeba24c60 https://github.com/nroonga/nroonga/commit/553aefdad5f6363dee64b39cb11dddaeeba24c60 Log: Return '' for dump command on empty database Formerly undefined is returned for this situation. Modified files: lib/nroonga.js src/nroonga.coffee test/database.test.coffee Modified: lib/nroonga.js (+6 -6) =================================================================== --- lib/nroonga.js 2012-07-03 22:40:46 +0900 (84ee838) +++ lib/nroonga.js 2012-07-10 09:55:10 +0900 (6ece3ae) @@ -34,7 +34,11 @@ if (command === 'dump') { return result.toString('UTF-8'); } else { - return msgpack.unpack(result); + if (result.length > 0) { + return msgpack.unpack(result); + } else { + return void 0; + } } }; @@ -45,11 +49,7 @@ } options = overrideOutputType(options, 'msgpack'); result = this.commandSyncString(optionsToCommandString(command, options)); - if (result.length > 0) { - return formatResult(result, command); - } else { - return void 0; - } + return formatResult(result, command); }; nroonga.Database.prototype.command = function(command, options, callback) { Modified: src/nroonga.coffee (+5 -5) =================================================================== --- src/nroonga.coffee 2012-07-03 22:40:46 +0900 (27e806f) +++ src/nroonga.coffee 2012-07-10 09:55:10 +0900 (b7d620e) @@ -20,15 +20,15 @@ formatResult = (result, command) -> if command == 'dump' result.toString('UTF-8') else - msgpack.unpack(result) + if result.length > 0 + msgpack.unpack(result) + else + undefined nroonga.Database.prototype.commandSync = (command, options={}) -> options = overrideOutputType(options, 'msgpack') result = this.commandSyncString(optionsToCommandString(command, options)) - if result.length > 0 - formatResult(result, command) - else - undefined + formatResult(result, command) nroonga.Database.prototype.command = (command, options, callback) -> if arguments.length == 2 Modified: test/database.test.coffee (+8 -0) =================================================================== --- test/database.test.coffee 2012-07-03 22:40:46 +0900 (aae0773) +++ test/database.test.coffee 2012-07-10 09:55:10 +0900 (75a278b) @@ -71,6 +71,14 @@ describe 'nroonga.Database', -> should.exist(data.version) done() +describe 'empty database', -> + db = new nroonga.Database() + + describe '#dump', -> + it 'should return empty string', -> + result = db.commandSync('dump') + should.equal(result, '') + describe 'database whose name is not string', -> it 'should throw an exception', -> (-> -------------- next part -------------- HTML$B$NE:IU%U%!%$%k$rJ]4I$7$^$7$?(B... Download