chunky_png 1.3.10 → 1.3.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/.standard.yml +16 -0
  4. data/.yardopts +1 -1
  5. data/CHANGELOG.rdoc +5 -1
  6. data/CONTRIBUTING.rdoc +17 -8
  7. data/Gemfile +5 -3
  8. data/LICENSE +1 -1
  9. data/README.md +6 -1
  10. data/Rakefile +5 -3
  11. data/benchmarks/decoding_benchmark.rb +17 -17
  12. data/benchmarks/encoding_benchmark.rb +22 -19
  13. data/benchmarks/filesize_benchmark.rb +6 -6
  14. data/bin/rake +29 -0
  15. data/bin/standardrb +29 -0
  16. data/chunky_png.gemspec +20 -14
  17. data/lib/chunky_png.rb +17 -30
  18. data/lib/chunky_png/canvas.rb +30 -27
  19. data/lib/chunky_png/canvas/adam7_interlacing.rb +16 -10
  20. data/lib/chunky_png/canvas/data_url_exporting.rb +3 -3
  21. data/lib/chunky_png/canvas/data_url_importing.rb +3 -3
  22. data/lib/chunky_png/canvas/drawing.rb +30 -43
  23. data/lib/chunky_png/canvas/masking.rb +14 -14
  24. data/lib/chunky_png/canvas/operations.rb +28 -24
  25. data/lib/chunky_png/canvas/png_decoding.rb +38 -32
  26. data/lib/chunky_png/canvas/png_encoding.rb +110 -102
  27. data/lib/chunky_png/canvas/resampling.rb +27 -32
  28. data/lib/chunky_png/canvas/stream_exporting.rb +8 -8
  29. data/lib/chunky_png/canvas/stream_importing.rb +8 -8
  30. data/lib/chunky_png/chunk.rb +72 -61
  31. data/lib/chunky_png/color.rb +213 -206
  32. data/lib/chunky_png/datastream.rb +23 -29
  33. data/lib/chunky_png/dimension.rb +18 -11
  34. data/lib/chunky_png/image.rb +11 -11
  35. data/lib/chunky_png/palette.rb +6 -9
  36. data/lib/chunky_png/point.rb +27 -26
  37. data/lib/chunky_png/rmagick.rb +10 -10
  38. data/lib/chunky_png/vector.rb +28 -29
  39. data/lib/chunky_png/version.rb +3 -1
  40. data/spec/chunky_png/canvas/adam7_interlacing_spec.rb +20 -21
  41. data/spec/chunky_png/canvas/data_url_exporting_spec.rb +8 -5
  42. data/spec/chunky_png/canvas/data_url_importing_spec.rb +5 -6
  43. data/spec/chunky_png/canvas/drawing_spec.rb +46 -38
  44. data/spec/chunky_png/canvas/masking_spec.rb +15 -16
  45. data/spec/chunky_png/canvas/operations_spec.rb +68 -67
  46. data/spec/chunky_png/canvas/png_decoding_spec.rb +37 -38
  47. data/spec/chunky_png/canvas/png_encoding_spec.rb +59 -50
  48. data/spec/chunky_png/canvas/resampling_spec.rb +19 -21
  49. data/spec/chunky_png/canvas/stream_exporting_spec.rb +47 -27
  50. data/spec/chunky_png/canvas/stream_importing_spec.rb +10 -11
  51. data/spec/chunky_png/canvas_spec.rb +57 -52
  52. data/spec/chunky_png/color_spec.rb +115 -114
  53. data/spec/chunky_png/datastream_spec.rb +55 -51
  54. data/spec/chunky_png/dimension_spec.rb +10 -10
  55. data/spec/chunky_png/image_spec.rb +11 -14
  56. data/spec/chunky_png/point_spec.rb +21 -23
  57. data/spec/chunky_png/rmagick_spec.rb +7 -8
  58. data/spec/chunky_png/vector_spec.rb +21 -17
  59. data/spec/chunky_png_spec.rb +2 -2
  60. data/spec/png_suite_spec.rb +35 -40
  61. data/spec/spec_helper.rb +6 -10
  62. data/tasks/benchmarks.rake +7 -8
  63. metadata +39 -8
  64. data/.travis.yml +0 -16
  65. data/lib/chunky_png/compatibility.rb +0 -15
