Kouhei Sutou
null+****@clear*****
Mon Jul 10 23:53:03 JST 2017
Kouhei Sutou 2017-07-10 23:53:03 +0900 (Mon, 10 Jul 2017) New Revision: 08ee0eb78585608afeb270303b505db092e8bbf6 https://github.com/ranguba/chupa-text/commit/08ee0eb78585608afeb270303b505db092e8bbf6 Message: chupa-text: add --uri option to overwrite input data URI Modified files: lib/chupa-text/command/chupa-text.rb test/command/test-chupa-text.rb Modified: lib/chupa-text/command/chupa-text.rb (+16 -2) =================================================================== --- lib/chupa-text/command/chupa-text.rb 2017-07-10 18:19:48 +0900 (984660b) +++ lib/chupa-text/command/chupa-text.rb 2017-07-10 23:53:03 +0900 (101d0b1) @@ -43,6 +43,7 @@ module ChupaText @input = nil @configuration = Configuration.load_default @enable_gems = true + @uri = nil @format = :json @need_screenshot = true @expected_screenshot_size = [200, 200] @@ -107,6 +108,13 @@ module ChupaText end parser.separator("") + parser.separator("Input related options") + parser.on("--uri=URI", + "Input data URI.") do |uri| + @uri = URI.parse(uri) + end + + parser.separator("") parser.separator("Output related options") parser.on("--format=FORMAT", AVAILABLE_FORMATS, "Output FORMAT.", @@ -178,7 +186,7 @@ module ChupaText def create_data if****@input*****? - data = VirtualFileData.new(nil, $stdin) + data = VirtualFileData.new(@uri, $stdin) else case @input when /\A[a-z]+:\/\//i @@ -186,7 +194,13 @@ module ChupaText else input = Pathname(@input) end - data = InputData.new(input) + if @uri + input.open("rb") do |io| + data = VirtualFileData.new(@uri, io) + end + else + data = InputData.new(input) + end end data.need_screenshot = @need_screenshot data.expected_screenshot_size = @expected_screenshot_size Modified: test/command/test-chupa-text.rb (+48 -2) =================================================================== --- test/command/test-chupa-text.rb 2017-07-10 18:19:48 +0900 (42354c9) +++ test/command/test-chupa-text.rb 2017-07-10 23:53:03 +0900 (2fa8c3a) @@ -116,7 +116,7 @@ class TestCommandChupaText < Test::Unit::TestCase @www_server_thread.kill end - def test_single + test("default") do @html = "<html><body>Hello</body></html>" assert_equal([ true, @@ -136,10 +136,32 @@ class TestCommandChupaText < Test::Unit::TestCase ], run_command(@uri)) end + + test("--uri") do + virtual_uri = "http://127.0.0.1/hello.html" + @html = "<html><body>Hello</body></html>" + assert_equal([ + true, + { + "mime-type" => "text/html", + "size" => @html.bytesize, + "uri" => virtual_uri, + "texts" => [ + { + "mime-type" => "text/html", + "size" => @html.bytesize, + "uri" => virtual_uri, + "body" => @html, + }, + ], + }, + ], + run_command(@uri, "--uri", virtual_uri)) + end end sub_test_case("standard input") do - def test_single + test("default") do body = "Hello\n" @stdin << "Hello\n" @stdin.rewind @@ -159,6 +181,30 @@ class TestCommandChupaText < Test::Unit::TestCase ], run_command) end + + test("--uri") do + body = "Hello\n" + uri = "http://127.0.0.1/hello.txt" + @stdin << "Hello\n" + @stdin.rewind + assert_equal([ + true, + { + "mime-type" => "text/plain", + "size" => body.bytesize, + "uri" => uri, + "texts" => [ + { + "mime-type" => "text/plain", + "size" => body.bytesize, + "body" => body, + "uri" => uri, + }, + ], + }, + ], + run_command("--uri", "http://127.0.0.1/hello.txt")) + end end end -------------- next part -------------- HTML����������������������������... Descargar