origami-docspring 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +18 -0
  3. data/examples/attachments/attachment.rb +7 -8
  4. data/examples/attachments/nested_document.rb +6 -5
  5. data/examples/encryption/encryption.rb +5 -4
  6. data/examples/events/events.rb +7 -6
  7. data/examples/flash/flash.rb +10 -9
  8. data/examples/forms/javascript.rb +14 -13
  9. data/examples/forms/xfa.rb +67 -66
  10. data/examples/javascript/hello_world.rb +6 -5
  11. data/examples/javascript/js_emulation.rb +26 -26
  12. data/examples/loop/goto.rb +12 -11
  13. data/examples/loop/named.rb +17 -16
  14. data/examples/signature/signature.rb +11 -11
  15. data/examples/uri/javascript.rb +25 -24
  16. data/examples/uri/open-uri.rb +5 -4
  17. data/examples/uri/submitform.rb +11 -10
  18. data/lib/origami/3d.rb +330 -334
  19. data/lib/origami/acroform.rb +267 -268
  20. data/lib/origami/actions.rb +266 -278
  21. data/lib/origami/annotations.rb +659 -670
  22. data/lib/origami/array.rb +192 -196
  23. data/lib/origami/boolean.rb +66 -70
  24. data/lib/origami/catalog.rb +360 -363
  25. data/lib/origami/collections.rb +132 -133
  26. data/lib/origami/compound.rb +125 -129
  27. data/lib/origami/destinations.rb +226 -237
  28. data/lib/origami/dictionary.rb +155 -154
  29. data/lib/origami/encryption.rb +967 -923
  30. data/lib/origami/extensions/fdf.rb +270 -275
  31. data/lib/origami/extensions/ppklite.rb +323 -328
  32. data/lib/origami/filespec.rb +170 -173
  33. data/lib/origami/filters/ascii.rb +162 -167
  34. data/lib/origami/filters/ccitt/tables.rb +248 -252
  35. data/lib/origami/filters/ccitt.rb +309 -312
  36. data/lib/origami/filters/crypt.rb +31 -34
  37. data/lib/origami/filters/dct.rb +47 -50
  38. data/lib/origami/filters/flate.rb +57 -60
  39. data/lib/origami/filters/jbig2.rb +50 -53
  40. data/lib/origami/filters/jpx.rb +40 -43
  41. data/lib/origami/filters/lzw.rb +151 -155
  42. data/lib/origami/filters/predictors.rb +250 -255
  43. data/lib/origami/filters/runlength.rb +111 -115
  44. data/lib/origami/filters.rb +319 -325
  45. data/lib/origami/font.rb +173 -177
  46. data/lib/origami/functions.rb +62 -66
  47. data/lib/origami/graphics/colors.rb +203 -208
  48. data/lib/origami/graphics/instruction.rb +79 -81
  49. data/lib/origami/graphics/path.rb +141 -144
  50. data/lib/origami/graphics/patterns.rb +156 -160
  51. data/lib/origami/graphics/render.rb +51 -47
  52. data/lib/origami/graphics/state.rb +144 -142
  53. data/lib/origami/graphics/text.rb +185 -188
  54. data/lib/origami/graphics/xobject.rb +818 -804
  55. data/lib/origami/graphics.rb +25 -26
  56. data/lib/origami/header.rb +63 -65
  57. data/lib/origami/javascript.rb +718 -651
  58. data/lib/origami/linearization.rb +284 -285
  59. data/lib/origami/metadata.rb +156 -135
  60. data/lib/origami/name.rb +98 -100
  61. data/lib/origami/null.rb +49 -51
  62. data/lib/origami/numeric.rb +133 -135
  63. data/lib/origami/obfuscation.rb +180 -182
  64. data/lib/origami/object.rb +634 -631
  65. data/lib/origami/optionalcontent.rb +147 -149
  66. data/lib/origami/outline.rb +46 -48
  67. data/lib/origami/outputintents.rb +76 -77
  68. data/lib/origami/page.rb +637 -596
  69. data/lib/origami/parser.rb +214 -221
  70. data/lib/origami/parsers/fdf.rb +44 -45
  71. data/lib/origami/parsers/pdf/lazy.rb +147 -154
  72. data/lib/origami/parsers/pdf/linear.rb +104 -109
  73. data/lib/origami/parsers/pdf.rb +109 -107
  74. data/lib/origami/parsers/ppklite.rb +44 -46
  75. data/lib/origami/pdf.rb +886 -896
  76. data/lib/origami/reference.rb +116 -120
  77. data/lib/origami/signature.rb +617 -625
  78. data/lib/origami/stream.rb +560 -558
  79. data/lib/origami/string.rb +366 -368
  80. data/lib/origami/template/patterns.rb +50 -52
  81. data/lib/origami/template/widgets.rb +111 -114
  82. data/lib/origami/trailer.rb +153 -157
  83. data/lib/origami/tree.rb +55 -57
  84. data/lib/origami/version.rb +19 -19
  85. data/lib/origami/webcapture.rb +87 -90
  86. data/lib/origami/xfa/config.rb +409 -414
  87. data/lib/origami/xfa/connectionset.rb +113 -117
  88. data/lib/origami/xfa/datasets.rb +38 -42
  89. data/lib/origami/xfa/localeset.rb +33 -37
  90. data/lib/origami/xfa/package.rb +49 -52
  91. data/lib/origami/xfa/pdf.rb +54 -59
  92. data/lib/origami/xfa/signature.rb +33 -37
  93. data/lib/origami/xfa/sourceset.rb +34 -38
  94. data/lib/origami/xfa/stylesheet.rb +35 -39
  95. data/lib/origami/xfa/template.rb +1630 -1634
  96. data/lib/origami/xfa/xdc.rb +33 -37
  97. data/lib/origami/xfa/xfa.rb +132 -123
  98. data/lib/origami/xfa/xfdf.rb +34 -38
  99. data/lib/origami/xfa/xmpmeta.rb +34 -38
  100. data/lib/origami/xfa.rb +50 -53
  101. data/lib/origami/xreftable.rb +462 -462
  102. data/lib/origami.rb +37 -38
  103. data/test/test_actions.rb +22 -20
  104. data/test/test_annotations.rb +54 -52
  105. data/test/test_forms.rb +23 -21
  106. data/test/test_native_types.rb +82 -78
  107. data/test/test_object_tree.rb +25 -24
  108. data/test/test_pages.rb +43 -41
  109. data/test/test_pdf.rb +2 -0
  110. data/test/test_pdf_attachment.rb +23 -21
  111. data/test/test_pdf_create.rb +16 -15
  112. data/test/test_pdf_encrypt.rb +69 -66
  113. data/test/test_pdf_parse.rb +131 -129
  114. data/test/test_pdf_parse_lazy.rb +53 -53
  115. data/test/test_pdf_sign.rb +67 -67
  116. data/test/test_streams.rb +145 -143
  117. data/test/test_xrefs.rb +46 -45
  118. metadata +64 -8
