pnm 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 66de49354358fed31c8299381599bb8b16d87d2143e2102ca61da00e6b8b2927
4
- data.tar.gz: 2bd7e0d7491be12b5562c3a1de19ee7e538d95c3535fc9bb92723726b5e5787c
3
+ metadata.gz: 5a3dd7ccd09f9d5a2f16212910e8aba16f25c78648e965c42847a86bc057632e
4
+ data.tar.gz: 7f22c53142d2317692fa2e840a6b12758e39990123c1d297d9624abc26a71c4b
5
5
  SHA512:
6
- metadata.gz: bd83d15feb8b65b28b43f64cd48ab23a5e3f710a991f781c43d6d74bc9ea9a02cb905d61bae70af1fe2476c551ece310050eccd0210acb5701d87efb40d61173
7
- data.tar.gz: 574e62b56e1ac1fea7a9110f1c01c805f373bfafd50210bb2145fca4086054d7d1ace113d1e46eadfe0b5c9314b3ca221168cdc2dba2e7168742615a7462e728
6
+ metadata.gz: c7ca3afc52aac295f564ecb5222c1339ce9ae623db0213ee7c878d05591396d735a76e0a19d62acce0cb095802352ebd1f1442ea4a803c32aa2bc4d8bf169289
7
+ data.tar.gz: '08e3653dd113aabd4333c789a4077b95733a18f3422db4e6006e7f534692f365f35474791dfb6d8c66716bb5c6e16ced1f07e2fbf7b36e6ba2842a09911c00b1'
data/README.md CHANGED
@@ -98,10 +98,9 @@ Requirements
98
98
 
99
99
  - PNM has been tested with
100
100
 
101
- - Ruby 2.6, 2.5, 2.4, 2.3, 2.2, 2.1,
102
- - Ruby 2.0.0,
103
- - Ruby 1.9.3,
104
- - JRuby 1.7.19,
101
+ - Ruby 2.7
102
+ - Ruby 2.6, 2.5, 2.4, 2.3, 2.2, 2.1, 2.0.0, 1.9.3,
103
+ - JRuby 9.2.9.0,
105
104
  - Rubinius 2.5.2.
106
105
 
107
106
  Documentation
@@ -118,7 +117,7 @@ Report bugs on the PNM home page: <https://github.com/stomar/pnm/>
118
117
  License
119
118
  -------
120
119
 
121
- Copyright &copy; 2013-2019 Marcus Stollsteimer
120
+ Copyright &copy; 2013-2020 Marcus Stollsteimer
122
121
 
123
122
  `PNM` is free software: you can redistribute it and/or modify
124
123
  it under the terms of the GNU General Public License version 3 or later (GPLv3+),
data/Rakefile CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # rakefile for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "rake/testtask"
8
8
 
@@ -3,7 +3,7 @@
3
3
 
4
4
  # bm_converter.rb: Benchmarks for the PNM library.
5
5
  #
6
- # Copyright (C) 2013-2019 Marcus Stollsteimer
6
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
7
7
 
8
8
  require "benchmark"
9
9
  require_relative "../lib/pnm"
data/lib/pnm.rb CHANGED
@@ -87,7 +87,7 @@ require_relative "pnm/exceptions"
87
87
  #
88
88
  # == Author
89
89
  #
90
- # Copyright (C) 2013-2019 Marcus Stollsteimer
90
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
91
91
  #
92
92
  # License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
93
93
  #
@@ -98,7 +98,7 @@ module PNM
98
98
  TAGLINE = "create/read/write PNM image files (PBM, PGM, PPM)"
99
99
 
100
100
  COPYRIGHT = <<-TEXT.gsub(/^ +/, "")
101
- Copyright (C) 2013-2019 Marcus Stollsteimer.
101
+ Copyright (C) 2013-2020 Marcus Stollsteimer.
102
102
  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
103
103
  This is free software: you are free to change and redistribute it.
104
104
  There is NO WARRANTY, to the extent permitted by law.
data/lib/pnm/converter.rb CHANGED
@@ -113,8 +113,8 @@ module PNM
113
113
  end
114
114
 
115
115
  values_as_string.map {|value| Integer(value) }
116
- rescue ::ArgumentError => error
117
- raise unless error.message.start_with?("invalid value for Integer")
116
+ rescue ::ArgumentError => e
117
+ raise unless e.message.start_with?("invalid value for Integer")
118
118
 
119
119
  raise PNM::DataError, "invalid pixel value: Integer expected"
120
120
  end
data/lib/pnm/parser.rb CHANGED
@@ -22,7 +22,7 @@ module PNM
22
22
  content = content.dup
23
23
 
24
24
  magic_number = nil
25
- tokens = []
25
+ tokens = []
26
26
  comments = []
27
27
 
28
28
  until magic_number
@@ -50,17 +50,17 @@ module PNM
50
50
 
51
51
  width, height, maxgray = tokens
52
52
 
53
- assert_integer(width, "width")
54
- assert_integer(height, "height")
53
+ assert_integer(width, "width")
54
+ assert_integer(height, "height")
55
55
  assert_integer(maxgray, "maxgray") if maxgray
56
56
 
57
- width = width.to_i
58
- height = height.to_i
57
+ width = width.to_i
58
+ height = height.to_i
59
59
  maxgray = maxgray.to_i if maxgray
60
60
 
61
- assert_value(width, "width") {|x| x > 0 }
62
- assert_value(height, "height") {|x| x > 0 }
63
- assert_value(maxgray, "maxgray") {|x| x > 0 && x <= 255 } if maxgray
61
+ assert_positive(width, "width")
62
+ assert_positive(height, "height")
63
+ assert_in_maxgray_range(maxgray) if maxgray
64
64
 
