pnm 0.4.1 → 0.6.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.
@@ -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
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # test_converter.rb: Unit tests for the PNM library.
2
4
  #
3
- # Copyright (C) 2013-2015 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
+
7
+ require "minitest/autorun"
8
+ require "pnm/converter"
4
9
 
5
- require 'minitest/autorun'
6
- require 'pnm/converter'
10
+ require_relative "backports"
7
11
 
8
12
 
9
13
  describe PNM::Converter do
@@ -11,196 +15,197 @@ describe PNM::Converter do
11
15
  before do
12
16
  @converter = PNM::Converter
13
17
 
14
- @pbm6 = {
15
- :width => 6,
16
- :height => 2,
17
- :array => [[0,1,0,0,1,1], [0,0,0,1,1,1]],
18
- :ascii => "0 1 0 0 1 1\n0 0 0 1 1 1\n",
19
- :binary => ['4C1C'].pack('H*')
20
- }
18
+ @pbm6 = {
19
+ width: 6,
20
+ height: 2,
21
+ array: [[0, 1, 0, 0, 1, 1], [0, 0, 0, 1, 1, 1]],
22
+ ascii: "0 1 0 0 1 1\n0 0 0 1 1 1\n",
23
+ binary: ["4C1C"].pack("H*")
24
+ }
21
25
 
22
26
  @pbm14 = {
23
- :width => 14,
24
- :height => 2,
25
- :array => [[0,0,1,1,1,0,0,0,1,1,0,0,1,0], [0,1,0,1,1,0,1,1,1,0,1,1,1,1]],
26
- :ascii => "0 0 1 1 1 0 0 0 1 1 0 0 1 0\n0 1 0 1 1 0 1 1 1 0 1 1 1 1\n",
27
- :binary => ['38C85BBC'].pack('H*')
28
- }
27
+ width: 14,
28
+ height: 2,
29
+ array: [[0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0],
30
+ [0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1]],
31
+ ascii: "0 0 1 1 1 0 0 0 1 1 0 0 1 0\n0 1 0 1 1 0 1 1 1 0 1 1 1 1\n",
32
+ binary: ["38C85BBC"].pack("H*")
33
+ }
29
34
 
30
35
  @pbm = @pbm14
31
36
 
32
- @pgm = {
33
- :width => 4,
34
- :height => 3,
35
- :array => [[0, 85, 170, 255], [85, 170, 255, 0], [170, 255, 0, 85]],
36
- :ascii => "0 85 170 255\n85 170 255 0\n170 255 0 85\n",
37
- :binary => ['0055AAFF55AAFF00AAFF0055'].pack('H*')
38
- }
39
-
40
- @ppm = {
41
- :width => 3,
42
- :height => 2,
43
- :array => [[[0,128,255], [128,255,0], [255,0,128]],
44
- [[255,128,0], [128,0,255], [0,255,128]]],
45
- :ascii => "0 128 255 128 255 0 255 0 128\n255 128 0 128 0 255 0 255 128\n",
46
- :binary => ['0080FF80FF00FF0080FF80008000FF00FF80'].pack('H*')
47
- }
48
- end
49
-
50
- it 'can convert from ASCII encoded PBM data' do
37
+ @pgm = {
38
+ width: 4,
39
+ height: 3,
40
+ array: [[0, 85, 170, 255], [85, 170, 255, 0], [170, 255, 0, 85]],
41
+ ascii: "0 85 170 255\n85 170 255 0\n170 255 0 85\n",
42
+ binary: ["0055AAFF55AAFF00AAFF0055"].pack("H*")
43
+ }
44
+
45
+ @ppm = {
46
+ width: 3,
47
+ height: 2,
48
+ array: [[[0, 128, 255], [128, 255, 0], [255, 0, 128]],
49
+ [[255, 128, 0], [128, 0, 255], [0, 255, 128]]],
50
+ ascii: "0 128 255 128 255 0 255 0 128\n255 128 0 128 0 255 0 255 128\n",
51
+ binary: ["0080FF80FF00FF0080FF80008000FF00FF80"].pack("H*")
52
+ }
53
+ end
54
+
55
+ it "can convert from ASCII encoded PBM data" do
51
56
  width = @pbm[:width]