@@ -1,16 +1,14 @@
1
- # coding: utf-8
2
- require 'spec_helper'
1
+ require "spec_helper"
3
2
 
4
3
  describe ChunkyPNG::Datastream do
5
-
6
- describe '.from_io'do
4
+ describe ".from_io" do
7
5
  it "should raise an error when loading a file with a bad signature" do
8
- filename = resource_file('damaged_signature.png')
6
+ filename = resource_file("damaged_signature.png")
9
7
  expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::SignatureMismatch)
10
8
  end
11
9
 
12
10
  it "should raise an error if the CRC of a chunk is incorrect" do
13
- filename = resource_file('damaged_chunk.png')
11
+ filename = resource_file("damaged_chunk.png")
14
12
  expect { ChunkyPNG::Datastream.from_file(filename) }.to raise_error(ChunkyPNG::CRCMismatch)
15
13
  end
16
14
 
@@ -20,31 +18,37 @@ describe ChunkyPNG::Datastream do
20
18
  end
21
19
 
22
20
  it "should read a stream with trailing data without failing" do
23
- filename = resource_file('trailing_bytes_after_iend_chunk.png')
21
+ filename = resource_file("trailing_bytes_after_iend_chunk.png")
24
22
  image = ChunkyPNG::Datastream.from_file(filename)
25
23
  expect(image).to be_instance_of(ChunkyPNG::Datastream)
26
24
  end
27
25
  end
28
26
 
29
- describe '#metadata' do
27
+ describe "#metadata" do
30
28
  it "should load uncompressed tXTt chunks correctly" do
31
- filename = resource_file('text_chunk.png')
29
+ filename = resource_file("text_chunk.png")
32
30
  ds = ChunkyPNG::Datastream.from_file(filename)
33
- expect(ds.metadata['Title']).to eql 'My amazing icon!'
34
- expect(ds.metadata['Author']).to eql "Willem van Bergen"
31
+ expect(ds.metadata["Title"]).to eql "My amazing icon!"
32
+ expect(ds.metadata["Author"]).to eql "Willem van Bergen"
35
33
  end
36
34
 
37
35
  it "should load compressed zTXt chunks correctly" do
38
- filename = resource_file('ztxt_chunk.png')
36
+ filename = resource_file("ztxt_chunk.png")
39
37
  ds = ChunkyPNG::Datastream.from_file(filename)
40
- expect(ds.metadata['Title']).to eql 'PngSuite'
41
- expect(ds.metadata['Copyright']).to eql "Copyright Willem van Schaik, Singapore 1995-96"
38
+ expect(ds.metadata["Title"]).to eql "PngSuite"
39
+ expect(ds.metadata["Copyright"]).to eql "Copyright Willem van Schaik, Singapore 1995-96"
40
+ end
41
+
42
+ it "ignores iTXt chunks" do
43
+ filename = resource_file("itxt_chunk.png")
44
+ ds = ChunkyPNG::Datastream.from_file(filename)
45
+ expect(ds.metadata).to be_empty
42
46
  end
43
47
  end
44
48
 
45
- describe '#physical_chunk' do
46
- it 'should read and write pHYs chunks correctly' do
47
- filename = resource_file('clock.png')
49
+ describe "#physical_chunk" do
50
+ it "should read and write pHYs chunks correctly" do
51
+ filename = resource_file("clock.png")
48
52
  ds = ChunkyPNG::Datastream.from_file(filename)
49
53
  expect(ds.physical_chunk.unit).to eql :meters
50
54
  expect(ds.physical_chunk.dpix.round).to eql 72
@@ -53,83 +57,83 @@ describe ChunkyPNG::Datastream do
53
57
  expect(ds.physical_chunk).not_to be_nil
54
58
  end
55
59
 
56
- it 'should raise ChunkyPNG::UnitsUnknown if we request dpi but the units are unknown' do
60
+ it "should raise ChunkyPNG::UnitsUnknown if we request dpi but the units are unknown" do
57
61
  physical_chunk = ChunkyPNG::Chunk::Physical.new(2835, 2835, :unknown)
58
- expect{physical_chunk.dpix}.to raise_error(ChunkyPNG::UnitsUnknown)
59
- expect{physical_chunk.dpiy}.to raise_error(ChunkyPNG::UnitsUnknown)
62
+ expect { physical_chunk.dpix }.to raise_error(ChunkyPNG::UnitsUnknown)
63
+ expect { physical_chunk.dpiy }.to raise_error(ChunkyPNG::UnitsUnknown)
60
64
  end
