File: mutate_spec.rb

package info (click to toggle)
ruby-vips 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,164 kB
  • sloc: ruby: 3,530; makefile: 3
file content (62 lines) | stat: -rw-r--r-- 1,438 bytes parent folder | download
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
58
59
60
61
62
require "spec_helper"

RSpec.describe Vips::MutableImage do
  it "can set! metadata in mutate" do
    image = Vips::Image.black(16, 16)
    image = image.mutate { |x|
      x.set_type! GObject::GINT_TYPE, "banana", 12
    }

    expect(image.get("banana")).to eq(12)
  end

  it "can remove! metadata in mutate" do
    image = Vips::Image.black(16, 16)
    image = image.mutate { |x|
      x.set_type! GObject::GINT_TYPE, "banana", 12
    }

    image = image.mutate { |x|
      x.remove! "banana"
    }

    expect(image.get_typeof("banana")).to eq(0)
  end

  it "can call destructive operations in mutate" do
    image = Vips::Image.black(16, 16)
    image = image.mutate { |x|
      x.draw_line! 255, 0, 0, x.width, x.height
    }

    expect(image.avg).to be > 0
  end

  it "cannot call non-destructive operations in mutate" do
    image = Vips::Image.black(16, 16)

    expect {
      image = image.mutate { |x|
        x.invert
      }
    }.to raise_exception(Vips::Error)
  end

  it "cannot use mutable images as arguments in mutate" do
    image = Vips::Image.black(16, 16)

    expect {
      image = image.mutate { |x|
        x.draw_image! x, 10, 10
      }
    }.to raise_exception(Vips::Error)
  end

  it "cannot call destructive operations outside mutate" do
    image = Vips::Image.black(16, 16)

    expect {
      image.draw_line! 255, 0, 0, image.width, image.height
    }.to raise_exception(Vips::Error)
  end
end