test/test-pdf.rb in chupa-text-decomposer-pdf-1.0.8 vs test/test-pdf.rb in chupa-text-decomposer-pdf-1.1.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2013-2017 Kouhei Sutou <kou@clear-code.com> +# Copyright (C) 2013-2019 Kouhei Sutou <kou@clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. @@ -30,10 +30,17 @@ def fixture_path(*components) base_path = Pathname(__FILE__).dirname + "fixture" base_path.join(*components) end + def capture_log(&block) + ChupaText::CaptureLogger.capture(&block).collect do |level, message| + message = message.split("\n", 2)[0] + [level, message] + end + end + sub_test_case("target?") do sub_test_case("extension") do def create_data(uri) data = ChupaText::Data.new data.body = "%PDF-1.4" @@ -208,9 +215,26 @@ def load_image_fixture(fixture_name) File.open(fixture_path(fixture_name), "rb") do |file| load_image_data(file.read) end + end + end + + sub_test_case("invalid") do + def test_empty + messages = capture_log do + assert_equal([], + decompose(fixture_path("empty.pdf")).collect(&:body)) + end + assert_equal([ + [ + :error, + "[decomposer][pdf] Failed to process PDF: " + + "Poppler::Error::Damaged: PDF document is damaged", + ], + ], + messages) end end end end