@@ -1,34 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestAttachment < Minitest::Test
5
- def setup
6
- @target = PDF.new
7
- @attachment = StringIO.new("test")
8
- @output = StringIO.new
9
- end
7
+ def setup
8
+ @target = PDF.new
9
+ @attachment = StringIO.new("test")
10
+ @output = StringIO.new
11
+ end
10
12
 
11
- def test_attach_file
12
- @target.attach_file(@attachment, name: "foo.bar", filter: :A85)
13
+ def test_attach_file
14
+ @target.attach_file(@attachment, name: "foo.bar", filter: :A85)
13
15
 
14
- @target.save(@output)
16
+ @target.save(@output)
15
17
 
16
- @output = @output.reopen(@output.string, "r")
17
- pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
18
+ @output = @output.reopen(@output.string, "r")
19
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
18
20
 
19
- assert_equal pdf.each_named_embedded_file.count, 1
20
- assert_nil pdf.get_embedded_file_by_name("foo.baz")
21
+ assert_equal pdf.each_named_embedded_file.count, 1
22
+ assert_nil pdf.get_embedded_file_by_name("foo.baz")
21
23
 
22
- file = pdf.get_embedded_file_by_name('foo.bar')
23
- refute_equal file, nil
24
+ file = pdf.get_embedded_file_by_name('foo.bar')
25
+ refute_equal file, nil
24
26
 