61
65
  end
62
66
 
63
- describe '#iTXt_chunk' do
64
- it 'should read iTXt chunks correctly' do
65
- filename = resource_file('itxt_chunk.png')
67
+ describe "#iTXt_chunk" do
68
+ it "should read iTXt chunks correctly" do
69
+ filename = resource_file("itxt_chunk.png")
66
70
  ds = ChunkyPNG::Datastream.from_file(filename)
67
71
  int_text_chunks = ds.chunks.select { |chunk| chunk.is_a?(ChunkyPNG::Chunk::InternationalText) }
68
72
  expect(int_text_chunks.length).to eq(2)
69
73
 
70
- coach_uk = int_text_chunks.find { |chunk| chunk.language_tag == 'en-gb' }
71
- coach_us = int_text_chunks.find { |chunk| chunk.language_tag == 'en-us' }
74
+ coach_uk = int_text_chunks.find { |chunk| chunk.language_tag == "en-gb" }
75
+ coach_us = int_text_chunks.find { |chunk| chunk.language_tag == "en-us" }
72
76
  expect(coach_uk).to_not be_nil
73
77
  expect(coach_us).to_not be_nil
74
78
 
75
- expect(coach_uk.keyword).to eq('coach')
76
- expect(coach_uk.text).to eq('bus with of higher standard of comfort, usually chartered or used for longer journeys')
77
- expect(coach_uk.translated_keyword).to eq('bus')
79
+ expect(coach_uk.keyword).to eq("coach")
80
+ expect(coach_uk.text).to eq("bus with of higher standard of comfort, usually chartered or used for longer journeys")
81
+ expect(coach_uk.translated_keyword).to eq("bus")
78
82
  expect(coach_uk.compressed).to eq(ChunkyPNG::UNCOMPRESSED_CONTENT)
79
83
  expect(coach_uk.compression).to eq(ChunkyPNG::COMPRESSION_DEFAULT)
80
84
 
81
- expect(coach_us.keyword).to eq('coach')
82
- expect(coach_us.text).to eq('US extracurricular sports teacher at a school (UK: PE teacher) lowest class on a passenger aircraft (UK: economy)')
83
- expect(coach_us.translated_keyword).to eq('trainer')
85
+ expect(coach_us.keyword).to eq("coach")
86
+ expect(coach_us.text).to eq("US extracurricular sports teacher at a school (UK: PE teacher) lowest class on a passenger aircraft (UK: economy)")
87
+ expect(coach_us.translated_keyword).to eq("trainer")
84
88
  expect(coach_us.compressed).to eq(ChunkyPNG::COMPRESSED_CONTENT)
85
89
  expect(coach_us.compression).to eq(ChunkyPNG::COMPRESSION_DEFAULT)
86
90
  end
87
91
 
88
- it 'should write iTXt chunks correctly' do
89
- expected_hex = %w(0000 001d 6954 5874 436f 6d6d 656e 7400 0000 0000 4372 6561 7465 6420 7769 7468 2047 494d 5064 2e65 07).join('')
92
+ it "should write iTXt chunks correctly" do
93
+ expected_hex = %w[0000 001d 6954 5874 436f 6d6d 656e 7400 0000 0000 4372 6561 7465 6420 7769 7468 2047 494d 5064 2e65 07].join("")
90
94
  stream = StringIO.new
91
- itext = ChunkyPNG::Chunk::InternationalText.new('Comment', 'Created with GIMP')
95
+ itext = ChunkyPNG::Chunk::InternationalText.new("Comment", "Created with GIMP")
92
96
  itext.write(stream)
93
- generated_hex = stream.string.unpack('H*').join('')
97
+ generated_hex = stream.string.unpack("H*").join("")
94
98
 
95
99
  expect(generated_hex).to eq(expected_hex)
96
100
  end
97
101
 