52
57
  height = @pbm[:height]
53
58
  data = @pbm[:ascii]
54
59
  expected = @pbm[:array]
55
60
 
56
- @converter.ascii2array(:pbm, width, height, data).must_equal expected
61
+ _(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
57
62
  end
58
63
 
59
- it 'can convert from ASCII encoded PGM data' do
64
+ it "can convert from ASCII encoded PGM data" do
60
65
  width = @pgm[:width]
61
66
  height = @pgm[:height]
62
67
  data = @pgm[:ascii]
63
68
  expected = @pgm[:array]
64
69
 
65
- @converter.ascii2array(:pgm, width, height, data).must_equal expected
70
+ _(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
66
71
  end
67
72
 
68
- it 'can convert from ASCII encoded PPM data' do
73
+ it "can convert from ASCII encoded PPM data" do
69
74
  width = @ppm[:width]
70
75
  height = @ppm[:height]
71
76
  data = @ppm[:ascii]
72
77
  expected = @ppm[:array]
73
78
 
74
- @converter.ascii2array(:ppm, width, height, data).must_equal expected
79
+ _(@converter.ascii2array(:ppm, width, height, data)).must_equal expected
75
80
  end
76
81
 
77
- it 'accepts ASCII encoded PBM data with omitted whitespace' do
82
+ it "accepts ASCII encoded PBM data with omitted whitespace" do
78
83
  width = 4
79
84
  height = 3
80
85
  data = " 010100\n000110"
81
86
  expected = [[0, 1, 0, 1], [0, 0, 0, 0], [0, 1, 1, 0]]
82
87
 
83
- @converter.ascii2array(:pbm, width, height, data).must_equal expected
88
+ _(@converter.ascii2array(:pbm, width, height, data)).must_equal expected
84
89
  end
85
90
 
86
- it 'accepts ASCII encoded PGM data with arbitrary whitespace' do
91
+ it "accepts ASCII encoded PGM data with arbitrary whitespace" do
87
92
  width = 4
88
93
  height = 3
89
94
  data = " \n 10 90\t170\r250\n90 \t170 250 \t\r\n\t 10\n\n\n170\n250\n10\n90\n"
90
95
  expected = [[10, 90, 170, 250], [90, 170, 250, 10], [170, 250, 10, 90]]
91
96
 
92
- @converter.ascii2array(:pgm, width, height, data).must_equal expected
97
+ _(@converter.ascii2array(:pgm, width, height, data)).must_equal expected
93
98
  end
94
99
 
95
- it 'can convert from binary encoded PBM data (width 6)' do
100
+ it "can convert from binary encoded PBM data (width 6)" do
96
101
  width = @pbm6[:width]
97
102
  height = @pbm6[:height]
98
103
  data = @pbm6[:binary]
99
104
  expected = @pbm6[:array]
100
105
 
101
- @converter.binary2array(:pbm, width, height, data).must_equal expected
106
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
102
107
  end
103
108
 
104
- it 'can convert from binary encoded PBM data (width 14)' do
109
+ it "can convert from binary encoded PBM data (width 14)" do
105
110
  width = @pbm14[:width]
106
111
  height = @pbm14[:height]
107
112
  data = @pbm14[:binary]
108
113
  expected = @pbm14[:array]
109
114
 
110
- @converter.binary2array(:pbm, width, height, data).must_equal expected
115
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
111
116
  end
112
117
 
113
- it 'can convert from binary encoded PGM data' do
118
+ it "can convert from binary encoded PGM data" do
114
119
  width = @pgm[:width]
115
120
  height = @pgm[:height]
116
121
  data = @pgm[:binary]
117
122
  expected = @pgm[:array]
118
123
 
119
- @converter.binary2array(:pgm, width, height, data).must_equal expected
124
+ _(@converter.binary2array(:pgm, width, height, data)).must_equal expected
120
125
  end
121
126
 
122
- it 'can convert from binary encoded PPM data' do
127
+ it "can convert from binary encoded PPM data" do
123
128
  width = @ppm[:width]
124
129
  height = @ppm[:height]
125
130
  data = @ppm[:binary]
126
131
  expected = @ppm[:array]
127
132
 
128
- @converter.binary2array(:ppm, width, height, data).must_equal expected
133
+ _(@converter.binary2array(:ppm, width, height, data)).must_equal expected
129
134
  end
130
135
 
131
- it 'accepts an additional whitespace character for binary encoded data' do
136
+ it "accepts an additional whitespace character for binary encoded data" do
132
137
  width = @pbm14[:width]
133
138
  height = @pbm14[:height]
134
139
  data = @pbm14[:binary] + "\t"
135
140
  expected = @pbm14[:array]
136
141
 
137
- @converter.binary2array(:pbm, width, height, data).must_equal expected
142
+ _(@converter.binary2array(:pbm, width, height, data)).must_equal expected
138
143
  end
139
144
 
140
- it 'can convert to ASCII encoded PBM data' do
145
+ it "can convert to ASCII encoded PBM data" do
141
146
  data = @pbm[:array]
142
147
  expected = @pbm[:ascii]
143
148
 
144
- @converter.array2ascii(data).must_equal expected
149
+ _(@converter.array2ascii(data)).must_equal expected
145
150
  end
146
151
 
147
- it 'can convert to ASCII encoded PGM data' do
152
+ it "can convert to ASCII encoded PGM data" do
148
153
  data = @pgm[:array]
149
154
  expected = @pgm[:ascii]
150
155
 
151
- @converter.array2ascii(data).must_equal expected
156
+ _(@converter.array2ascii(data)).must_equal expected
152
157
  end
153
158
 
154
- it 'can convert to ASCII encoded PPM data' do
159
+ it "can convert to ASCII encoded PPM data" do
155
160
  data = @ppm[:array]
156
161
  expected = @ppm[:ascii]
157
162
 
158
- @converter.array2ascii(data).must_equal expected
163
+ _(@converter.array2ascii(data)).must_equal expected
159
164
  end
160
165
 
161
- it 'can convert to binary encoded PBM data (width 6)' do
166
+ it "can convert to binary encoded PBM data (width 6)" do
162
167
  data = @pbm6[:array]
163
168
  expected = @pbm6[:binary]
164
169
 
165
- @converter.array2binary(:pbm, data).must_equal expected
170
+ _(@converter.array2binary(:pbm, data)).must_equal expected
166
171
  end
167
172
 
168
- it 'can convert to binary encoded PBM data (width 14)' do
173
+ it "can convert to binary encoded PBM data (width 14)" do
169
174
  data = @pbm14[:array]
170
175
  expected = @pbm14[:binary]
171
176
 
172
- @converter.array2binary(:pbm, data).must_equal expected
177
+ _(@converter.array2binary(:pbm, data)).must_equal expected
173
178
  end
174
179
 
175
- it 'can convert to binary encoded PGM data' do
180
+ it "can convert to binary encoded PGM data" do
176
181
  data = @pgm[:array]
177
182
  expected = @pgm[:binary]
178
183
 
179
- @converter.array2binary(:pgm, data).must_equal expected
184
+ _(@converter.array2binary(:pgm, data)).must_equal expected
180
185
  end
181
186
 
182
- it 'can convert to binary encoded PPM data' do
187
+ it "can convert to binary encoded PPM data" do
183
188
  data = @ppm[:array]
184
189
  expected = @ppm[:binary]
185
190
 
186
- @converter.array2binary(:ppm, data).must_equal expected
191
+ _(@converter.array2binary(:ppm, data)).must_equal expected
187
192
  end
188
193
 
189
- it 'can calculate correct byte widths for a PBM image' do
190
- @converter.byte_width(:pbm, 0).must_equal 0
191
- @converter.byte_width(:pbm, 1).must_equal 1
192
- @converter.byte_width(:pbm, 7).must_equal 1
193
- @converter.byte_width(:pbm, 8).must_equal 1
194
- @converter.byte_width(:pbm, 9).must_equal 2
195
- @converter.byte_width(:pbm, 64).must_equal 8
196
- @converter.byte_width(:pbm, 65).must_equal 9
194
+ it "can calculate correct byte widths for a PBM image" do
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
197
202
  end
198
203
 
199
- it 'can calculate correct byte widths for a PGM image' do
200
- @converter.byte_width(:pgm, 13).must_equal 13
204
+ it "can calculate correct byte widths for a PGM image" do
205
+ _(@converter.byte_width(:pgm, 13)).must_equal 13
201
206
  end
202
207
 
203
- it 'can calculate correct byte widths for a PPM image' do
204
- @converter.byte_width(:ppm, 13).must_equal 39
208
+ it "can calculate correct byte widths for a PPM image" do
209
+ _(@converter.byte_width(:ppm, 13)).must_equal 39
205
210
  end
206
211
  end
@@ -1,234 +1,238 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # test_exceptions.rb: Unit tests for the PNM library.
2
4
  #
3
- # Copyright (C) 2013-2015 Marcus Stollsteimer
5
+ # Copyright (C) 2013-2020 Marcus Stollsteimer
6
+
7
+ require "minitest/autorun"
8
+ require "stringio"
9
+ require "pnm"
4
10
 
5
- require 'minitest/autorun'
6
- require 'stringio'
7
- require 'pnm'
11
+ require_relative "backports"
8
12
 
9
13
 
10
- describe 'PNM.create' do
14
+ describe "PNM.create" do
11
15
 
12
- it 'raises an exception for invalid data type (String)' do
13
- data = '0'
14
- lambda { PNM.create(data) }.must_raise PNM::ArgumentError
16
+ it "raises an exception for invalid data type (String)" do
17
+ data = "0"
18
+ _ { PNM.create(data) }.must_raise PNM::ArgumentError
15
19
  end
16
20
 
17
- it 'raises an exception for invalid type' do
21
+ it "raises an exception for invalid type" do
18
22
  data = [[0, 0], [0, 0]]
19
- lambda { PNM.create(data, :type => :abc) }.must_raise PNM::ArgumentError
23
+ _ { PNM.create(data, type: :abc) }.must_raise PNM::ArgumentError
20
24
  end
21
25
 
22
- it 'raises an exception for invalid maxgray (String)' do
26
+ it "raises an exception for invalid maxgray (String)" do
23
27
  data = [[0, 0], [0, 0]]
24
- lambda { PNM.create(data, :maxgray => '255') }.must_raise PNM::ArgumentError
28
+ _ { PNM.create(data, maxgray: "255") }.must_raise PNM::ArgumentError
25
29
  end
26
30
 
27
- it 'raises an exception for invalid maxgray (> 255)' do
31
+ it "raises an exception for invalid maxgray (> 255)" do
28
32
  data = [[0, 0], [0, 0]]
29
- lambda { PNM.create(data, :maxgray => 256) }.must_raise PNM::ArgumentError
33
+ _ { PNM.create(data, maxgray: 256) }.must_raise PNM::ArgumentError
30
34
  end
31
35
 
32
- it 'raises an exception for invalid maxgray (0)' do
36
+ it "raises an exception for invalid maxgray (0)" do
33
37
  data = [[0, 0], [0, 0]]
34
- lambda { PNM.create(data, :maxgray => 0) }.must_raise PNM::ArgumentError
38
+ _ { PNM.create(data, maxgray: 0) }.must_raise PNM::ArgumentError
35
39
  end
36
40
 
37
- it 'raises an exception for invalid comment (Fixnum)' do
41
+ it "raises an exception for invalid comment (Integer)" do
38
42
  data = [[0, 0], [0, 0]]
39
- lambda { PNM.create(data, :comment => 1) }.must_raise PNM::ArgumentError
43
+ _ { PNM.create(data, comment: 1) }.must_raise PNM::ArgumentError
40
44
  end
41
45
 
42
- it 'raises an exception for image type and data mismatch (PBM)' do
43
- data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
44
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
46
+ it "raises an exception for image type and data mismatch (PBM)" do
47
+ data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
48
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
45
49
  end
46
50
 
47
- it 'raises an exception for image type and data mismatch (PGM)' do
48
- data = [[[0,0,0], [0,0,0]], [[0,0,0], [0,0,0]]]
49
- lambda { PNM.create(data, :type => :pgm) }.must_raise PNM::DataError
51
+ it "raises an exception for image type and data mismatch (PGM)" do
52
+ data = [[[0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0]]]
53
+ _ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
50
54
  end
51
55
 
52
- it 'raises an exception for non-integer pixel value (String)' do
53
- data = [[0, 0], ['X', 0]]
54
- lambda { PNM.create(data) }.must_raise PNM::DataError
56
+ it "raises an exception for non-integer pixel value (String)" do
57
+ data = [[0, 0], ["X", 0]]
58
+ _ { PNM.create(data) }.must_raise PNM::DataError
55
59
  end
56
60
 
57
- it 'raises an exception for non-integer pixel value (Float)' do
61
+ it "raises an exception for non-integer pixel value (Float)" do
58
62
  data = [[0, 0], [0.5, 0]]
59
- lambda { PNM.create(data) }.must_raise PNM::DataError
63
+ _ { PNM.create(data) }.must_raise PNM::DataError
60
64
  end
61
65
 
62
- it 'raises an exception for rows of different size' do
66
+ it "raises an exception for rows of different size" do
63
67
  data = [[0, 0], [0, 0, 0]]
64
- lambda { PNM.create(data) }.must_raise PNM::DataError
68
+ _ { PNM.create(data) }.must_raise PNM::DataError
65
69
  end
66
70
 
67
- it 'raises an exception for invalid array dimensions (#1)' do
71
+ it "raises an exception for invalid array dimensions (#1)" do
68
72
  data = [0, 0, 0]
69
- lambda { PNM.create(data) }.must_raise PNM::DataError
73
+ _ { PNM.create(data) }.must_raise PNM::DataError
70
74
  end
71
75
 
72
- it 'raises an exception for invalid array dimensions (#2)' do
76
+ it "raises an exception for invalid array dimensions (#2)" do
73
77
  data = [[0, 0], 0, 0]
74
- lambda { PNM.create(data) }.must_raise PNM::DataError
78
+ _ { PNM.create(data) }.must_raise PNM::DataError
75
79
  end
76
80
 
77
- it 'raises an exception for invalid array dimensions (#3)' do
81
+ it "raises an exception for invalid array dimensions (#3)" do
78
82
  data = [[0, 0], [0, [0, 0]]]
79
- lambda { PNM.create(data) }.must_raise PNM::DataError
83
+ _ { PNM.create(data) }.must_raise PNM::DataError
80
84
  end
81
85
 
82
- it 'raises an exception for invalid array dimensions (#4)' do
83
- data = [[[0,0], [0,0]], [[0,0], [0,0]]]
84
- lambda { PNM.create(data) }.must_raise PNM::DataError
86
+ it "raises an exception for invalid array dimensions (#4)" do
87
+ data = [[[0, 0], [0, 0]], [[0, 0], [0, 0]]]
88
+ _ { PNM.create(data) }.must_raise PNM::DataError
85
89
  end
86
90
 
87
- it 'raises an exception for invalid array dimensions (#5)' do
88
- data = [[[0,0,0], [0,0,0]], [0 ,0]]
89
- lambda { PNM.create(data) }.must_raise PNM::DataError
91
+ it "raises an exception for invalid array dimensions (#5)" do
92
+ data = [[[0, 0, 0], [0, 0, 0]], [0, 0]]
93
+ _ { PNM.create(data) }.must_raise PNM::DataError
90
94
  end
91
95
 
92
- it 'raises an exception for invalid array dimensions (#6)' do
93
- data = [[[0,0,0], 0], [0 ,0]]
94
- lambda { PNM.create(data) }.must_raise PNM::DataError
96
+ it "raises an exception for invalid array dimensions (#6)" do
97
+ data = [[[0, 0, 0], 0], [0, 0]]
98
+ _ { PNM.create(data) }.must_raise PNM::DataError
95
99
  end
96
100
 
97
- it 'raises an exception for an empty array' do
101
+ it "raises an exception for an empty array" do
98
102
  data = [[]]
99
- lambda { PNM.create(data) }.must_raise PNM::DataError
103
+ _ { PNM.create(data) }.must_raise PNM::DataError
100
104
  end
101
105
 
102
- it 'raises an exception for invalid PBM data (> 1)' do
106
+ it "raises an exception for invalid PBM data (> 1)" do
103
107
  data = [[0, 0], [2, 0]]
104
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
108
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
105
109
  end
106
110
 
107
- it 'raises an exception for invalid PBM data (< 0)' do
111
+ it "raises an exception for invalid PBM data (< 0)" do
108
112
  data = [[0, 0], [-1, 0]]
109
- lambda { PNM.create(data, :type => :pbm) }.must_raise PNM::DataError
113
+ _ { PNM.create(data, type: :pbm) }.must_raise PNM::DataError
110
114
  end
111
115
 
112
- it 'raises an exception for invalid PGM data (> 255)' do
116
+ it "raises an exception for invalid PGM data (> 255)" do
113
117
  data = [[0, 0], [1, 500]]
114
- lambda { PNM.create(data, :type => :pgm) }.must_raise PNM::DataError
118
+ _ { PNM.create(data, type: :pgm) }.must_raise PNM::DataError
115
119
  end
116
120
 
117
- it 'raises an exception for invalid PGM data (> maxgray)' do
121
+ it "raises an exception for invalid PGM data (> maxgray)" do
118
122
  data = [[0, 0], [1, 200]]
119
- lambda { PNM.create(data, :maxgray => 100) }.must_raise PNM::DataError
123
+ _ { PNM.create(data, maxgray: 100) }.must_raise PNM::DataError
120
124
  end
121
125
  end
122
126
 
123
127
 
124
- describe 'PNM.read' do
128
+ describe "PNM.read" do
125
129
 
126
- it 'raises an exception for integer argument' do
127
- lambda { PNM.read(123) }.must_raise PNM::ArgumentError
130
+ it "raises an exception for integer argument" do
131
+ _ { PNM.read(123) }.must_raise PNM::ArgumentError
128
132
  end
129
133
 
130
- it 'raises an exception for unknown magic number' do
131
- file = StringIO.new('P0 1 1 0')
132
- lambda { PNM.read(file) }.must_raise PNM::ParserError
134
+ it "raises an exception for unknown magic number" do
135
+ file = StringIO.new("P0 1 1 0")
136
+ _ { PNM.read(file) }.must_raise PNM::ParserError
133
137
  end
134
138
 
135
- it 'raises an exception for an empty file' do
136
- file = StringIO.new('')
137
- lambda { PNM.read(file) }.must_raise PNM::ParserError
139
+ it "raises an exception for an empty file" do
140
+ file = StringIO.new("")
141
+ _ { PNM.read(file) }.must_raise PNM::ParserError
138
142
  end
139
143
 
140
- it 'raises an exception for missing tokens (#1)' do
141
- file = StringIO.new('P1')
142
- lambda { PNM.read(file) }.must_raise PNM::ParserError
144
+ it "raises an exception for missing tokens (#1)" do
145
+ file = StringIO.new("P1")
146
+ _ { PNM.read(file) }.must_raise PNM::ParserError
143
147
  end
144
148
 
145
- it 'raises an exception for missing tokens (#2)' do
146
- file = StringIO.new('P1 1')
147
- lambda { PNM.read(file) }.must_raise PNM::ParserError
149
+ it "raises an exception for missing tokens (#2)" do
150
+ file = StringIO.new("P1 1")
151
+ _ { PNM.read(file) }.must_raise PNM::ParserError
148
152
  end
149
153
 
150
- it 'raises an exception for missing tokens (#3)' do
151
- file = StringIO.new('P1 1 ')
152
- lambda { PNM.read(file) }.must_raise PNM::ParserError
154
+ it "raises an exception for missing tokens (#3)" do
155
+ file = StringIO.new("P1 1 ")
156
+ _ { PNM.read(file) }.must_raise PNM::ParserError
153
157
  end
154
158
 
155
- it 'raises an exception for missing tokens (#4)' do
156
- file = StringIO.new('P1 1 1')
157
- lambda { PNM.read(file) }.must_raise PNM::ParserError
159
+ it "raises an exception for missing tokens (#4)" do
160
+ file = StringIO.new("P1 1 1")
161
+ _ { PNM.read(file) }.must_raise PNM::ParserError
158
162
  end
159
163
 
160
- it 'raises an exception for missing tokens (#5)' do
164
+ it "raises an exception for missing tokens (#5)" do
161
165
  file = StringIO.new("P1 1 # Test\n 1")
162
- lambda { PNM.read(file) }.must_raise PNM::ParserError
166
+ _ { PNM.read(file) }.must_raise PNM::ParserError
163
167
  end
164
168
 
165
- it 'raises an exception for missing tokens (#6)' do
169
+ it "raises an exception for missing tokens (#6)" do
166
170
  file = StringIO.new("P2 1 1 255")
167
- lambda { PNM.read(file) }.must_raise PNM::ParserError
171
+ _ { PNM.read(file) }.must_raise PNM::ParserError
168
172
  end
169
173
 
170
- it 'raises an exception for token of wrong type (#1)' do
171
- file = StringIO.new('P1 ? 1 0')
172
- lambda { PNM.read(file) }.must_raise PNM::ParserError
174
+ it "raises an exception for token of wrong type (#1)" do
175
+ file = StringIO.new("P1 ? 1 0")
176
+ _ { PNM.read(file) }.must_raise PNM::ParserError
173
177
  end
174
178
 
175
- it 'raises an exception for token of wrong type (#2)' do
176
- file = StringIO.new('P1 1 X 0')
177
- lambda { PNM.read(file) }.must_raise PNM::ParserError
179
+ it "raises an exception for token of wrong type (#2)" do
180
+ file = StringIO.new("P1 1 X 0")
181
+ _ { PNM.read(file) }.must_raise PNM::ParserError
178
182
  end
179
183
 
180
- it 'raises an exception for token of wrong type (#3)' do
181
- file = StringIO.new('P2 1 1 foo 0')
182
- lambda { PNM.read(file) }.must_raise PNM::ParserError
184
+ it "raises an exception for token of wrong type (#3)" do
185
+ file = StringIO.new("P2 1 1 foo 0")
186
+ _ { PNM.read(file) }.must_raise PNM::ParserError
183
187
  end
184
188
 
185
- it 'raises an exception for zero width' do
186
- file = StringIO.new('P2 0 1 255 0')
187
- lambda { PNM.read(file) }.must_raise PNM::ParserError
189
+ it "raises an exception for zero width" do
190
+ file = StringIO.new("P2 0 1 255 0")
191
+ _ { PNM.read(file) }.must_raise PNM::ParserError
188
192
  end
189
193
 
190
- it 'raises an exception for zero height' do
191
- file = StringIO.new('P2 1 0 255 0')
192
- lambda { PNM.read(file) }.must_raise PNM::ParserError
194
+ it "raises an exception for zero height" do
195
+ file = StringIO.new("P2 1 0 255 0")
196
+ _ { PNM.read(file) }.must_raise PNM::ParserError
193
197
  end
194
198
 
195
- it 'raises an exception for invalid maxgray (> 255)' do
196
- file = StringIO.new('P2 1 1 256 0')
197
- lambda { PNM.read(file) }.must_raise PNM::ParserError
199
+ it "raises an exception for invalid maxgray (> 255)" do
200
+ file = StringIO.new("P2 1 1 256 0")
201
+ _ { PNM.read(file) }.must_raise PNM::ParserError
198
202
  end
199
203
 
200
- it 'raises an exception for invalid maxgray (0)' do
201
- file = StringIO.new('P2 1 1 0 0')
202
- lambda { PNM.read(file) }.must_raise PNM::ParserError
204
+ it "raises an exception for invalid maxgray (0)" do
205
+ file = StringIO.new("P2 1 1 0 0")
206
+ _ { PNM.read(file) }.must_raise PNM::ParserError
203
207
  end
204
208
 
205
- it 'raises an exception for image dimension mismatch (#1)' do
206
- file = StringIO.new('P1 2 3 0 0 0 0 0')
207
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
209
+ it "raises an exception for image dimension mismatch (#1)" do
210
+ file = StringIO.new("P1 2 3 0 0 0 0 0")
211
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
208
212
  end
209
213
 
210
- it 'raises an exception for image dimension mismatch (#2)' do
211
- file = StringIO.new('P1 2 3 0 0 0 0 0 0 0')
212
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
214
+ it "raises an exception for image dimension mismatch (#2)" do
215
+ file = StringIO.new("P1 2 3 0 0 0 0 0 0 0")
216
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
213
217
  end
214
218
 
215
- it 'raises an exception for image dimension mismatch (#3)' do
216
- file = StringIO.new('P3 2 3 255 0 0 0 0 0 0')
217
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
219
+ it "raises an exception for image dimension mismatch (#3)" do
220
+ file = StringIO.new("P3 2 3 255 0 0 0 0 0 0")
221
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
218
222
  end
219
223
 
220
- it 'raises an exception for image dimension mismatch (#4)' do
221
- file = StringIO.new('P5 2 3 255 AAAAAAA')
222
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
224
+ it "raises an exception for image dimension mismatch (#4)" do
225
+ file = StringIO.new("P5 2 3 255 AAAAAAA")
226
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
223
227
  end
224
228
 
225
- it 'raises an exception for image dimension mismatch (#5)' do
226
- file = StringIO.new('P5 2 3 255 AAAAAAA')
227
- lambda { PNM.read(file) }.must_raise PNM::DataSizeError
229
+ it "raises an exception for image dimension mismatch (#5)" do
230
+ file = StringIO.new("P5 2 3 255 AAAAAAA")
231
+ _ { PNM.read(file) }.must_raise PNM::DataSizeError
228
232
  end
229
233
 
230
- it 'raises an exception for non-numeric image data' do
231
- file = StringIO.new('P1 2 3 0 X 0 0 0 0')
232
- lambda { PNM.read(file) }.must_raise PNM::DataError
234
+ it "raises an exception for non-numeric image data" do
235
+ file = StringIO.new("P1 2 3 0 X 0 0 0 0")
236
+ _ { PNM.read(file) }.must_raise PNM::DataError
233
237
  end
234
238
  end