25
- assert file.key?(:EF)
26
- assert file.EF.key?(:F)
27
+ assert file.key?(:EF)
28
+ assert file.EF.key?(:F)
27
29
 
28
- stream = file.EF.F
29
- assert stream.is_a?(Stream)
30
+ stream = file.EF.F
31
+ assert stream.is_a?(Stream)
30
32
 
31
- assert_equal stream.dictionary.Filter, :A85
32
- assert_equal stream.data, "test"
33
- end
33
+ assert_equal stream.dictionary.Filter, :A85
34
+ assert_equal stream.data, "test"
35
+ end
34
36
  end
@@ -1,24 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestPDFCreate < Minitest::Test
7
+ def setup
8
+ @output = StringIO.new
9
+ end
5
10
 
6
- def setup
7
- @output = StringIO.new
8
- end
9
-
10
- def test_pdf_create
11
- pdf = PDF.new
11
+ def test_pdf_create
12
+ pdf = PDF.new
12
13
 
13
- null = Null.new
14
- pdf << null
14
+ null = Null.new
15
+ pdf << null
15
16
 
16
- pdf.save(@output)
17
+ pdf.save(@output)
17
18
 
18
- assert null.indirect?
19
- assert_equal null.reference.solve, null
20
- assert pdf.root_objects.include?(null)
21
- assert_equal pdf.revisions.first.body[null.reference], null
22
- assert_equal null.reference.solve, null
23
- end
19
+ assert null.indirect?
20
+ assert_equal null.reference.solve, null
21
+ assert pdf.root_objects.include?(null)
22
+ assert_equal pdf.revisions.first.body[null.reference], null
23
+ assert_equal null.reference.solve, null
24
+ end
24
25
  end
