Kouhei Sutou
null+****@clear*****
Mon Aug 12 12:02:59 JST 2013
Kouhei Sutou 2013-08-12 12:02:59 +0900 (Mon, 12 Aug 2013) New Revision: 6b666d065ba58f8b22bbeae1f793644821f5f03c https://github.com/groonga/grntest/commit/6b666d065ba58f8b22bbeae1f793644821f5f03c Message: Extract response parser Added files: lib/grntest/response-parser.rb Modified files: lib/grntest/executors/base-executor.rb lib/grntest/tester.rb Modified: lib/grntest/executors/base-executor.rb (+1 -0) =================================================================== --- lib/grntest/executors/base-executor.rb 2013-08-12 11:59:59 +0900 (94aaeb4) +++ lib/grntest/executors/base-executor.rb 2013-08-12 12:02:59 +0900 (29bd7be) @@ -23,6 +23,7 @@ require "groonga/command" require "grntest/error" require "grntest/execution-context" +require "grntest/response-parser" module Grntest module Executors Added: lib/grntest/response-parser.rb (+64 -0) 100644 =================================================================== --- /dev/null +++ lib/grntest/response-parser.rb 2013-08-12 12:02:59 +0900 (2f25ec7) @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2012-2013 Kouhei Sutou <kou �� clear-code.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +require "json" +require "msgpack" + +require "grntest/error" + +module Grntest + class ResponseParser + class << self + def parse(content, type) + parser = new(type) + parser.parse(content) + end + end + + def initialize(type) + @type = type + end + + def parse(content) + case @type + when "json", "msgpack" + parse_result(content.chomp) + else + content + end + end + + def parse_result(result) + case @type + when "json" + begin + JSON.parse(result) + rescue JSON::ParserError + raise ParseError.new(@type, result, $!.message) + end + when "msgpack" + begin + MessagePack.unpack(result.chomp) + rescue MessagePack::UnpackError, NoMemoryError + raise ParseError.new(@type, result, $!.message) + end + else + raise ParseError.new(@type, result, "unknown type") + end + end + end +end Modified: lib/grntest/tester.rb (+0 -41) =================================================================== --- lib/grntest/tester.rb 2013-08-12 11:59:59 +0900 (2756739) +++ lib/grntest/tester.rb 2013-08-12 12:02:59 +0900 (3289fd8) @@ -697,47 +697,6 @@ module Grntest end end - class ResponseParser - class << self - def parse(content, type) - parser = new(type) - parser.parse(content) - end - end - - def initialize(type) - @type = type - end - - def parse(content) - case @type - when "json", "msgpack" - parse_result(content.chomp) - else - content - end - end - - def parse_result(result) - case @type - when "json" - begin - JSON.parse(result) - rescue JSON::ParserError - raise ParseError.new(@type, result, $!.message) - end - when "msgpack" - begin - MessagePack.unpack(result.chomp) - rescue MessagePack::UnpackError, NoMemoryError - raise ParseError.new(@type, result, $!.message) - end - else - raise ParseError.new(@type, result, "unknown type") - end - end - end - class TestRunner MAX_N_COLUMNS = 79 -------------- next part -------------- HTML����������������������������... 다운로드