98
- it 'should handle incorrect UTF-8 encoding in iTXt chunks' do
99
- incorrect_text_encoding = [0, 0, 0, 14, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 0, 195, 40, 17, 87, 97, 213].pack('C*')
100
- incorrect_translated_keyword_encoding = [0, 0, 0, 19, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 226, 130, 40, 0, 116, 101, 115, 116, 228, 53, 113, 182].pack('C*')
102
+ it "should handle incorrect UTF-8 encoding in iTXt chunks" do
103
+ incorrect_text_encoding = [0, 0, 0, 14, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 0, 195, 40, 17, 87, 97, 213].pack("C*")
104
+ incorrect_translated_keyword_encoding = [0, 0, 0, 19, 105, 84, 88, 116, 67, 111, 109, 109, 101, 110, 116, 0, 0, 0, 0, 226, 130, 40, 0, 116, 101, 115, 116, 228, 53, 113, 182].pack("C*")
101
105
 
102
106
  expect { ChunkyPNG::Chunk.read(StringIO.new(incorrect_text_encoding)) }.to raise_error(ChunkyPNG::InvalidUTF8)
103
107
  expect { ChunkyPNG::Chunk.read(StringIO.new(incorrect_translated_keyword_encoding)) }.to raise_error(ChunkyPNG::InvalidUTF8)
104
108
  end
105
109
 
106
- it 'should handle UTF-8 in iTXt compressed chunks correctly' do
107
- parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new('Comment', '', '', '💩', ChunkyPNG::COMPRESSED_CONTENT))
110
+ it "should handle UTF-8 in iTXt compressed chunks correctly" do
111
+ parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "", "", "💩", ChunkyPNG::COMPRESSED_CONTENT))
108
112
 
109
- expect(parsed.text).to eq('')
113
+ expect(parsed.text).to eq("")
110
114
  expect(parsed.text.encoding).to eq(Encoding::UTF_8)
111
115
 
112
- expect(parsed.translated_keyword).to eq('💩')
116
+ expect(parsed.translated_keyword).to eq("💩")
113
117
  expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
114
118
  end
115
119
 
116
- it 'should handle UTF-8 in iTXt chunks correctly' do
117
- parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new('Comment', '', '', '💩'))
120
+ it "should handle UTF-8 in iTXt chunks correctly" do
121
+ parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "", "", "💩"))
118
122
 
119
- expect(parsed.text).to eq('')
123
+ expect(parsed.text).to eq("")
120
124
  expect(parsed.text.encoding).to eq(Encoding::UTF_8)
121
-
122
- expect(parsed.translated_keyword).to eq('💩')
125
+
126
+ expect(parsed.translated_keyword).to eq("💩")
123
127
  expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
124
128
  end
125
129
 
126
- it 'should transform non UTF-8 iTXt fields to UTF-8 on write' do
127
- parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new('Comment', '®'.encode('Windows-1252'), '', 'ƒ'.encode('Windows-1252')))
130
+ it "should transform non UTF-8 iTXt fields to UTF-8 on write" do
131
+ parsed = serialized_chunk(ChunkyPNG::Chunk::InternationalText.new("Comment", "®".encode("Windows-1252"), "", "ƒ".encode("Windows-1252")))
128
132
 
129
- expect(parsed.text).to eq('®')
133
+ expect(parsed.text).to eq("®")
130
134
  expect(parsed.text.encoding).to eq(Encoding::UTF_8)
131
135
 
132
- expect(parsed.translated_keyword).to eq('ƒ')
136
+ expect(parsed.translated_keyword).to eq("ƒ")
133
137
  expect(parsed.translated_keyword.encoding).to eq(Encoding::UTF_8)
134
138
  end
135
139
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG::Dimension do
4
4
  subject { ChunkyPNG::Dimension.new(2, 3) }
@@ -6,31 +6,31 @@ describe ChunkyPNG::Dimension do
6
6
  it { should respond_to(:width) }
7
7
  it { should respond_to(:height) }
8
8
 
9
- describe '#area' do
9
+ describe "#area" do
10
10
  it "should calculate the area correctly" do
11
11
  expect(subject.area).to eql 6
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
- describe 'ChunkyPNG.Dimension' do
16
+ describe "ChunkyPNG.Dimension" do
17
17
  subject { ChunkyPNG::Dimension.new(1, 2) }
18
18
 
19
19
  it "should create a dimension from a 2-item array" do
20
20
  expect(ChunkyPNG::Dimension([1, 2])).to eql subject
21
- expect(ChunkyPNG::Dimension(['1', '2'])).to eql subject
21
+ expect(ChunkyPNG::Dimension(["1", "2"])).to eql subject
22
22
  end