@@ -1,95 +1,98 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestEncryption < Minitest::Test
5
- def setup
6
- @target = PDF.read(File.join(__dir__, "dataset/calc.pdf"),
7
- ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
8
- @output = StringIO.new
9
- end
7
+ include Origami
8
+ def setup
9
+ @target = PDF.read(File.join(__dir__, "dataset/calc.pdf"),
10
+ ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
11
+ @output = StringIO.new
12
+ end
10
13
 
11
- def test_encrypt_rc4_40b
12
- @output.string = ""
13
- @target.encrypt(cipher: 'rc4', key_size: 40).save(@output)
14
- end
14
+ def test_encrypt_rc4_40b
15
+ @output = StringIO.new
16
+ @target.encrypt(cipher: 'rc4', key_size: 40).save(@output)
17
+ end
15
18
 
16
- def test_encrypt_rc4_128b
17
- @output.string = ""
18
- @target.encrypt(cipher: 'rc4').save(@output)
19
- end
19
+ def test_encrypt_rc4_128b
20
+ @output = StringIO.new
21
+ @target.encrypt(cipher: 'rc4').save(@output)
22
+ end
20
23
 
21
- def test_encrypt_aes_128b
22
- @output.string = ""
23
- @target.encrypt(cipher: 'aes').save(@output)
24
- end
24
+ def test_encrypt_aes_128b
25
+ @output = StringIO.new
26
+ @target.encrypt(cipher: 'aes').save(@output)
27
+ end
25
28
 
26
- def test_decrypt_rc4_40b
27
- @output.string = ""
29
+ def test_decrypt_rc4_40b
30
+ @output = StringIO.new
28
31
 
29
- pdf = PDF.new.encrypt(cipher: 'rc4', key_size: 40)
30
- pdf.Catalog[:Test] = "test"
31
- pdf.save(@output)
32
+ pdf = PDF.new.encrypt(cipher: 'rc4', key_size: 40)
33
+ pdf.Catalog[:Test] = "test"
34
+ pdf.save(@output)
32
35
 
33
- refute_equal pdf.Catalog[:Test], "test"
36
+ refute_equal pdf.Catalog[:Test], "test"
34
37
 
35
- @output = @output.reopen(@output.string, "r")
36
- pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
38
+ @output = @output.reopen(@output.string, "r")
39
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
37
40
 
38
- assert_equal pdf.Catalog[:Test], "test"
39
- end
41
+ assert_equal pdf.Catalog[:Test], "test"
42
+ end
40
43
 
41
- def test_decrypt_rc4_128b
42
- @output.string = ""
43
- pdf = PDF.new.encrypt(cipher: 'rc4')
44
- pdf.Catalog[:Test] = "test"
45
- pdf.save(@output)
44
+ def test_decrypt_rc4_128b
45
+ @output = StringIO.new
46
+ pdf = PDF.new.encrypt(cipher: 'rc4')
47
+ pdf.Catalog[:Test] = "test"
48
+ pdf.save(@output)
46
49
 
47
- refute_equal pdf.Catalog[:Test], "test"
50
+ refute_equal pdf.Catalog[:Test], "test"
48
51
 
49
- @output.reopen(@output.string, "r")
50
- pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
52
+ @output.reopen(@output.string, "r")
53
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
51
54
 
52
- assert_equal pdf.Catalog[:Test], "test"
53
- end
55
+ assert_equal pdf.Catalog[:Test], "test"
56
+ end
54
57
 
55
- def test_decrypt_aes_128b
56
- @output.string = ""
57
- pdf = PDF.new.encrypt(cipher: 'aes')
58
- pdf.Catalog[:Test] = "test"
59
- pdf.save(@output)
58
+ def test_decrypt_aes_128b
59
+ @output = StringIO.new
60
+ pdf = PDF.new.encrypt(cipher: 'aes')
61
+ pdf.Catalog[:Test] = "test"
62
+ pdf.save(@output)
60
63
 
61
- refute_equal pdf.Catalog[:Test], "test"
64
+ refute_equal pdf.Catalog[:Test], "test"
62
65
 
63
- @output = @output.reopen(@output.string, "r")
64
- pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
66
+ @output = @output.reopen(@output.string, "r")
67
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
65
68
 
66
- assert_equal pdf.Catalog[:Test], "test"
67
- end
69
+ assert_equal pdf.Catalog[:Test], "test"
70
+ end
68
71
 
69
- def test_decrypt_aes_256b
70
- @output.string = ""
71
- pdf = PDF.new.encrypt(cipher: 'aes', key_size: 256)
72
- pdf.Catalog[:Test] = "test"
73
- pdf.save(@output)
72
+ def test_decrypt_aes_256b
73
+ @output = StringIO.new
74
+ pdf = PDF.new.encrypt(cipher: 'aes', key_size: 256)
75
+ pdf.Catalog[:Test] = "test"
76
+ pdf.save(@output)
74
77
 
75
- refute_equal pdf.Catalog[:Test], "test"
78
+ refute_equal pdf.Catalog[:Test], "test"
76
79
 
77
- @output = @output.reopen(@output.string, "r")
78
- pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
80
+ @output = @output.reopen(@output.string, "r")
81
+ pdf = PDF.read(@output, ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
79
82
 
80
- assert_equal pdf.Catalog[:Test], "test"
81
- end
83
+ assert_equal pdf.Catalog[:Test], "test"
84
+ end
82
85
 
83
- def test_crypt_filter
84
- @output.string = ""
85
- pdf = PDF.new.encrypt(cipher: 'aes', key_size: 128)
86
+ def test_crypt_filter
87
+ @output = StringIO.new
88
+ pdf = PDF.new.encrypt(cipher: 'aes', key_size: 128)
86
89
 
87
- pdf.Catalog[:S1] = Stream.new("test", :Filter => :Crypt)
88
- pdf.Catalog[:S2] = Stream.new("test")
90
+ pdf.Catalog[:S1] = Stream.new("test", Filter: :Crypt)
91
+ pdf.Catalog[:S2] = Stream.new("test")
89
92
 
90
- pdf.save(@output)
93
+ pdf.save(@output)
91
94
 
92
- assert_equal pdf.Catalog.S1.encoded_data, "test"
93
- refute_equal pdf.Catalog.S2.encoded_data, "test"
94
- end
95
+ assert_equal pdf.Catalog.S1.encoded_data, "test"
96
+ refute_equal pdf.Catalog.S2.encoded_data, "test"
97
+ end
95
98
  end
@@ -1,134 +1,136 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
 
3
5
  class TestPDFParser < Minitest::Test
4
- def setup
5
- @files =
6
- %w{
7
- dataset/empty.pdf
8
- dataset/calc.pdf
9
- dataset/crypto.pdf
10
- }
11
- end
12
-
13
- def test_parse_pdf
14
- @files.each do |file|
15
- pdf = PDF.read(File.join(__dir__, file), ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
16
-
17
- assert_instance_of PDF, pdf
18
-
19
- pdf.each_object do |object|
20
- assert_kind_of Origami::Object, object
21
- end
22
- end
23
- end
24
-
25
- def test_parse_dictionary
26
- dict = Dictionary.parse("<</Ref 2 0 R/N null/Pi 3.14 /D <<>>>>")
27
-
28
- assert_instance_of Dictionary, dict
29
- assert_instance_of Dictionary, dict[:D]
30
- assert_instance_of Null, dict[:N]
31
- assert_instance_of Reference, dict[:Ref]
32
- assert_equal dict.size, 4
33
- assert_raises(InvalidReferenceError) { dict[:Ref].solve }
34
- assert dict[:Pi] == 3.14
35
- end
36
-
37
- def test_parse_array
38
- array = Origami::Array.parse("[/Test (abc) .2 \n 799 [<<>>]]")
39
-
40
- assert array.all?{|e| e.is_a?(Origami::Object)}
41
- assert_equal array.length, 5
42
- assert_raises(InvalidArrayObjectError) { Origami::Array.parse("[1 ") }
43
- assert_raises(InvalidArrayObjectError) { Origami::Array.parse("") }
44
- end
45
-
46
- def test_parse_string
47
- str = LiteralString.parse("(\\122\\125by\\n)")
48
- assert_instance_of LiteralString, str
49
- assert_equal str.value, "RUby\n"
50
-
51
- assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("") }
52
- assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("(test") }
53
- assert_equal "((O))", LiteralString.parse("(((O)))").value
54
- assert_equal LiteralString.parse("(ABC\\\nDEF\\\r\nGHI)").value, "ABCDEFGHI"
55
- assert_equal LiteralString.parse('(\r\n\b\t\f\\(\\)\\x\\\\)').value, "\r\n\b\t\f()x\\"
56
- assert_equal LiteralString.parse('(\r\n\b\t\f\\\\\\(\\))').to_s, '(\r\n\b\t\f\\\\\\(\\))'
57
-
58
- str = HexaString.parse("<52 55 62 79 0A>")
59
- assert_instance_of HexaString, str
60
- assert_equal str.value, "RUby\n"
61
-
62
- assert_equal HexaString.parse("<4>").value, 0x40.chr
63
-
64
- assert_raises(InvalidHexaStringObjectError) { HexaString.parse("") }
65
- assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12") }
66
- assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12X>") }
67
- end
68
-
69
- def test_parse_bool
70
- b_true = Boolean.parse("true")
71
- b_false = Boolean.parse("false")
72
-
73
- assert_instance_of Boolean, b_true
74
- assert_instance_of Boolean, b_false
75
-
76
- assert b_false.false?
77
- refute b_true.false?
78
-
79
- assert_raises(InvalidBooleanObjectError) { Boolean.parse("") }
80
- assert_raises(InvalidBooleanObjectError) { Boolean.parse("tru") }
81
- end
82
-
83
- def test_parse_real
84
- real = Real.parse("-3.141592653")
85
- assert_instance_of Real, real
86
- assert_equal real, -3.141592653
87
-
88
- real = Real.parse("+.00200")
89
- assert_instance_of Real, real
90
- assert_equal real, 0.002
91
-
92
- assert_raises(InvalidRealObjectError) { Real.parse("") }
93
- assert_raises(InvalidRealObjectError) { Real.parse(".") }
94
- assert_raises(InvalidRealObjectError) { Real.parse("+0x1") }
95
- end
96
-
97
- def test_parse_int
98
- int = Origami::Integer.parse("02000000000000")
99
- assert_instance_of Origami::Integer, int
100
- assert_equal int, 2000000000000
101
-
102
- int = Origami::Integer.parse("-98")
103
- assert_instance_of Origami::Integer, int
104
- assert_equal int, -98
105
-
106
- assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("") }
107
- assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("+-1") }
108
- assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("ABC") }
109
- end
110
-
111
- def test_parse_name
112
- name = Name.parse("/#52#55#62#79#0A")
113
- assert_instance_of Name, name
114
- assert_equal name.value, :"RUby\n"
115
-
116
- name = Name.parse("/")
117
- assert_instance_of Name, name
118
- assert_equal :"", name.value
119
-
120
- assert_raises(Origami::InvalidNameObjectError) { Name.parse("") }
121
- assert_raises(Origami::InvalidNameObjectError) { Name.parse("test") }
122
- end
123
-
124
- def test_parse_reference
125
- ref = Reference.parse("199 1 R")
126
- assert_instance_of Reference, ref
127
-
128
- assert_equal [199, 1], ref.to_a
129
- assert_raises(InvalidReferenceError) { ref.solve }
130
- assert_raises(InvalidReferenceError) { Reference.parse("-2 0 R") }
131
- assert_raises(InvalidReferenceError) { Reference.parse("0 R") }
132
- assert_raises(InvalidReferenceError) { Reference.parse("") }
6
+ def setup
7
+ @files =
8
+ %w[
9
+ dataset/empty.pdf
10
+ dataset/calc.pdf
11
+ dataset/crypto.pdf
12
+ ]
13
+ end
14
+
15
+ def test_parse_pdf
16
+ @files.each do |file|
17
+ pdf = PDF.read(File.join(__dir__, file), ignore_errors: false, verbosity: Parser::VERBOSE_QUIET)
18
+
19
+ assert_instance_of PDF, pdf
20
+
21
+ pdf.each_object do |object|
22
+ assert_kind_of Origami::Object, object
23
+ end
133
24
  end
