File: test-element.rb

package info (click to toggle)
rabbit 3.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,220 kB
  • sloc: ruby: 29,637; lisp: 309; makefile: 43; sh: 9
file content (103 lines) | stat: -rw-r--r-- 4,517 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Copyright (C) 2005-2019  Kouhei Sutou <kou@cozmixng.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

require "rabbit/element"

class RabbitElementTest < Test::Unit::TestCase
  def test_normalize_font_property
    assert_normalize_font_property(["font_desc", "Sans Italic 12"],
                                   [:desc, "Sans Italic 12"])
    assert_normalize_font_property(["font_desc", "Sans Italic 12"],
                                   [:description, "Sans Italic 12"])

    assert_normalize_font_property(["font_family", "Sans"],
                                   [:family, "Sans"])

    assert_normalize_font_property(["size", 12800],
                                   [:size, 12800])
    assert_normalize_font_property(["size", "small"],
                                   [:size, "small"])

    assert_normalize_font_property(["style", "oblique"],
                                   [:style, "oblique"])

    assert_normalize_font_property(["weight", "bold"],
                                   [:weight, "bold"])

    assert_normalize_font_property(["variant", "smallcaps"],
                                   [:variant, "smallcaps"])

    assert_normalize_font_property(["stretch", "ultracondensed"],
                                   [:stretch, "ultracondensed"])
    
    assert_normalize_font_property(["foreground", "#ff00cc"],
                                   [:foreground, "#ff00cc"])
    assert_normalize_font_property(["foreground", "#ff00cc"],
                                   [:color, "#ff00cc"])
    assert_normalize_font_property(["foreground", "#ff00cc"],
                                   [:fg_color, "#ff00cc"])
    assert_normalize_font_property(["foreground", "#ff00cc"],
                                   [:fg, "#ff00cc"])

    assert_normalize_font_property(["background", "#ff00cc"],
                                   [:background, "#ff00cc"])
    assert_normalize_font_property(["background", "#ff00cc"],
                                   [:bg_color, "#ff00cc"])
    assert_normalize_font_property(["background", "#ff00cc"],
                                   [:bg, "#ff00cc"])

    assert_normalize_font_property(["underline", "low"],
                                   [:underline, "low"])
    assert_normalize_font_property(["underline", "low"],
                                   [:ul, "low"])

    assert_normalize_font_property(["underline_color", "red"],
                                   [:underline_color, "red"])
    assert_normalize_font_property(["underline_color", "red"],
                                   [:ul_color, "red"])

    assert_normalize_font_property(["rise", 12800],
                                   [:rise, 12800])
    assert_normalize_font_property(["rise", 12800],
                                   [:superscript, 12800])
    assert_normalize_font_property(["rise", -12800],
                                   [:subscript, 12800])

    assert_normalize_font_property(["strikethrough", "true"],
                                   [:strikethrough, true])
    assert_normalize_font_property(["strikethrough", "false"],
                                   [:strike_through, false])

    assert_normalize_font_property(["strikethrough_color", "red"],
                                   [:strikethrough_color, "red"])
    assert_normalize_font_property(["strikethrough_color", "red"],
                                   [:strike_through_color, "red"])

    assert_normalize_font_property(["fallback", "false"],
                                   [:fallback, false])
  end

  def normalize_font_property(key, value)
    elem = Rabbit::Element::Text.new("XXX")
    elem.__send__(:normalize_font_property, key, value)
  end

  def assert_normalize_font_property(expected, actual)
    _wrap_assertion do
      assert_equal(expected, normalize_font_property(*actual))
    end
  end
end