65
65
  result = {
66
66
  magic_number: magic_number,
@@ -114,10 +114,17 @@ module PNM
114
114
  raise PNM::ParserError, msg
115
115
  end
116
116
 
117
- def self.assert_value(value, name)
118
- return if yield(value)
117
+ def self.assert_positive(value, name)
118
+ return if value > 0
119
119
 
120
- msg = "invalid #{name} value - `#{value}'"
120
+ msg = "#{name} must be greater than 0 - `#{value}'"
121
+ raise PNM::ParserError, msg
122
+ end
123
+
124
+ def self.assert_in_maxgray_range(value)
125
+ return if value > 0 && value <= 255
126
+
127
+ msg = "invalid maxgray value - `#{value}'"
121
128
  raise PNM::ParserError, msg
122
129
  end
123
130
  end
data/lib/pnm/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PNM
4
- VERSION = "0.5.2"
5
- DATE = "2019-02-09"
4
+ VERSION = "0.5.3"
5
+ DATE = "2020-01-19"
6
6
  end
data/test/backports.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PNM
4
+ module Backports # :nodoc:
5
+ module Minitest # :nodoc:
6
+
7
+ # Provides workaround for missing value wrappers in minitest < 5.6.0.
8
+ def _(value = nil, &block)
9
+ block || value
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+
16
+ if Gem.loaded_specs["minitest"].version < Gem::Version.new("5.6.0")
17
+ warn "Using workaround for missing value wrappers in minitest < 5.6.0."
18
+ include PNM::Backports::Minitest
19
+ end
@@ -2,11 +2,13 @@
2
2
 
3
3
  # test_converter.rb: Unit tests for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "minitest/autorun"
8
8
  require "pnm/converter"
9
9
 
10
+ require_relative "backports"
11
+
10
12
 
11
13
  describe PNM::Converter do
12
14
 
@@ -56,7 +58,7 @@ describe PNM::Converter do
56
58
  data = @pbm[:ascii]
57
59
  expected = @pbm[:array]
58
60
 
59
- @converter.ascii2array(:pbm, width, height, data).must_equal expected
61
+ _(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
60
62
  end
61
63
 
62
64
  it "can convert from ASCII encoded PGM data" do
@@ -65,7 +67,7 @@ describe PNM::Converter do
65
67
  data = @pgm[:ascii]
66
68
  expected = @pgm[:array]
67
69
 
68
- @converter.ascii2array(:pgm, width, height, data).must_equal expected
70
+ _(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
69
71
  end
70
72
 
71
73
  it "can convert from ASCII encoded PPM data" do
@@ -74,7 +76,7 @@ describe PNM::Converter do
74
76
  data = @ppm[:ascii]
75
77
  expected = @ppm[:array]
76
78
 
77
- @converter.ascii2array(:ppm, width, height, data).must_equal expected
79
+ _(@converter.ascii2array(:ppm, width, height, data)).must_equal expected
78
80
  end
79
81
 
80
82
  it "accepts ASCII encoded PBM data with omitted whitespace" do
@@ -83,7 +85,7 @@ describe PNM::Converter do
83
85
  data = " 010100\n000110"
84
86
  expected = [[0, 1, 0, 1], [0, 0, 0, 0], [0, 1, 1, 0]]
85
87
 
86
- @converter.ascii2array(:pbm, width, height, data).must_equal expected
88
+ _(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
87
89
  end
88
90
 
89
91
  it "accepts ASCII encoded PGM data with arbitrary whitespace" do
@@ -92,7 +94,7 @@ describe PNM::Converter do
92
94
  data = " \n 10 90\t170\r250\n90 \t170 250 \t\r\n\t 10\n\n\n170\n250\n10\n90\n"
93
95
  expected = [[10, 90, 170, 250], [90, 170, 250, 10], [170, 250, 10, 90]]
94
96
 
95
- @converter.ascii2array(:pgm, width, height, data).must_equal expected
97
+ _(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
96
98
  end
97
99
 
98
100
  it "can convert from binary encoded PBM data (width 6)" do
@@ -101,7 +103,7 @@ describe PNM::Converter do
101
103
  data = @pbm6[:binary]
102
104
  expected = @pbm6[:array]
103
105
 
104
- @converter.binary2array(:pbm, width, height, data).must_equal expected
106
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
105
107
  end
106
108
 
107
109
  it "can convert from binary encoded PBM data (width 14)" do
@@ -110,7 +112,7 @@ describe PNM::Converter do
110
112
  data = @pbm14[:binary]
111
113
  expected = @pbm14[:array]
112
114
 
113
- @converter.binary2array(:pbm, width, height, data).must_equal expected
115
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
114
116
  end
115
117
 
116
118
  it "can convert from binary encoded PGM data" do
@@ -119,7 +121,7 @@ describe PNM::Converter do
119
121
  data = @pgm[:binary]
120
122
  expected = @pgm[:array]
121
123
 
122
- @converter.binary2array(:pgm, width, height, data).must_equal expected
124
+ _(@converter.binary2array(:pgm, width, height, data)).must_equal expected
123
125
  end
124
126
 
125
127
  it "can convert from binary encoded PPM data" do
@@ -128,7 +130,7 @@ describe PNM::Converter do
128
130
  data = @ppm[:binary]
129
131
  expected = @ppm[:array]
130
132
 
131
- @converter.binary2array(:ppm, width, height, data).must_equal expected
133
+ _(@converter.binary2array(:ppm, width, height, data)).must_equal expected
132
134
  end
133
135
 
134
136
  it "accepts an additional whitespace character for binary encoded data" do
@@ -137,73 +139,73 @@ describe PNM::Converter do
137
139
  data = @pbm14[:binary] + "\t"
138
140
  expected = @pbm14[:array]
139
141
 
140
- @converter.binary2array(:pbm, width, height, data).must_equal expected
142
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
141
143
  end
142
144
 
143
145
  it "can convert to ASCII encoded PBM data" do
144
146
  data = @pbm[:array]
145
147
  expected = @pbm[:ascii]
146
148
 
147
- @converter.array2ascii(data).must_equal expected
149
+ _(@converter.array2ascii(data)).must_equal expected
148
150
  end
149
151
 
150
152
  it "can convert to ASCII encoded PGM data" do
151
153
  data = @pgm[:array]
152
154
  expected = @pgm[:ascii]
153
155
 
154
- @converter.array2ascii(data).must_equal expected
156
+ _(@converter.array2ascii(data)).must_equal expected
155
157
  end
156
158
 
157
159
  it "can convert to ASCII encoded PPM data" do
158
160
  data = @ppm[:array]
159
161
  expected = @ppm[:ascii]
160
162
 
161
- @converter.array2ascii(data).must_equal expected
163
+ _(@converter.array2ascii(data)).must_equal expected
162
164
  end
163
165
 
164
166
  it "can convert to binary encoded PBM data (width 6)" do
165
167
  data = @pbm6[:array]
166
168
  expected = @pbm6[:binary]
167
169
 
168
- @converter.array2binary(:pbm, data).must_equal expected
170
+ _(@converter.array2binary(:pbm, data)).must_equal expected
169
171
  end
170
172
 
171
173
  it "can convert to binary encoded PBM data (width 14)" do
172
174
  data = @pbm14[:array]
173
175
  expected = @pbm14[:binary]
174
176
 
175
- @converter.array2binary(:pbm, data).must_equal expected
177
+ _(@converter.array2binary(:pbm, data)).must_equal expected
176
178
  end
177
179
 
178
180
  it "can convert to binary encoded PGM data" do
179
181
  data = @pgm[:array]
180
182
  expected = @pgm[:binary]
181
183
 
182
- @converter.array2binary(:pgm, data).must_equal expected
184
+ _(@converter.array2binary(:pgm, data)).must_equal expected
183
185
  end
184
186
 
185
187
  it "can convert to binary encoded PPM data" do
186
188
  data = @ppm[:array]
187
189
  expected = @ppm[:binary]
188
190
 
189
- @converter.array2binary(:ppm, data).must_equal expected
191
+ _(@converter.array2binary(:ppm, data)).must_equal expected
190
192
  end
191
193
 
192
194
  it "can calculate correct byte widths for a PBM image" do
193
- @converter.byte_width(:pbm, 0).must_equal 0
194
- @converter.byte_width(:pbm, 1).must_equal 1
195
- @converter.byte_width(:pbm, 7).must_equal 1
196
- @converter.byte_width(:pbm, 8).must_equal 1
197
- @converter.byte_width(:pbm, 9).must_equal 2
198
- @converter.byte_width(:pbm, 64).must_equal 8
199
- @converter.byte_width(:pbm, 65).must_equal 9
195
+ _(@converter.byte_width(:pbm, 0)).must_equal 0
196
+ _(@converter.byte_width(:pbm, 1)).must_equal 1
197
+ _(@converter.byte_width(:pbm, 7)).must_equal 1
198
+ _(@converter.byte_width(:pbm, 8)).must_equal 1
199
+ _(@converter.byte_width(:pbm, 9)).must_equal 2
200
+ _(@converter.byte_width(:pbm, 64)).must_equal 8
201
+ _(@converter.byte_width(:pbm, 65)).must_equal 9
200
202
  end
201
203
 
202
204
  it "can calculate correct byte widths for a PGM image" do
203
- @converter.byte_width(:pgm, 13).must_equal 13
205
+ _(@converter.byte_width(:pgm, 13)).must_equal 13
204
206
  end
205
207
 
206
208
  it "can calculate correct byte widths for a PPM image" do
207
- @converter.byte_width(:ppm, 13).must_equal 39
209
+ _(@converter.byte_width(:ppm, 13)).must_equal 39
208
210
  end
209
211
  end
@@ -2,123 +2,125 @@
2
2
 
3
3
  # test_exceptions.rb: Unit tests for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "minitest/autorun"
8
8
  require "stringio"
9
9
  require "pnm"
10
10
 
11
+ require_relative "backports"
12
+
11
13
 
12
14
  describe "PNM.create" do
13
15
 
14
16
  it "raises an exception for invalid data type (String)" do
15
17
  data = "0"
16
- proc { PNM.create(data) }.must_raise PNM::ArgumentError
18
+ _ { PNM.create(data) }.must_raise PNM::ArgumentError
17
19
  end
18
20
 
19
21
  it "raises an exception for invalid type" do
20
22
  data = [[0, 0], [0, 0]]
21
- proc { PNM.create(data, type: :abc) }.must_raise PNM::ArgumentError
23
+ _ { PNM.create(data, type: :abc) }.must_raise PNM::ArgumentError
22
24
  end
23
25
 
24
26
  it "raises an exception for invalid maxgray (String)" do
25
27
  data = [[0, 0], [0, 0]]
26
- proc { PNM.create(data, maxgray: "255") }.must_raise PNM::ArgumentError
28
+ _ { PNM.create(data, maxgray: "255") }.must_raise PNM::ArgumentError
27
29
  end
28
30
 
29
31
  it "raises an exception for invalid maxgray (> 255)" do
30
32
  data = [[0, 0], [0, 0]]
31
- proc { PNM.create(data, maxgray: 256) }.must_raise PNM::ArgumentError
33
+ _ { PNM.create(data, maxgray: 256) }.must_raise PNM::ArgumentError
32
34
  end
33
35
 
34
36
  it "raises an exception for invalid maxgray (0)" do
35
37
  data = [[0, 0], [0, 0]]
36
- proc { PNM.create(data, maxgray: 0) }.must_raise PNM::ArgumentError
38
+ _ { PNM.create(data, maxgray: 0) }.must_raise PNM::ArgumentError
37
39
  end
38
40
 
39
41
  it "raises an exception for invalid comment (Integer)" do
40
42
  data = [[0, 0], [0, 0]]
41
- proc { PNM.create(data, comment: 1) }.must_raise PNM::ArgumentError
43
+ _ { PNM.create(data, comment: 1) }.must_raise PNM::ArgumentError
42
44
  end
43
45
 
44
46
  it "raises an exception for image type and data mismatch (PBM)" do
45
47
  data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
46
- proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
48
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
47
49
  end
48
50
 
49
51
  it "raises an exception for image type and data mismatch (PGM)" do
50
52
  data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
51
- proc { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
53
+ _ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
52
54
  end
53
55
 
54
56
  it "raises an exception for non-integer pixel value (String)" do
55
57
  data = [[0, 0], ["X", 0]]
56
- proc { PNM.create(data) }.must_raise PNM::DataError
58
+ _ { PNM.create(data) }.must_raise PNM::DataError
57
59
  end
58
60
 
59
61
  it "raises an exception for non-integer pixel value (Float)" do
60
62
  data = [[0, 0], [0.5, 0]]
61
- proc { PNM.create(data) }.must_raise PNM::DataError
63
+ _ { PNM.create(data) }.must_raise PNM::DataError
62
64
  end
63
65
 
64
66
  it "raises an exception for rows of different size" do
65
67
  data = [[0, 0], [0, 0, 0]]
66
- proc { PNM.create(data) }.must_raise PNM::DataError
68
+ _ { PNM.create(data) }.must_raise PNM::DataError
67
69
  end
68
70
 
69
71
  it "raises an exception for invalid array dimensions (#1)" do
70
72
  data = [0, 0, 0]
71
- proc { PNM.create(data) }.must_raise PNM::DataError
73
+ _ { PNM.create(data) }.must_raise PNM::DataError
72
74
  end
73
75
 
74
76
  it "raises an exception for invalid array dimensions (#2)" do
75
77
  data = [[0, 0], 0, 0]
76
- proc { PNM.create(data) }.must_raise PNM::DataError
78
+ _ { PNM.create(data) }.must_raise PNM::DataError
77
79
  end
78
80
 
79
81
  it "raises an exception for invalid array dimensions (#3)" do
80
82
  data = [[0, 0], [0, [0, 0]]]
81
- proc { PNM.create(data) }.must_raise PNM::DataError
83
+ _ { PNM.create(data) }.must_raise PNM::DataError
82
84
  end
83
85
 
84
86
  it "raises an exception for invalid array dimensions (#4)" do
85
87
  data = [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
86
- proc { PNM.create(data) }.must_raise PNM::DataError
88
+ _ { PNM.create(data) }.must_raise PNM::DataError
87
89
  end
88
90
 
89
91
  it "raises an exception for invalid array dimensions (#5)" do
90
92
  data = [[[0, 0, 0], [0, 0, 0]], [0, 0]]
91
- proc { PNM.create(data) }.must_raise PNM::DataError
93
+ _ { PNM.create(data) }.must_raise PNM::DataError
92
94
  end
93
95
 
94
96
  it "raises an exception for invalid array dimensions (#6)" do
95
97
  data = [[[0, 0, 0], 0], [0, 0]]
96
- proc { PNM.create(data) }.must_raise PNM::DataError
98
+ _ { PNM.create(data) }.must_raise PNM::DataError
97
99
  end
98
100
 
99
101
  it "raises an exception for an empty array" do
100
102
  data = [[]]
101
- proc { PNM.create(data) }.must_raise PNM::DataError
103
+ _ { PNM.create(data) }.must_raise PNM::DataError
102
104
  end
103
105
 
104
106
  it "raises an exception for invalid PBM data (> 1)" do
105
107
  data = [[0, 0], [2, 0]]
106
- proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
108
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
107
109
  end
108
110
 
109
111
  it "raises an exception for invalid PBM data (< 0)" do
110
112
  data = [[0, 0], [-1, 0]]
111
- proc { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
113
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
112
114
  end
113
115
 
114
116
  it "raises an exception for invalid PGM data (> 255)" do
115
117
  data = [[0, 0], [1, 500]]
116
- proc { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
118
+ _ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
117
119
  end
118
120
 
119
121
  it "raises an exception for invalid PGM data (> maxgray)" do
120
122
  data = [[0, 0], [1, 200]]
121
- proc { PNM.create(data, maxgray: 100) }.must_raise PNM::DataError
123
+ _ { PNM.create(data, maxgray: 100) }.must_raise PNM::DataError
122
124
  end
123
125
  end
124
126
 
@@ -126,111 +128,111 @@ end
126
128
  describe "PNM.read" do
127
129
 
128
130
  it "raises an exception for integer argument" do
129
- proc { PNM.read(123) }.must_raise PNM::ArgumentError
131
+ _ { PNM.read(123) }.must_raise PNM::ArgumentError
130
132
  end
131
133
 
132
134
  it "raises an exception for unknown magic number" do
133
135
  file = StringIO.new("P0 1 1 0")
134
- proc { PNM.read(file) }.must_raise PNM::ParserError
136
+ _ { PNM.read(file) }.must_raise PNM::ParserError
135
137
  end
136
138
 
137
139
  it "raises an exception for an empty file" do
138
140
  file = StringIO.new("")
139
- proc { PNM.read(file) }.must_raise PNM::ParserError
141
+ _ { PNM.read(file) }.must_raise PNM::ParserError
140
142
  end
141
143
 
142
144
  it "raises an exception for missing tokens (#1)" do
143
145
  file = StringIO.new("P1")
144
- proc { PNM.read(file) }.must_raise PNM::ParserError
146
+ _ { PNM.read(file) }.must_raise PNM::ParserError
145
147
  end
146
148
 
147
149
  it "raises an exception for missing tokens (#2)" do
148
150
  file = StringIO.new("P1 1")
149
- proc { PNM.read(file) }.must_raise PNM::ParserError
151
+ _ { PNM.read(file) }.must_raise PNM::ParserError
150
152
  end
151
153
 
152
154
  it "raises an exception for missing tokens (#3)" do
153
155
  file = StringIO.new("P1 1 ")
154
- proc { PNM.read(file) }.must_raise PNM::ParserError
156
+ _ { PNM.read(file) }.must_raise PNM::ParserError
155
157
  end
156
158
 
157
159
  it "raises an exception for missing tokens (#4)" do
158
160
  file = StringIO.new("P1 1 1")
159
- proc { PNM.read(file) }.must_raise PNM::ParserError
161
+ _ { PNM.read(file) }.must_raise PNM::ParserError
160
162
  end
161
163
 
162
164
  it "raises an exception for missing tokens (#5)" do
163
165
  file = StringIO.new("P1 1 # Test\n 1")
164
- proc { PNM.read(file) }.must_raise PNM::ParserError
166
+ _ { PNM.read(file) }.must_raise PNM::ParserError
165
167
  end
166
168
 
167
169
  it "raises an exception for missing tokens (#6)" do
168
170
  file = StringIO.new("P2 1 1 255")
169
- proc { PNM.read(file) }.must_raise PNM::ParserError
171
+ _ { PNM.read(file) }.must_raise PNM::ParserError
170
172
  end
171
173
 
172
174
  it "raises an exception for token of wrong type (#1)" do
173
175
  file = StringIO.new("P1 ? 1 0")
174
- proc { PNM.read(file) }.must_raise PNM::ParserError
176
+ _ { PNM.read(file) }.must_raise PNM::ParserError
175
177
  end
176
178
 
177
179
  it "raises an exception for token of wrong type (#2)" do
178
180
  file = StringIO.new("P1 1 X 0")
179
- proc { PNM.read(file) }.must_raise PNM::ParserError
181
+ _ { PNM.read(file) }.must_raise PNM::ParserError
180
182
  end
181
183
 
182
184
  it "raises an exception for token of wrong type (#3)" do
183
185
  file = StringIO.new("P2 1 1 foo 0")
184
- proc { PNM.read(file) }.must_raise PNM::ParserError
186
+ _ { PNM.read(file) }.must_raise PNM::ParserError
185
187
  end
186
188
 
187
189
  it "raises an exception for zero width" do
188
190
  file = StringIO.new("P2 0 1 255 0")
189
- proc { PNM.read(file) }.must_raise PNM::ParserError
191
+ _ { PNM.read(file) }.must_raise PNM::ParserError
190
192
  end
191
193
 
192
194
  it "raises an exception for zero height" do
193
195
  file = StringIO.new("P2 1 0 255 0")
194
- proc { PNM.read(file) }.must_raise PNM::ParserError
196
+ _ { PNM.read(file) }.must_raise PNM::ParserError
195
197
  end
196
198
 
197
199
  it "raises an exception for invalid maxgray (> 255)" do
198
200
  file = StringIO.new("P2 1 1 256 0")
199
- proc { PNM.read(file) }.must_raise PNM::ParserError
201
+ _ { PNM.read(file) }.must_raise PNM::ParserError
200
202
  end
201
203
 
202
204
  it "raises an exception for invalid maxgray (0)" do
203
205
  file = StringIO.new("P2 1 1 0 0")
204
- proc { PNM.read(file) }.must_raise PNM::ParserError
206
+ _ { PNM.read(file) }.must_raise PNM::ParserError
205
207
  end
206
208
 
207
209
  it "raises an exception for image dimension mismatch (#1)" do
208
210
  file = StringIO.new("P1 2 3 0 0 0 0 0")
209
- proc { PNM.read(file) }.must_raise PNM::DataSizeError
211
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
210
212
  end
211
213
 
212
214
  it "raises an exception for image dimension mismatch (#2)" do
213
215
  file = StringIO.new("P1 2 3 0 0 0 0 0 0 0")
214
- proc { PNM.read(file) }.must_raise PNM::DataSizeError
216
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
215
217
  end
216
218
 
217
219
  it "raises an exception for image dimension mismatch (#3)" do
218
220
  file = StringIO.new("P3 2 3 255 0 0 0 0 0 0")
219
- proc { PNM.read(file) }.must_raise PNM::DataSizeError
221
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
220
222
  end
221
223
 
222
224
  it "raises an exception for image dimension mismatch (#4)" do
223
225
  file = StringIO.new("P5 2 3 255 AAAAAAA")
224
- proc { PNM.read(file) }.must_raise PNM::DataSizeError
226
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
225
227
  end
226
228
 
227
229
  it "raises an exception for image dimension mismatch (#5)" do
228
230
  file = StringIO.new("P5 2 3 255 AAAAAAA")
229
- proc { PNM.read(file) }.must_raise PNM::DataSizeError
231
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
230
232
  end
231
233
 
232
234
  it "raises an exception for non-numeric image data" do
233
235
  file = StringIO.new("P1 2 3 0 X 0 0 0 0")
234
- proc { PNM.read(file) }.must_raise PNM::DataError
236
+ _ { PNM.read(file) }.must_raise PNM::DataError
235
237
  end
236
238
  end
data/test/test_image.rb CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  # test_image.rb: Unit tests for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "minitest/autorun"
8
8
  require "pnm"
9
9
 
10
+ require_relative "backports"
11
+
10
12
 
11
13
  describe PNM::Image do
12
14
 
@@ -47,229 +49,229 @@ describe PNM::Image do
47
49
  end
48
50
 
49
51
  it "freezes pixel data" do
50
- proc { @bilevel.pixels << [1, 1, 0, 1, 1] }.must_raise RuntimeError
52
+ _ { @bilevel.pixels << [1, 1, 0, 1, 1] }.must_raise RuntimeError
51
53
  end
52
54
 
53
55
  it "freezes comment string" do
54
- proc { @bilevel.comment << "string" }.must_raise RuntimeError
56
+ _ { @bilevel.comment << "string" }.must_raise RuntimeError
55
57
  end
56
58
 
57
59
  it "sets maxgray to 1 for bilevel images" do
58
60
  image = PNM.create([[0, 1, 0], [1, 0, 1]])
59
- image.type.must_equal :pbm
60
- image.maxgray.must_equal 1
61
+ _(image.type).must_equal :pbm
62
+ _(image.maxgray).must_equal 1
61
63
  end
62
64
 
63
65
  it "sets maxgray by default to 255 for grayscale images" do
64
66
  image = PNM.create([[0, 10, 20], [10, 20, 30]])
65
- image.type.must_equal :pgm
66
- image.maxgray.must_equal 255
67
+ _(image.type).must_equal :pgm
68
+ _(image.maxgray).must_equal 255
67
69
  end
68
70
 
69
71
  it "sets maxgray by default to 255 for color images" do
70
72
  image = PNM.create([[[0, 0, 0], [10, 10, 10]], [[10, 10, 10], [20, 20, 20]]])
71
- image.type.must_equal :ppm
72
- image.maxgray.must_equal 255
73
+ _(image.type).must_equal :ppm
74
+ _(image.maxgray).must_equal 255
73
75
  end
74
76
 
75
77
  it "accepts setting of maxgray to 1 for bilevel images" do
76
78
  image = PNM.create([[0, 1, 0], [1, 0, 1]], maxgray: 1)
77
- image.type.must_equal :pbm
78
- image.maxgray.must_equal 1
79
+ _(image.type).must_equal :pbm
80
+ _(image.maxgray).must_equal 1
79
81
  end
80
82
 
81
83
  it "ignores invalid maxgray for bilevel images and sets it to 1" do
82
84
  image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :pbm, maxgray: 255)
83
- image.type.must_equal :pbm
84
- image.maxgray.must_equal 1
85
+ _(image.type).must_equal :pbm
86
+ _(image.maxgray).must_equal 1
85
87
  end
86
88
 
87
89
  it "can create a grayscale image from bilevel values (using type)" do
88
90
  image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :pgm)
89
- image.type.must_equal :pgm
90
- image.pixels.must_equal [[0, 1, 0], [1, 0, 1]]
91
- image.maxgray.must_equal 255
91
+ _(image.type).must_equal :pgm
92
+ _(image.pixels).must_equal [[0, 1, 0], [1, 0, 1]]
93
+ _(image.maxgray).must_equal 255
92
94
  end
93
95
 
94
96
  it "also accepts types given as string instead of symbol" do
95
97
  image = PNM.create([[0, 1, 0], [1, 0, 1]], type: "pgm")
96
- image.type.must_equal :pgm
98
+ _(image.type).must_equal :pgm
97
99
  end
98
100
 
99
101
  it "can create a grayscale image from bilevel values (using maxgray)" do
100
102
  image = PNM.create([[0, 1, 0], [1, 0, 1]], maxgray: 2)
101
- image.type.must_equal :pgm
102
- image.pixels.must_equal [[0, 1, 0], [1, 0, 1]]
103
- image.maxgray.must_equal 2
103
+ _(image.type).must_equal :pgm
104
+ _(image.pixels).must_equal [[0, 1, 0], [1, 0, 1]]
105
+ _(image.maxgray).must_equal 2
104
106
  end
105
107
 
106
108
  it "can create a color image from bilevel values" do
107
109
  image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :ppm)
108
- image.info.must_match %r{^PPM 3x2 Color}
109
- image.pixels.must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
110
- image.maxgray.must_equal 255
110
+ _(image.info).must_equal "PPM 3x2 Color"
111
+ _(image.pixels).must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
112
+ _(image.maxgray).must_equal 255
111
113
  end
112
114
 
113
115
  it "can create a color image from bilevel values with a given maxgray" do
114
116
  image = PNM.create([[0, 1, 0], [1, 0, 1]], type: :ppm, maxgray: 2)
115
- image.info.must_match %r{^PPM 3x2 Color}
116
- image.pixels.must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
117
- image.maxgray.must_equal 2
117
+ _(image.info).must_equal "PPM 3x2 Color"
118
+ _(image.pixels).must_equal [[[0, 0, 0], [1, 1, 1], [0, 0, 0]], [[1, 1, 1], [0, 0, 0], [1, 1, 1]]]
119
+ _(image.maxgray).must_equal 2
118
120
  end
119
121
 
120
122
  it "can create a color image from gray values" do
121
123
  image = PNM.create([[0, 3, 6], [3, 6, 9]], type: :ppm)
122
- image.info.must_match %r{^PPM 3x2 Color}
123
- image.pixels.must_equal [[[0, 0, 0], [3, 3, 3], [6, 6, 6]], [[3, 3, 3], [6, 6, 6], [9, 9, 9]]]
124
+ _(image.info).must_equal "PPM 3x2 Color"
125
+ _(image.pixels).must_equal [[[0, 0, 0], [3, 3, 3], [6, 6, 6]], [[3, 3, 3], [6, 6, 6], [9, 9, 9]]]
124
126
  end
125
127
 
126
128
  it "does not modify the input data for color images created from gray values" do
127
129
  data = [[0, 3, 6], [3, 6, 9]]
128
130
  PNM.create(data, type: :ppm)
129
- data.must_equal [[0, 3, 6], [3, 6, 9]]
131
+ _(data).must_equal [[0, 3, 6], [3, 6, 9]]
130
132
  end
131
133
 
132
134
  it "can write a bilevel image to an ASCII encoded file" do
133
135
  @bilevel.write(@temp_path, :ascii)
134
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_ascii.pbm")
136
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/bilevel_ascii.pbm")
135
137
  File.delete(@temp_path)
136
138
  end
137
139
 
138
140
  it "can write a bilevel image (width 5) to a binary encoded file" do
139
141
  @bilevel.write(@temp_path, :binary)
140
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
142
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
141
143
  File.delete(@temp_path)
142
144
  end
143
145
 
144
146
  it "can write a bilevel image (width 16) to a binary encoded file" do
145
147
  @bilevel2.write(@temp_path, :binary)
146
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/bilevel_2_binary.pbm")
148
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/bilevel_2_binary.pbm")
147
149
  File.delete(@temp_path)
148
150
  end
149
151
 
150
152
  it "can write a grayscale image to an ASCII encoded file" do
151
153
  @grayscale.write(@temp_path, :ascii)
152
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
154
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
153
155
  File.delete(@temp_path)
154
156
  end
155
157
 
156
158
  it "can write a grayscale image to a binary encoded file" do
157
159
  @grayscale.write(@temp_path, :binary)
158
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary.pgm")
160
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/grayscale_binary.pgm")
159
161
  File.delete(@temp_path)
160
162
  end
161
163
 
162
164
  it "can write a color image to an ASCII encoded file" do
163
165
  @color.write(@temp_path, :ascii)
164
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/color_ascii.ppm")
166
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/color_ascii.ppm")
165
167
  File.delete(@temp_path)
166
168
  end
167
169
 
168
170
  it "can write a color image to a binary encoded file" do
169
171
  @color.write(@temp_path, :binary)
170
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/color_binary.ppm")
172
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/color_binary.ppm")
171
173
  File.delete(@temp_path)
172
174
  end
173
175
 
174
176
  it "can write a bilevel image to a file, adding the extension" do
175
177
  @bilevel.write_with_extension(@temp_path)
176
- File.binread("#{@temp_path}.pbm").must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
178
+ _(File.binread("#{@temp_path}.pbm")).must_equal File.binread("#{@srcpath}/bilevel_binary.pbm")
177
179
  File.delete("#{@temp_path}.pbm")
178
180
  end
179
181
 
180
182
  it "can write a grayscale image to a file, adding the extension" do
181
183
  @grayscale.write_with_extension(@temp_path, :ascii)
182
- File.binread("#{@temp_path}.pgm").must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
184
+ _(File.binread("#{@temp_path}.pgm")).must_equal File.binread("#{@srcpath}/grayscale_ascii.pgm")
183
185
  File.delete("#{@temp_path}.pgm")
184
186
  end
185
187
 
186
188
  it "can write a color image to a file, adding the extension" do
187
189
  @color.write_with_extension(@temp_path, :binary)
188
- File.binread("#{@temp_path}.ppm").must_equal File.binread("#{@srcpath}/color_binary.ppm")
190
+ _(File.binread("#{@temp_path}.ppm")).must_equal File.binread("#{@srcpath}/color_binary.ppm")
189
191
  File.delete("#{@temp_path}.ppm")
190
192
  end
191
193
 
192
194
  it "can return image information" do
193
- @bilevel.info.must_equal "PBM 5x6 Bilevel"
194
- @grayscale.info.must_equal "PGM 4x3 Grayscale"
195
- @color.info.must_equal "PPM 5x3 Color"
195
+ _(@bilevel.info).must_equal "PBM 5x6 Bilevel"
196
+ _(@grayscale.info).must_equal "PGM 4x3 Grayscale"
197
+ _(@color.info).must_equal "PPM 5x3 Color"
196
198
  end
197
199
 
198
200
  it "can return meaningful debugging information" do
199
- @bilevel.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PBM 5x6 Bilevel>$}
200
- @grayscale.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PGM 4x3 Grayscale, maxgray=250>$}
201
- @color.inspect.must_match %r{^#<PNM::\w+Image:0x\h+ PPM 5x3 Color, maxgray=6>$}
201
+ _(@bilevel.inspect).must_match %r{\A#<PNM::PBMImage:0x\h+ PBM 5x6 Bilevel>\z}
202
+ _(@grayscale.inspect).must_match %r{\A#<PNM::PGMImage:0x\h+ PGM 4x3 Grayscale, maxgray=250>\z}
203
+ _(@color.inspect).must_match %r{\A#<PNM::PPMImage:0x\h+ PPM 5x3 Color, maxgray=6>\z}
202
204
  end
203
205
 
204
206
  it "can write binary data containing CRLF" do
205
207
  @grayscale_crlf.write(@temp_path, :binary)
206
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
208
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
207
209
  File.delete(@temp_path)
208
210
  end
209
211
 
210
212
  it "can write binary data containing CRLF to an I/O stream" do
211
213
  File.open(@temp_path, "w") {|f| @grayscale_crlf.write(f, :binary) }
212
- File.binread(@temp_path).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
214
+ _(File.binread(@temp_path)).must_equal File.binread("#{@srcpath}/grayscale_binary_crlf.pgm")
213
215
  File.delete(@temp_path)
214
216
  end
215
217
 
216
218
  it "can write zero-length comments" do
217
219
  comment = ""
218
220
  PNM.create([[0, 0]], comment: comment).write(@temp_path, :ascii)
219
- File.binread(@temp_path).must_equal "P1\n#\n2 1\n0 0\n"
221
+ _(File.binread(@temp_path)).must_equal "P1\n#\n2 1\n0 0\n"
220
222
  File.delete(@temp_path)
221
223
  end
222
224
 
223
225
  it "can write comments with trailing zero-length line" do
224
226
  comment = "An empty line:\n"
225
227
  PNM.create([[0, 0]], comment: comment).write(@temp_path, :ascii)
226
- File.binread(@temp_path).must_equal "P1\n# An empty line:\n#\n2 1\n0 0\n"
228
+ _(File.binread(@temp_path)).must_equal "P1\n# An empty line:\n#\n2 1\n0 0\n"
227
229
  File.delete(@temp_path)
228
230
  end
229
231
 
230
232
  it "can check equality of images (1)" do
231
233
  pixels = [[0, 1, 0], [1, 0, 1]]
232
- bilevel = PNM.create(pixels, comment: "image")
234
+ bilevel1 = PNM.create(pixels, comment: "image")
233
235
  bilevel2 = PNM.create(pixels, comment: "image")
234
236
 
235
- (bilevel2 == bilevel).must_equal true
237
+ _(bilevel2 == bilevel1).must_equal true
236
238
  end
237
239
 
238
240
  it "can check equality of images (2)" do
239
241
  pixels = [[0, 1, 0], [1, 0, 1]]
240
- bilevel = PNM.create(pixels, comment: "image")
242
+ bilevel1 = PNM.create(pixels, comment: "image")
241
243
  bilevel2 = PNM.create(pixels, comment: "other image")
242
244
 
243
- (bilevel2 == bilevel).must_equal false
245
+ _(bilevel2 == bilevel1).must_equal false
244
246
  end
245
247
 
246
248
  it "can check equality of images (3)" do
247
249
  pixels = [[0, 1, 0], [1, 0, 1]]
248
- bilevel = PNM.create(pixels)
250
+ bilevel1 = PNM.create(pixels)
249
251
  bilevel2 = PNM.create(pixels.reverse)
250
252
 
251
- (bilevel2 == bilevel).must_equal false
253
+ _(bilevel2 == bilevel1).must_equal false
252
254
  end
253
255
 
254
256
  it "can check equality of images (4)" do
255
257
  pixels = [[0, 1, 0], [1, 0, 1]]
256
- bilevel = PNM.create(pixels, type: :pbm)
258
+ bilevel = PNM.create(pixels, type: :pbm)
257
259
  graylevel = PNM.create(pixels, type: :pgm)
258
260
 
259
- (graylevel == bilevel).must_equal false
261
+ _(graylevel == bilevel).must_equal false
260
262
  end
261
263
 
262
264
  it "can check equality of images (5)" do
263
265
  pixels = [[0, 1, 2], [3, 4, 5]]
264
- graylevel = PNM.create(pixels, maxgray: 10)
266
+ graylevel1 = PNM.create(pixels, maxgray: 10)
265
267
  graylevel2 = PNM.create(pixels, maxgray: 255)
266
268
 
267
- (graylevel2 == graylevel).must_equal false
269
+ _(graylevel2 == graylevel1).must_equal false
268
270
  end
269
271
 
270
272
  it "can check equality of images (6)" do
271
273
  image = PNM.create([[0, 1, 2], [3, 4, 5]])
272
274
 
273
- (image == "a string").must_equal false
275
+ _(image == "a string").must_equal false
274
276
  end
275
277
  end
data/test/test_parser.rb CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  # test_parser.rb: Unit tests for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "minitest/autorun"
8
8
  require "pnm/parser"
9
9
 
10
+ require_relative "backports"
11
+
10
12
 
11
13
  describe PNM::Parser do
12
14
 
@@ -27,7 +29,7 @@ describe PNM::Parser do
27
29
  data: "0 1 0 0 1 1\n0 0 0 1 1 1"
28
30
  }
29
31
 
30
- @parser.parse(content).must_equal expected
32
+ _(@parser.parse(content)).must_equal expected
31
33
  end
32
34
 
33
35
  it "can parse ASCII encoded PGM data" do
@@ -44,7 +46,7 @@ describe PNM::Parser do
44
46
  data: "10 20 30 40\n50 60 70 80"
45
47
  }
46
48
 
47
- @parser.parse(content).must_equal expected
49
+ _(@parser.parse(content)).must_equal expected
48
50
  end
49
51
 
50
52
  it "can parse binary encoded data" do
@@ -56,7 +58,7 @@ describe PNM::Parser do
56
58
  data: ["05AF"].pack("H*")
57
59
  }
58
60
 
59
- @parser.parse(content).must_equal expected
61
+ _(@parser.parse(content)).must_equal expected
60
62
  end
61
63
 
62
64
  it "does not change the passed data" do
@@ -64,7 +66,7 @@ describe PNM::Parser do
64
66
  original_content = content.dup
65
67
  @parser.parse(content)
66
68
 
67
- content.must_equal original_content
69
+ _(content).must_equal original_content
68
70
  end
69
71
 
70
72
  it "does accept multiple whitespace as delimiter" do
@@ -76,23 +78,23 @@ describe PNM::Parser do
76
78
  data: "0 1 0 0 1 1"
77
79
  }
78
80
 
79
- @parser.parse(content).must_equal expected
81
+ _(@parser.parse(content)).must_equal expected
80
82
  end
81
83
 
82
84
  it "can parse binary encoded data including whitespace" do
83
- @parser.parse("P4 16 4 A\nB\rC D\t")[:data].must_equal "A\nB\rC D\t"
85
+ _(@parser.parse("P4 16 4 A\nB\rC D\t")[:data]).must_equal "A\nB\rC D\t"
84
86
  end
85
87
 
86
88
  it "can parse binary encoded data starting with whitespace" do
87
- @parser.parse("P4 8 2 \nA")[:data].must_equal "\nA"
89
+ _(@parser.parse("P4 8 2 \nA")[:data]).must_equal "\nA"
88
90
  end
89
91
 
90
92
  it "can parse binary encoded data starting with comment character" do
91
- @parser.parse("P4 8 2 #A")[:data].must_equal "#A"
93
+ _(@parser.parse("P4 8 2 #A")[:data]).must_equal "#A"
92
94
  end
93
95
 
94
96
  it "does not chomp newlines from parsed binary encoded data" do
95
- @parser.parse("P4 8 2 AB\n")[:data].must_equal "AB\n"
97
+ _(@parser.parse("P4 8 2 AB\n")[:data]).must_equal "AB\n"
96
98
  end
97
99
 
98
100
  it "can parse comments" do
@@ -115,6 +117,6 @@ describe PNM::Parser do
115
117
  data: "0 1 0 0 1 1\n0 0 0 1 1 1"
116
118
  }
117
119
 
118
- @parser.parse(content).must_equal expected
120
+ _(@parser.parse(content)).must_equal expected
119
121
  end
120
122
  end
data/test/test_pnm.rb CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  # test_pnm.rb: Unit tests for the PNM library.
4
4
  #
5
- # Copyright (C) 2013-2019 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
6
 
7
7
  require "minitest/autorun"
8
8
  require "pnm"
9
9
 
10
+ require_relative "backports"
11
+
10
12
 
11
13
  describe PNM do
12
14
 
@@ -18,89 +20,89 @@ describe PNM do
18
20
  file = File.expand_path("#{@srcpath}/bilevel_ascii.pbm")
19
21
  image = PNM.read(file)
20
22
 
21
- image.info.must_match %r{^PBM 5x6 Bilevel}
22
- image.maxgray.must_equal 1
23
- image.comment.must_equal "Bilevel"
24
- image.pixels.must_equal [[0, 0, 0, 0, 0],
25
- [0, 1, 1, 1, 0],
26
- [0, 0, 1, 0, 0],
27
- [0, 0, 1, 0, 0],
28
- [0, 0, 1, 0, 0],
29
- [0, 0, 0, 0, 0]]
23
+ _(image.info).must_equal "PBM 5x6 Bilevel"
24
+ _(image.maxgray).must_equal 1
25
+ _(image.comment).must_equal "Bilevel"
26
+ _(image.pixels).must_equal [[0, 0, 0, 0, 0],
27
+ [0, 1, 1, 1, 0],
28
+ [0, 0, 1, 0, 0],
29
+ [0, 0, 1, 0, 0],
30
+ [0, 0, 1, 0, 0],
31
+ [0, 0, 0, 0, 0]]
30
32
  end
31
33
 
32
34
  it "can read an ASCII encoded PGM file" do
33
35
  file = File.expand_path("#{@srcpath}/grayscale_ascii.pgm")
34
36
  image = PNM.read(file)
35
37
 
36
- image.info.must_match %r{^PGM 4x3 Grayscale}
37
- image.maxgray.must_equal 250
38
- image.comment.must_equal "Grayscale\n(with multiline comment)"
39
- image.pixels.must_equal [[ 0, 50, 100, 150],
40
- [ 50, 100, 150, 200],
41
- [100, 150, 200, 250]]
38
+ _(image.info).must_equal "PGM 4x3 Grayscale"
39
+ _(image.maxgray).must_equal 250
40
+ _(image.comment).must_equal "Grayscale\n(with multiline comment)"
41
+ _(image.pixels).must_equal [[ 0, 50, 100, 150],
42
+ [ 50, 100, 150, 200],
43
+ [100, 150, 200, 250]]
42
44
  end
43
45
 
44
46
  it "can read an ASCII encoded PPM file" do
45
47
  file = File.expand_path("#{@srcpath}/color_ascii.ppm")
46
48
  image = PNM.read(file)
47
49
 
48
- image.info.must_match %r{^PPM 5x3 Color}
49
- image.maxgray.must_equal 6
50
- image.pixels.must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
51
- [[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
52
- [[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
50
+ _(image.info).must_equal "PPM 5x3 Color"
51
+ _(image.maxgray).must_equal 6
52
+ _(image.pixels).must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
53
+ [[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
54
+ [[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
53
55
  end
54
56
 
55
57
  it "can read a binary encoded PBM file" do
56
58
  file = File.expand_path("#{@srcpath}/bilevel_binary.pbm")
57
59
  image = PNM.read(file)
58
60
 
59
- image.info.must_match %r{^PBM 5x6 Bilevel}
60
- image.maxgray.must_equal 1
61
- image.comment.must_equal "Bilevel"
62
- image.pixels.must_equal [[0, 0, 0, 0, 0],
63
- [0, 1, 1, 1, 0],
64
- [0, 0, 1, 0, 0],
65
- [0, 0, 1, 0, 0],
66
- [0, 0, 1, 0, 0],
67
- [0, 0, 0, 0, 0]]
61
+ _(image.info).must_equal "PBM 5x6 Bilevel"
62
+ _(image.maxgray).must_equal 1
63
+ _(image.comment).must_equal "Bilevel"
64
+ _(image.pixels).must_equal [[0, 0, 0, 0, 0],
65
+ [0, 1, 1, 1, 0],
66
+ [0, 0, 1, 0, 0],
67
+ [0, 0, 1, 0, 0],
68
+ [0, 0, 1, 0, 0],
69
+ [0, 0, 0, 0, 0]]
68
70
  end
69
71
 
70
72
  it "can read a binary encoded PGM file" do
71
73
  file = File.expand_path("#{@srcpath}/grayscale_binary.pgm")
72
74
  image = PNM.read(file)
73
75
 
74
- image.info.must_match %r{^PGM 4x3 Grayscale}
75
- image.maxgray.must_equal 250
76
- image.comment.must_equal "Grayscale\n(with multiline comment)"
77
- image.pixels.must_equal [[ 0, 50, 100, 150],
78
- [ 50, 100, 150, 200],
79
- [100, 150, 200, 250]]
76
+ _(image.info).must_equal "PGM 4x3 Grayscale"
77
+ _(image.maxgray).must_equal 250
78
+ _(image.comment).must_equal "Grayscale\n(with multiline comment)"
79
+ _(image.pixels).must_equal [[ 0, 50, 100, 150],
80
+ [ 50, 100, 150, 200],
81
+ [100, 150, 200, 250]]
80
82
  end
81
83
 
82
84
  it "can read a binary encoded PPM file" do
83
85
  file = File.expand_path("#{@srcpath}/color_binary.ppm")
84
86
  image = PNM.read(file)
85
87
 
86
- image.info.must_match %r{^PPM 5x3 Color}
87
- image.maxgray.must_equal 6
88
- image.pixels.must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
89
- [[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
90
- [[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
88
+ _(image.info).must_equal "PPM 5x3 Color"
89
+ _(image.maxgray).must_equal 6
90
+ _(image.pixels).must_equal [[[0, 6, 0], [1, 5, 1], [2, 4, 2], [3, 3, 4], [4, 2, 6]],
91
+ [[1, 5, 2], [2, 4, 2], [3, 3, 2], [4, 2, 2], [5, 1, 2]],
92
+ [[2, 4, 6], [3, 3, 4], [4, 2, 2], [5, 1, 1], [6, 0, 0]]]
91
93
  end
92
94
 
93
95
  it "can read binary data containing CRLF" do
94
96
  file = File.expand_path("#{@srcpath}/grayscale_binary_crlf.pgm")
95
97
 
96
98
  image = PNM.read(file)
97
- image.pixels.must_equal [[65, 66], [13, 10], [65, 66]]
99
+ _(image.pixels).must_equal [[65, 66], [13, 10], [65, 66]]
98
100
  end
99
101
 
100
102
  it "can read binary data containing CRLF from an I/O stream" do
101
103
  file = File.expand_path("#{@srcpath}/grayscale_binary_crlf.pgm")
102
104
 
103
105
  image = File.open(file, "r") {|f| PNM.read(f) }
104
- image.pixels.must_equal [[65, 66], [13, 10], [65, 66]]
106
+ _(image.pixels).must_equal [[65, 66], [13, 10], [65, 66]]
105
107
  end
106
108
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pnm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcus Stollsteimer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-09 00:00:00.000000000 Z
11
+ date: 2020-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -61,6 +61,7 @@ files:
61
61
  - lib/pnm/parser.rb
62
62
  - lib/pnm/version.rb
63
63
  - pnm.gemspec
64
+ - test/backports.rb
64
65
  - test/bilevel_2_binary.pbm
65
66
  - test/bilevel_ascii.pbm
66
67
  - test/bilevel_binary.pbm
@@ -95,13 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubygems_version: 3.0.1
99
+ rubygems_version: 3.1.2
99
100
  signing_key:
100
101
  specification_version: 4
101
102
  summary: PNM - create/read/write PNM image files (PBM, PGM, PPM)
102
103
  test_files:
103
104
  - test/test_exceptions.rb
104
- - test/test_image.rb
105
105
  - test/test_converter.rb
106
106
  - test/test_pnm.rb
107
+ - test/test_image.rb
107
108
  - test/test_parser.rb