23
23
 
24
- it "should create a dimension from a hash with x and y keys" do
25
- expect(ChunkyPNG::Dimension(:width => 1, :height => 2)).to eql subject
26
- expect(ChunkyPNG::Dimension('width' => '1', 'height' => '2')).to eql subject
24
+ it "should create a dimension from a hash with width and height keys" do
25
+ expect(ChunkyPNG::Dimension(width: 1, height: 2)).to eql subject
26
+ expect(ChunkyPNG::Dimension("width" => "1", "height" => "2")).to eql subject
27
27
  end
28
28
 
29
29
  it "should create a dimension from a point-like string" do
30
30
  [
31
- ChunkyPNG::Dimension('1,2'),
32
- ChunkyPNG::Dimension('1 2'),
33
- ChunkyPNG::Dimension('(1 , 2)'),
31
+ ChunkyPNG::Dimension("1,2"),
32
+ ChunkyPNG::Dimension("1 2"),
33
+ ChunkyPNG::Dimension("(1 , 2)"),
34
34
  ChunkyPNG::Dimension("{1x2}"),
35
35
  ChunkyPNG::Dimension("[1\t2}"),
36
36
  ].all? { |point| point == subject }
@@ -1,31 +1,28 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG::Image do
4
- describe '#metadata' do
5
-
4
+ describe "#metadata" do
6
5
  it "should load metadata from an existing file" do
7
- image = ChunkyPNG::Image.from_file(resource_file('text_chunk.png'))
8
- expect(image.metadata['Title']).to eql 'My amazing icon!'
9
- expect(image.metadata['Author']).to eql 'Willem van Bergen'
6
+ image = ChunkyPNG::Image.from_file(resource_file("text_chunk.png"))
7
+ expect(image.metadata["Title"]).to eql "My amazing icon!"
8
+ expect(image.metadata["Author"]).to eql "Willem van Bergen"
10
9
  end
11
10
 
12
11
  it "should write metadata to the file correctly" do
13
- filename = resource_file('_metadata.png')
12
+ filename = resource_file("_metadata.png")
14
13
 
15
14
  image = ChunkyPNG::Image.new(10, 10)
16
- image.metadata['Title'] = 'My amazing icon!'
17
- image.metadata['Author'] = 'Willem van Bergen'
15
+ image.metadata["Title"] = "My amazing icon!"
16
+ image.metadata["Author"] = "Willem van Bergen"
18
17
  image.save(filename)
19
18
 
20
19
  metadata = ChunkyPNG::Datastream.from_file(filename).metadata
21
- expect(metadata['Title']).to eql 'My amazing icon!'
22
- expect(metadata['Author']).to eql 'Willem van Bergen'
20
+ expect(metadata["Title"]).to eql "My amazing icon!"
21
+ expect(metadata["Author"]).to eql "Willem van Bergen"
23
22
  end
24
23
 
25
24
  it "should load empty images correctly" do
26
- expect do
27
- ChunkyPNG::Image.from_file(resource_file('empty.png'))
28
- end.to_not raise_error
25
+ expect { ChunkyPNG::Image.from_file(resource_file("empty.png")) }.to_not raise_error
29
26
  end
30
27
  end
31
28
  end
@@ -1,58 +1,56 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG::Point do
4
-
5
4
  subject { ChunkyPNG::Point.new(1, 2) }
6
5
 
7
6
  it { should respond_to(:x) }
8
7
  it { should respond_to(:y) }
9
8
 
10
- describe '#within_bounds?' do
9
+ describe "#within_bounds?" do
11
10
  it { should be_within_bounds(2, 3) }
12
- it { should_not be_within_bounds('1x3') }
11
+ it { should_not be_within_bounds("1x3") }
13
12
  it { should_not be_within_bounds(2, 2) }
14
- it { should_not be_within_bounds('[1 2]') }
13
+ it { should_not be_within_bounds("[1 2]") }
15
14
  end
16
15
 
17
- describe '#<=>' do
16
+ describe "#<=>" do
18
17
  it "should return 0 if the coordinates are identical" do
19
- expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql 0
18
+ expect((subject <=> ChunkyPNG::Point.new(1, 2))).to eql(0)
20
19
  end
21
20
 
22
21
  it "should return -1 if the y coordinate is smaller than the other one" do
