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
|