25
+ end
26
+
27
+ def test_parse_dictionary
28
+ dict = Dictionary.parse("<</Ref 2 0 R/N null/Pi 3.14 /D <<>>>>")
29
+
30
+ assert_instance_of Dictionary, dict
31
+ assert_instance_of Dictionary, dict[:D]
32
+ assert_instance_of Null, dict[:N]
33
+ assert_instance_of Reference, dict[:Ref]
34
+ assert_equal dict.size, 4
35
+ assert_raises(InvalidReferenceError) { dict[:Ref].solve }
36
+ assert dict[:Pi] == 3.14
37
+ end
38
+
39
+ def test_parse_array
40
+ array = Origami::Array.parse("[/Test (abc) .2 \n 799 [<<>>]]")
41
+
42
+ assert array.all? { |e| e.is_a?(Origami::Object) }
43
+ assert_equal array.length, 5
44
+ assert_raises(InvalidArrayObjectError) { Origami::Array.parse("[1 ") }
45
+ assert_raises(InvalidArrayObjectError) { Origami::Array.parse("") }
46
+ end
47
+
48
+ def test_parse_string
49
+ str = LiteralString.parse("(\\122\\125by\\n)")
50
+ assert_instance_of LiteralString, str
51
+ assert_equal str.value, "RUby\n"
52
+
53
+ assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("") }
54
+ assert_raises(InvalidLiteralStringObjectError) { LiteralString.parse("(test") }
55
+ assert_equal "((O))", LiteralString.parse("(((O)))").value
56
+ assert_equal LiteralString.parse("(ABC\\\nDEF\\\r\nGHI)").value, "ABCDEFGHI"
57
+ assert_equal LiteralString.parse('(\r\n\b\t\f\\(\\)\\x\\\\)').value, "\r\n\b\t\f()x\\"
58
+ assert_equal LiteralString.parse('(\r\n\b\t\f\\\\\\(\\))').to_s, '(\r\n\b\t\f\\\\\\(\\))'
59
+
60
+ str = HexaString.parse("<52 55 62 79 0A>")
61
+ assert_instance_of HexaString, str
62
+ assert_equal str.value, "RUby\n"
63
+
64
+ assert_equal HexaString.parse("<4>").value, 0x40.chr
65
+
66
+ assert_raises(InvalidHexaStringObjectError) { HexaString.parse("") }
67
+ assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12") }
68
+ assert_raises(InvalidHexaStringObjectError) { HexaString.parse("<12X>") }
69
+ end
70
+
71
+ def test_parse_bool
72
+ b_true = Boolean.parse("true")
73
+ b_false = Boolean.parse("false")
74
+
75
+ assert_instance_of Boolean, b_true
76
+ assert_instance_of Boolean, b_false
77
+
78
+ assert b_false.false?
79
+ refute b_true.false?
80
+
81
+ assert_raises(InvalidBooleanObjectError) { Boolean.parse("") }
82
+ assert_raises(InvalidBooleanObjectError) { Boolean.parse("tru") }
83
+ end
84
+
85
+ def test_parse_real
86
+ real = Real.parse("-3.141592653")
87
+ assert_instance_of Real, real
88
+ assert_equal real, -3.141592653
89
+
90
+ real = Real.parse("+.00200")
91
+ assert_instance_of Real, real
92
+ assert_equal real, 0.002
93
+
94
+ assert_raises(InvalidRealObjectError) { Real.parse("") }
95
+ assert_raises(InvalidRealObjectError) { Real.parse(".") }
96
+ assert_raises(InvalidRealObjectError) { Real.parse("+0x1") }
97
+ end
98
+
99
+ def test_parse_int
100
+ int = Origami::Integer.parse("02000000000000")
101
+ assert_instance_of Origami::Integer, int
102
+ assert_equal int, 2000000000000
103
+
104
+ int = Origami::Integer.parse("-98")
105
+ assert_instance_of Origami::Integer, int
106
+ assert_equal int, -98
107
+
108
+ assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("") }
109
+ assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("+-1") }
110
+ assert_raises(Origami::InvalidIntegerObjectError) { Origami::Integer.parse("ABC") }
111
+ end
112
+
113
+ def test_parse_name
114
+ name = Name.parse("/#52#55#62#79#0A")
115
+ assert_instance_of Name, name
116
+ assert_equal name.value, :"RUby\n"
117
+
118
+ name = Name.parse("/")
119
+ assert_instance_of Name, name
120
+ assert_equal :"", name.value
121
+
122
+ assert_raises(Origami::InvalidNameObjectError) { Name.parse("") }
123
+ assert_raises(Origami::InvalidNameObjectError) { Name.parse("test") }
124
+ end
125
+
126
+ def test_parse_reference
127
+ ref = Reference.parse("199 1 R")
128
+ assert_instance_of Reference, ref
129
+
130
+ assert_equal [199, 1], ref.to_a
131
+ assert_raises(InvalidReferenceError) { ref.solve }
132
+ assert_raises(InvalidReferenceError) { Reference.parse("-2 0 R") }
133
+ assert_raises(InvalidReferenceError) { Reference.parse("0 R") }
134
+ assert_raises(InvalidReferenceError) { Reference.parse("") }
135
+ end
134
136
  end