23
- expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql -1
24
- expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql -1 # x doesn't matter
25
- expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql -1 # x doesn't matter
22
+ expect((subject <=> ChunkyPNG::Point.new(1, 3))).to eql(-1)
23
+ expect((subject <=> ChunkyPNG::Point.new(0, 3))).to eql(-1) # x doesn't matter
24
+ expect((subject <=> ChunkyPNG::Point.new(2, 3))).to eql(-1) # x doesn't matter
26
25
  end
27
26
 
28
27
  it "should return 1 if the y coordinate is larger than the other one" do
29
- expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql 1
30
- expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql 1 # x doesn't matter
31
- expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql 1 # x doesn't matter
28
+ expect((subject <=> ChunkyPNG::Point.new(1, 0))).to eql(1)
29
+ expect((subject <=> ChunkyPNG::Point.new(0, 0))).to eql(1) # x doesn't matter
30
+ expect((subject <=> ChunkyPNG::Point.new(2, 0))).to eql(1) # x doesn't matter
32
31
  end
33
32
 
34
33
  it "should return -1 if the x coordinate is smaller and y is the same" do
35
- expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql -1
34
+ expect((subject <=> ChunkyPNG::Point.new(2, 2))).to eql(-1)
36
35
  end
37
36
 
38
37
  it "should return 1 if the x coordinate is larger and y is the same" do
39
- expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql 1
38
+ expect((subject <=> ChunkyPNG::Point.new(0, 2))).to eql(1)
40
39
  end
41
40
  end
42
41
  end
43
42
 
44
- describe 'ChunkyPNG.Point' do
43
+ describe "ChunkyPNG.Point" do
45
44
  subject { ChunkyPNG::Point.new(1, 2) }
46
45
 
47
-
48
46
  it "should create a point from a 2-item array" do
49
47
  expect(ChunkyPNG::Point([1, 2])).to eql subject
50
- expect(ChunkyPNG::Point(['1', '2'])).to eql subject
48
+ expect(ChunkyPNG::Point(["1", "2"])).to eql subject
51
49
  end
52
50
 
53
51
  it "should create a point from a hash with x and y keys" do
54
- expect(ChunkyPNG::Point(:x => 1, :y => 2)).to eql subject
55
- expect(ChunkyPNG::Point('x' => '1', 'y' => '2')).to eql subject
52
+ expect(ChunkyPNG::Point(x: 1, y: 2)).to eql subject
53
+ expect(ChunkyPNG::Point("x" => "1", "y" => "2")).to eql subject
56
54
  end
57
55
 
58
56
  it "should create a point from a ChunkyPNG::Dimension object" do
@@ -62,9 +60,9 @@ describe 'ChunkyPNG.Point' do
62
60
 
63
61
  it "should create a point from a point-like string" do
64
62
  [
65
- ChunkyPNG::Point('1,2'),
66
- ChunkyPNG::Point('1 2'),
67
- ChunkyPNG::Point('(1 , 2)'),
63
+ ChunkyPNG::Point("1,2"),
64
+ ChunkyPNG::Point("1 2"),
65
+ ChunkyPNG::Point("(1 , 2)"),
68
66
  ChunkyPNG::Point("{1,\t2}"),
69
67
  ChunkyPNG::Point("[1 2}"),
70
68
  ].all? { |point| point == subject }
@@ -1,23 +1,22 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  begin
4
- require 'chunky_png/rmagick'
4
+ require "chunky_png/rmagick"
5
5
 
6
6
  describe ChunkyPNG::RMagick do
7
-
8
7
  it "should import an image from RMagick correctly" do
9
- image = Magick::Image.read(resource_file('composited.png')).first
8
+ image = Magick::Image.read(resource_file("composited.png")).first
10
9
  canvas = ChunkyPNG::RMagick.import(image)
11
- expect(canvas).to eql reference_canvas('composited')
10
+ expect(canvas).to eql reference_canvas("composited")
12
11
  end
13
12
 
14
13
  it "should export an image to RMagick correctly" do
15
- canvas = reference_canvas('composited')
14
+ canvas = reference_canvas("composited")
16
15
  image = ChunkyPNG::RMagick.export(canvas)
17
- image.format = 'PNG32'
16
+ image.format = "PNG32"
18
17
  expect(canvas).to eql ChunkyPNG::Canvas.from_blob(image.to_blob)
