Kouhei Sutou
null+****@clear*****
Tue Aug 14 14:57:14 JST 2012
Kouhei Sutou 2012-08-14 14:57:14 +0900 (Tue, 14 Aug 2012) New Revision: fec07b3e8d7e90df6814673be76be12960bd1840 https://github.com/groonga/grntest/commit/fec07b3e8d7e90df6814673be76be12960bd1840 Log: Extract output normalization code Modified files: lib/grntest/tester.rb Modified: lib/grntest/tester.rb (+19 -15) =================================================================== --- lib/grntest/tester.rb 2012-08-14 14:53:47 +0900 (0071d66) +++ lib/grntest/tester.rb 2012-08-14 14:57:14 +0900 (1a31e1d) @@ -936,21 +936,7 @@ EOF when :input normalized_result << content when :output - type = options[:type] - case type - when "json", "msgpack" - status, *values = parse_result(content, type) - normalized_status = normalize_status(status) - normalized_output_content = [normalized_status, *values] - normalized_output = JSON.generate(normalized_output_content) - if normalized_output.bytesize > @max_n_columns - normalized_output = JSON.pretty_generate(normalized_output_content) - end - normalized_output.force_encoding("ASCII-8BIT") - normalized_result << "#{normalized_output}\n" - else - normalized_result << "#{content}\n".force_encoding("ASCII-8BIT") - end + normalized_result << normalize_output(content, options) when :error normalized_result << "#{content}\n".force_encoding("ASCII-8BIT") end @@ -958,6 +944,24 @@ EOF normalized_result end + def normalize_output(content, options) + type = options[:type] + case type + when "json", "msgpack" + status, *values = parse_result(content, type) + normalized_status = normalize_status(status) + normalized_output_content = [normalized_status, *values] + normalized_output = JSON.generate(normalized_output_content) + if normalized_output.bytesize > @max_n_columns + normalized_output = JSON.pretty_generate(normalized_output_content) + end + normalized_output.force_encoding("ASCII-8BIT") + "#{normalized_output}\n" + else + "#{content}\n".force_encoding("ASCII-8BIT") + end + end + def parse_result(result, type) case type when "json" -------------- next part -------------- HTML����������������������������... 下載