@@ -1,69 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'minitest/autorun'
2
4
  require 'stringio'
3
5
 
4
6
  class TestPDFLazyParser < Minitest::Test
5
-
6
- def setup
7
- @files =
8
- %w{
9
- dataset/empty.pdf
10
- dataset/calc.pdf
11
- dataset/crypto.pdf
12
- }
13
-
7
+ def setup
8
+ @files =
9
+ %w[
10
+ dataset/empty.pdf
11
+ dataset/calc.pdf
12
+ dataset/crypto.pdf
13
+ ]
14
+ end
15
+
16
+ def test_parse_pdf_lazy
17
+ @files.each do |file|
18
+ pdf = PDF.read(File.join(__dir__, file),
19
+ ignore_errors: false,
20
+ lazy: true,
21
+ verbosity: Parser::VERBOSE_QUIET)
22
+
23
+ assert_instance_of PDF, pdf
24
+
25
+ pdf.each_object do |object|
26
+ assert_kind_of Origami::Object, object
27
+ end
28
+
29
+ assert_instance_of Catalog, pdf.Catalog
30
+
31
+ pdf.each_page do |page|
32
+ assert_kind_of Page, page
33
+ end
14
34
  end
35
+ end
15
36
 
16
- def test_parse_pdf_lazy
17
- @files.each do |file|
18
- pdf = PDF.read(File.join(__dir__, file),
19
- ignore_errors: false,
20
- lazy: true,
21
- verbosity: Parser::VERBOSE_QUIET)
22
-
23
- assert_instance_of PDF, pdf
24
-
25
- pdf.each_object do |object|
26
- assert_kind_of Origami::Object, object
27
- end
37
+ def test_save_pdf_lazy
38
+ @files.each do |file|
39
+ pdf = PDF.read(File.join(__dir__, file),
40
+ ignore_errors: false,
41
+ lazy: true,
42
+ verbosity: Parser::VERBOSE_QUIET)
28
43
 
