File: braces_equals_spec.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (55 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
RSpec.describe Magick::ImageList, '#[]=' do
  it 'works' do
    image_list = described_class.new(*FILES[0..9])
    image = Magick::Image.new(5, 5)

    rv = image_list[0] = image
    expect(rv).to be(image)
    expect(image_list[0]).to be(image)
    expect(image_list.scene).to eq(0)

    # replace 2 images with 1
    image = Magick::Image.new(5, 5)
    rv = image_list[1, 2] = image
    expect(rv).to be(image)
    expect(image_list.length).to eq(9)
    expect(image_list[1]).to be(image)
    expect(image_list.scene).to eq(1)

    # replace 1 image with 2
    image = Magick::Image.new(5, 5)
    image2 = Magick::Image.new(5, 5)
    ary = [image, image2]
    rv = image_list[3, 1] = ary
    expect(rv).to be(ary)
    expect(image_list.length).to eq(10)
    expect(image_list[3]).to be(image)
    expect(image_list[4]).to be(image2)
    expect(image_list.scene).to eq(4)

    image = Magick::Image.new(5, 5)
    rv = image_list[5..6] = image
    expect(rv).to be(image)
    expect(image_list.length).to eq(9)
    expect(image_list[5]).to be(image)
    expect(image_list.scene).to eq(5)

    ary = [image, image]
    rv = image_list[7..8] = ary
    expect(rv).to be(ary)
    expect(image_list.length).to eq(9)
    expect(image_list[7]).to be(image)
    expect(image_list[8]).to be(image)
    expect(image_list.scene).to eq(8)

    rv = image_list[-1] = image
    expect(rv).to be(image)
    expect(image_list.length).to eq(9)
    expect(image_list[8]).to be(image)
    expect(image_list.scene).to eq(8)

    expect { image_list[0] = 1 }.to raise_error(ArgumentError)
    expect { image_list[0, 1] = [1, 2] }.to raise_error(ArgumentError)
    expect { image_list[2..3] = 'x' }.to raise_error(ArgumentError)
  end
end