File: replace_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 (57 lines) | stat: -rw-r--r-- 1,690 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
56
57
RSpec.describe Magick::ImageList, '#replace' do
  def make_lists
    image_list = Magick::ImageList.new(*FILES[0..9])
    image_list2 = Magick::ImageList.new # intersection is 5..9
    image_list2 << image_list[5]
    image_list2 << image_list[6]
    image_list2 << image_list[7]
    image_list2 << image_list[8]
    image_list2 << image_list[9]
    [image_list, image_list2]
  end

  it 'works' do
    image_list, image_list2 = make_lists

    # Replace with empty image_list
    result = image_list.replace([])
    expect(image_list).to be(result)
    expect(image_list.length).to eq(0)
    expect(image_list.scene).to be(nil)

    # Replace empty image_list with non-empty image_list
    temp = described_class.new

    temp.replace(image_list2)
    expect(temp.length).to eq(5)
    expect(temp.scene).to eq(4)

    # Try to replace with illegal values
    expect { image_list.replace([1, 2, 3]) }.to raise_error(ArgumentError)
  end

  it 'replaces with a shorter image_list' do
    image_list, image_list2 = make_lists

    image_list.scene = 7
    cur = image_list.cur_image
    result = image_list.replace(image_list2)
    expect(image_list).to be(result)
    expect(image_list.length).to eq(5)
    expect(image_list.scene).to eq(2)
    expect(image_list.cur_image).to be(cur)
  end

  it 'replaces with a longer image_list' do
    image_list, image_list2 = make_lists

    # Replace with longer image_list
    image_list2.scene = 2
    cur = image_list2.cur_image
    result = image_list2.replace(image_list)
    expect(image_list2).to be(result)
    expect(image_list2.length).to eq(10)
    expect(image_list2.scene).to eq(7)
    expect(image_list2.cur_image).to be(cur)
  end
end