19
18
  end
20
19
  end
21
- rescue LoadError => e
20
+ rescue LoadError
22
21
  # skipping RMagick tests
23
22
  end
@@ -1,17 +1,17 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ChunkyPNG::Vector do
4
4
  subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]) }
5
5
 
6
6
  it { should respond_to(:points) }
7
7
 
8
- describe '#length' do
8
+ describe "#length" do
9
9
  it "shopuld have 3 items" do
10
10
  expect(subject.length).to eql(3)
11
11
  end
12
12
  end
13
13
 
14
- describe '#x_range' do
14
+ describe "#x_range" do
15
15
  it "should get the right range of x values" do
16
16
  expect(subject.x_range).to eql(1..4)
17
17
  end
@@ -29,7 +29,7 @@ describe ChunkyPNG::Vector do
29
29
  end
30
30
  end
31
31
 
32
- describe '#y_range' do
32
+ describe "#y_range" do
33
33
  it "should get the right range of y values" do
34
34
  expect(subject.y_range).to eql(3..6)
35
35
  end
@@ -47,7 +47,7 @@ describe ChunkyPNG::Vector do
47
47
  end
48
48
  end
49
49
 
50
- describe '#offset' do
50
+ describe "#offset" do
51
51
  it "should return a ChunkyPNG::Point" do
52
52
  expect(subject.offset).to be_kind_of(ChunkyPNG::Point)
53
53
  end
@@ -58,7 +58,7 @@ describe ChunkyPNG::Vector do
58
58
  end
59
59
  end
60
60
 
61
- describe '#dimension' do
61
+ describe "#dimension" do
62
62
  it "should return a ChunkyPNG::Dimension" do
63
63
  expect(subject.dimension).to be_kind_of(ChunkyPNG::Dimension)
64
64
  end
@@ -69,26 +69,30 @@ describe ChunkyPNG::Vector do
69
69
  end
70
70
  end
71
71
 
72
- describe '#edges' do
72
+ describe "#edges" do
73
73
  it "should get three edges when closing the path" do
74
- expect(subject.edges(true).to_a).to eql [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
75
- [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
76
- [ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)]]
74
+ expect(subject.edges(true).to_a).to eql [
75
+ [ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
76
+ [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
77
+ [ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)],
78
+ ]
77
79
  end
78
80
 
79
81
  it "should get two edges when not closing the path" do
80
- expect(subject.edges(false).to_a).to eql [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
81
- [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]]
82
+ expect(subject.edges(false).to_a).to eql [
83
+ [ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
84
+ [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
85
+ ]
82
86
  end
83
87
  end
84
88
  end
85
89
 
86
- describe 'ChunkyPNG.Vector' do
90
+ describe "ChunkyPNG.Vector" do
87
91
  let(:example) { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
88
92
 
89
93
  it "should return an empty vector when given an empty array" do
90
94
  expect(ChunkyPNG::Vector()).to eql ChunkyPNG::Vector.new([])
91
- expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([])
95
+ expect(ChunkyPNG::Vector(*[])).to eql ChunkyPNG::Vector.new([]) # rubocop:disable Lint/UnneededSplatExpansion
92
96
  end
93
97
 
94
98
  it "should raise an error when an odd number of numerics is given" do
@@ -96,14 +100,14 @@ describe 'ChunkyPNG.Vector' do
96
100
  end
97
101
 
98
102
  it "should create a vector from a string" do
99
- expect(ChunkyPNG::Vector('(2,4) (1,2) (3,6)')).to eql example
103
+ expect(ChunkyPNG::Vector("(2,4) (1,2) (3,6)")).to eql example
100
104
  end
101
105
 
102
106
  it "should create a vector from a flat array" do
103
- expect(ChunkyPNG::Vector(2,4,1,2,3,6)).to eql example
107
+ expect(ChunkyPNG::Vector(2, 4, 1, 2, 3, 6)).to eql example
104
108
  end
105
109
 
106
110
  it "should create a vector from a nested array" do
107
- expect(ChunkyPNG::Vector('(2,4)', [1, 2], :x => 3, :y => 6)).to eql example
111
+ expect(ChunkyPNG::Vector("(2,4)", [1, 2], x: 3, y: 6)).to eql example
108
112
  end
109
113
  end