forked from zdavatz/spreadsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfont.rb
163 lines (160 loc) · 5.76 KB
/
font.rb
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env ruby
# TestFont -- Spreadsheet -- 09.10.2008 -- [email protected]
$: << File.expand_path('../lib', File.dirname(__FILE__))
require 'test/unit'
require 'spreadsheet'
module Spreadsheet
class TestFont < Test::Unit::TestCase
def setup
@font = Font.new 'Arial'
end
def test_italic
assert_equal false, @font.italic
@font.italic!
assert_equal true, @font.italic
@font.italic = nil
assert_equal false, @font.italic
@font.italic = 1
assert_equal true, @font.italic
end
def test_encoding
assert_equal :default, @font.encoding
@font.encoding = :apple_roman
assert_equal :apple_roman, @font.encoding
@font.encoding = 'Chinese Simplified'
assert_equal :chinese_simplified, @font.encoding
assert_raises ArgumentError do @font.size = 'ascii' end
assert_equal :chinese_simplified, @font.encoding
@font.encoding = nil
assert_equal :default, @font.encoding
end
def test_family
assert_equal :none, @font.family
@font.family = :roman
assert_equal :roman, @font.family
@font.family = 'Swiss'
assert_equal :swiss, @font.family
assert_raises ArgumentError do @font.size = :greek end
assert_equal :swiss, @font.family
@font.family = nil
assert_equal :none, @font.family
end
def test_name
assert_equal 'Arial', @font.name
@font.name = 'Helvetica'
assert_equal 'Helvetica', @font.name
end
def test_outline
assert_equal false, @font.outline
@font.outline!
assert_equal true, @font.outline
@font.outline = nil
assert_equal false, @font.outline
@font.outline = 1
assert_equal true, @font.outline
end
def test_escapement
assert_equal :normal, @font.escapement
@font.escapement = :superscript
assert_equal :superscript, @font.escapement
@font.escapement = 'sub'
assert_equal :subscript, @font.escapement
assert_raises ArgumentError do @font.size = "upwards" end
assert_equal :subscript, @font.escapement
@font.escapement = nil
assert_equal :normal, @font.escapement
end
def test_shadow
assert_equal false, @font.shadow
@font.shadow!
assert_equal true, @font.shadow
@font.shadow = nil
assert_equal false, @font.shadow
@font.shadow = 1
assert_equal true, @font.shadow
end
def test_size
assert_equal 10, @font.size
@font.size = 12
assert_equal 12, @font.size
@font.size = 11.2
assert_equal 11.2, @font.size
assert_raises ArgumentError do @font.size = "123" end
end
def test_strikeout
assert_equal false, @font.strikeout
@font.strikeout!
assert_equal true, @font.strikeout
@font.strikeout = nil
assert_equal false, @font.strikeout
@font.strikeout = 1
assert_equal true, @font.strikeout
end
def test_underline
assert_equal :none, @font.underline
@font.underline = :single
assert_equal :single, @font.underline
@font.underline = 'double accounting'
assert_equal :double_accounting, @font.underline
assert_raises ArgumentError do @font.size = :triple end
assert_equal :double_accounting, @font.underline
@font.underline = nil
assert_equal :none, @font.underline
@font.underline = true
assert_equal :single, @font.underline
end
def test_weight
assert_equal :normal, @font.weight
@font.weight = :bold
assert_equal :bold, @font.weight
@font.weight = 100
assert_equal 100, @font.weight
assert_raises ArgumentError do @font.weight = Object.new end
assert_equal 100, @font.weight
@font.weight = 'bold'
assert_equal :bold, @font.weight
@font.weight = nil
assert_equal :normal, @font.weight
end
def test_key
expected = 'Arial_10_normal_normal_none_text_none_default'
assert_equal expected, @font.key
@font.name = 'Helvetica'
expected = 'Helvetica_10_normal_normal_none_text_none_default'
assert_equal expected, @font.key
@font.size = 12
expected = 'Helvetica_12_normal_normal_none_text_none_default'
assert_equal expected, @font.key
@font.weight = :bold
expected = 'Helvetica_12_bold_normal_none_text_none_default'
assert_equal expected, @font.key
@font.italic!
expected = 'Helvetica_12_bold_italic_normal_none_text_none_default'
assert_equal expected, @font.key
@font.strikeout!
expected = 'Helvetica_12_bold_italic_strikeout_normal_none_text_none_default'
assert_equal expected, @font.key
@font.outline!
expected = 'Helvetica_12_bold_italic_strikeout_outline_normal_none_text_none_default'
assert_equal expected, @font.key
@font.shadow!
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_normal_none_text_none_default'
assert_equal expected, @font.key
@font.escapement = :super
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_superscript_none_text_none_default'
assert_equal expected, @font.key
@font.underline = :double
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_superscript_double_text_none_default'
assert_equal expected, @font.key
@font.color = :blue
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_superscript_double_blue_none_default'
assert_equal expected, @font.key
@font.family = :swiss
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_superscript_double_blue_swiss_default'
assert_equal expected, @font.key
@font.encoding = :iso_latin1
expected = 'Helvetica_12_bold_italic_strikeout_outline_shadow_superscript_double_blue_swiss_iso_latin1'
assert_equal expected, @font.key
end
end
end