summaryrefslogtreecommitdiffhomepage
path: root/test/stylesheet/tc_gradient_fill.rb
blob: ab4dc11ad790926c0fa285e8e9daf2c7957ce971 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

require 'tc_helper'

class TestGradientFill < Test::Unit::TestCase
  def setup
    @item = Axlsx::GradientFill.new
  end

  def teardown; end

  def test_initialiation
    assert_equal(:linear, @item.type)
    assert_nil(@item.degree)
    assert_nil(@item.left)
    assert_nil(@item.right)
    assert_nil(@item.top)
    assert_nil(@item.bottom)
    assert(@item.stop.is_a?(Axlsx::SimpleTypedList))
  end

  def test_type
    assert_raise(ArgumentError) { @item.type = 7 }
    assert_nothing_raised { @item.type = :path }
    assert_equal(:path, @item.type)
  end

  def test_degree
    assert_raise(ArgumentError) { @item.degree = -7 }
    assert_nothing_raised { @item.degree = 5.0 }
    assert_in_delta(@item.degree, 5.0)
  end

  def test_left
    assert_raise(ArgumentError) { @item.left = -1.1 }
    assert_nothing_raised { @item.left = 1.0 }
    assert_in_delta(@item.left, 1.0)
  end

  def test_right
    assert_raise(ArgumentError) { @item.right = -1.1 }
    assert_nothing_raised { @item.right = 0.5 }
    assert_in_delta(@item.right, 0.5)
  end

  def test_top
    assert_raise(ArgumentError) { @item.top = -1.1 }
    assert_nothing_raised { @item.top = 1.0 }
    assert_in_delta(@item.top, 1.0)
  end

  def test_bottom
    assert_raise(ArgumentError) { @item.bottom = -1.1 }
    assert_nothing_raised { @item.bottom = 0.0 }
    assert_in_delta(@item.bottom, 0.0)
  end

  def test_stop
    @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(rgb: "00000000"), 0.5)

    assert_equal(1, @item.stop.size)
    assert(@item.stop.last.is_a?(Axlsx::GradientStop))
  end

  def test_to_xml_string
    @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(rgb: "000000"), 0.5)
    @item.stop << Axlsx::GradientStop.new(Axlsx::Color.new(rgb: "FFFFFF"), 0.5)
    @item.type = :path
    doc = Nokogiri::XML(@item.to_xml_string)

    assert(doc.xpath("//color[@rgb='FF000000']"))
  end
end