Kouhei Sutou
null+****@clear*****
Tue Jul 11 00:04:47 JST 2017
Kouhei Sutou 2017-07-11 00:04:47 +0900 (Tue, 11 Jul 2017) New Revision: b0e8779fc52cd1f3156fa5c041136e4d5f71f8a7 https://github.com/ranguba/chupa-text/commit/b0e8779fc52cd1f3156fa5c041136e4d5f71f8a7 Message: chupa-text: add --mime-type option to overwrite input data MIME type Modified files: lib/chupa-text/command/chupa-text.rb test/command/test-chupa-text.rb Modified: lib/chupa-text/command/chupa-text.rb (+7 -0) =================================================================== --- lib/chupa-text/command/chupa-text.rb 2017-07-10 23:53:03 +0900 (101d0b1) +++ lib/chupa-text/command/chupa-text.rb 2017-07-11 00:04:47 +0900 (f375c70) @@ -44,6 +44,7 @@ module ChupaText @configuration = Configuration.load_default @enable_gems = true @uri = nil + @mime_type = nil @format = :json @need_screenshot = true @expected_screenshot_size = [200, 200] @@ -113,6 +114,10 @@ module ChupaText "Input data URI.") do |uri| @uri = URI.parse(uri) end + parser.on("--mime-type=MIME_TYPE", + "Input data MIME type.") do |mime_type| + @mime_type = mime_type + end parser.separator("") parser.separator("Output related options") @@ -185,6 +190,7 @@ module ChupaText end def create_data + options = {mime_type: @mime_type} if****@input*****? data = VirtualFileData.new(@uri, $stdin) else @@ -202,6 +208,7 @@ module ChupaText data = InputData.new(input) end end + data.mime_type = @mime_type if @mime_type data.need_screenshot = @need_screenshot data.expected_screenshot_size = @expected_screenshot_size data Modified: test/command/test-chupa-text.rb (+42 -0) =================================================================== --- test/command/test-chupa-text.rb 2017-07-10 23:53:03 +0900 (2fa8c3a) +++ test/command/test-chupa-text.rb 2017-07-11 00:04:47 +0900 (4ac6b51) @@ -158,6 +158,27 @@ class TestCommandChupaText < Test::Unit::TestCase ], run_command(@uri, "--uri", virtual_uri)) end + + test("--mime-type") do + @html = "<html><body>Hello</body></html>" + assert_equal([ + true, + { + "mime-type" => "text/plain", + "size" => @html.bytesize, + "uri" => @uri, + "texts" => [ + { + "mime-type" => "text/plain", + "size" => @html.bytesize, + "uri" => @uri, + "body" => @html, + }, + ], + }, + ], + run_command(@uri, "--mime-type", "text/plain")) + end end sub_test_case("standard input") do @@ -205,6 +226,27 @@ class TestCommandChupaText < Test::Unit::TestCase ], run_command("--uri", "http://127.0.0.1/hello.txt")) end + + test("--mime-type") do + body = "Hello\n" + @stdin << "Hello\n" + @stdin.rewind + assert_equal([ + true, + { + "mime-type" => "text/html", + "size" => body.bytesize, + "texts" => [ + { + "mime-type" => "text/html", + "size" => body.bytesize, + "body" => body, + }, + ], + }, + ], + run_command("--mime-type", "text/html")) + end end end -------------- next part -------------- HTML����������������������������...下载