29
- assert_instance_of Catalog, pdf.Catalog
30
-
31
- pdf.each_page do |page|
32
- assert_kind_of Page, page
33
- end
34
- end
44
+ pdf.save(StringIO.new)
35
45
  end
46
+ end
36
47
 
37
- def test_save_pdf_lazy
38
- @files.each do |file|
39
- pdf = PDF.read(File.join(__dir__, file),
40
- ignore_errors: false,
41
- lazy: true,
42
- verbosity: Parser::VERBOSE_QUIET)
48
+ def test_random_access
49
+ io = StringIO.new
50
+ stream = Stream.new("abc")
43
51
 
44
- pdf.save(StringIO.new)
45
- end
52
+ PDF.create(io) do |pdf|
53
+ pdf.insert(stream)
46
54
  end
47
55
 
48
- def test_random_access
49
- io = StringIO.new
50
- stream = Stream.new("abc")
51
-
52
- PDF.create(io) do |pdf|
53
- pdf.insert(stream)
54
- end
56
+ io = io.reopen(io.string, 'r')
55
57
 
56
- io = io.reopen(io.string, 'r')
58
+ pdf = PDF.read(io, ignore_errors: false,
59
+ lazy: true,
60
+ verbosity: Parser::VERBOSE_QUIET)
57
61
 
58
- pdf = PDF.read(io, ignore_errors: false,
59
- lazy: true,
60
- verbosity: Parser::VERBOSE_QUIET)
62
+ non_existent = pdf[42]
63
+ existent = pdf[stream.reference]
61
64
 
62
- non_existent = pdf[42]
63
- existent = pdf[stream.reference]
64
-
65
- assert_nil non_existent
66
- assert_instance_of Stream, existent
67
- assert_equal stream.data, existent.data
68
- end
65
+ assert_nil non_existent
66
+ assert_instance_of Stream, existent
67
+ assert_equal stream.data, existent.data
68
+ end
69
69
  end