forked from gdelugre/origami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pdf_parse_lazy.rb
69 lines (53 loc) · 1.68 KB
/
test_pdf_parse_lazy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'minitest/autorun'
require 'stringio'
class TestPDFLazyParser < Minitest::Test
def setup
@files =
%w{
dataset/empty.pdf
dataset/calc.pdf
dataset/crypto.pdf
}
end
def test_parse_pdf_lazy
@files.each do |file|
pdf = PDF.read(File.join(__dir__, file),
ignore_errors: false,
lazy: true,
verbosity: Parser::VERBOSE_QUIET)
assert_instance_of PDF, pdf
pdf.each_object do |object|
assert_kind_of Origami::Object, object
end
assert_instance_of Catalog, pdf.Catalog
pdf.each_page do |page|
assert_kind_of Page, page
end
end
end
def test_save_pdf_lazy
@files.each do |file|
pdf = PDF.read(File.join(__dir__, file),
ignore_errors: false,
lazy: true,
verbosity: Parser::VERBOSE_QUIET)
pdf.save(StringIO.new)
end
end
def test_random_access
io = StringIO.new
stream = Stream.new("abc")
PDF.create(io) do |pdf|
pdf.insert(stream)
end
io = io.reopen(io.string, 'r')
pdf = PDF.read(io, ignore_errors: false,
lazy: true,
verbosity: Parser::VERBOSE_QUIET)
non_existent = pdf[42]
existent = pdf[stream.reference]
assert_nil non_existent
assert_instance_of Stream, existent
assert_equal stream.data, existent.data
end
end