osheet-xmlss 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,263 @@
1
+ require "assert"
2
+
3
+ require 'osheet/xmlss/style_settings'
4
+
5
+ module Osheet::Xmlss
6
+
7
+ class StyleSettingsTests < Assert::Context
8
+ desc "the style writer when building"
9
+ before do
10
+ @settings = StyleSettings.new([])
11
+ @workbook = Osheet::Workbook.new
12
+ @workbook.style('.align.center') { @workbook.align :center }
13
+ @workbook.style('.font.size') { @workbook.font 14 }
14
+ @workbook.style('.font.weight') { @workbook.font :bold }
15
+ @workbook.style('.font.style') { @workbook.font :italic }
16
+ @workbook.style('.bg.color') { @workbook.bg '#FF0000' }
17
+ @workbook.style('.border.color') { @workbook.border '#FF0000', :thin }
18
+ end
19
+ subject { @settings }
20
+
21
+ should have_reader :styles, :value
22
+ should have_instance_method :setting, :[]
23
+
24
+ should "be empty if no styles given" do
25
+ assert_equal({}, subject.value)
26
+ end
27
+
28
+ should "conditionally run a block if the setting exists and is not empty" do
29
+ settings = StyleSettings.new([@workbook.styles.first])
30
+ @something = ''
31
+
32
+ settings.setting(:font) { @something = 'i should be empty' }
33
+ assert_empty @something
34
+
35
+ settings.setting(:align) { @something = 'i should not be empty' }
36
+ assert_not_empty @something
37
+ end
38
+
39
+ end
40
+
41
+
42
+
43
+ class AlignmentSettingsTests < StyleSettingsTests
44
+ desc "align settings"
45
+
46
+ should "translate horizontal directives" do
47
+ assert_equal({:horizontal => :left}, subject.send(:align_settings, [:left]))
48
+ assert_equal({:horizontal => :center}, subject.send(:align_settings, [:center]))
49
+ assert_equal({:horizontal => :right}, subject.send(:align_settings, [:right]))
50
+ end
51
+
52
+ should "translate vertical directives" do
53
+ assert_equal({:vertical => :top}, subject.send(:align_settings, [:top]))
54
+ assert_equal({:vertical => :center}, subject.send(:align_settings, [:middle]))
55
+ assert_equal({:vertical => :bottom}, subject.send(:align_settings, [:bottom]))
56
+ end
57
+
58
+ should "translate wrap text and rotate directives" do
59
+ assert_equal({:wrap_text => true}, subject.send(:align_settings, [:wrap]))
60
+ assert_equal({:rotate => 90}, subject.send(:align_settings, [90]))
61
+ end
62
+
63
+ end
64
+
65
+
66
+
67
+ class FontSettingsTests < StyleSettingsTests
68
+ desc "font settings"
69
+
70
+ should "translate size, color and name directives" do
71
+ assert_equal({:size => 12}, subject.send(:font_settings, [12]))
72
+ assert_equal({:color => '#FFFFFF'}, subject.send(:font_settings, ['#FFFFFF']))
73
+ assert_equal({:name => 'Arial'}, subject.send(:font_settings, ['Arial']))
74
+ end
75
+
76
+ should "translate style directives" do
77
+ assert_equal({:bold => true}, subject.send(:font_settings, [:bold]))
78
+ assert_equal({:italic => true}, subject.send(:font_settings, [:italic]))
79
+ assert_equal({:shadow => true}, subject.send(:font_settings, [:shadow]))
80
+ assert_equal({:alignment => :subscript}, subject.send(:font_settings, [:subscript]))
81
+ assert_equal({:alignment => :superscript}, subject.send(:font_settings, [:superscript]))
82
+ assert_equal({:strike_through => true}, subject.send(:font_settings, [:strikethrough]))
83
+ end
84
+
85
+ should "translate underline directives" do
86
+ assert_equal({:underline => :single}, subject.send(:font_settings, [:underline]))
87
+ assert_equal({:underline => :double}, subject.send(:font_settings, [:double_underline]))
88
+ assert_equal({:underline => :single_accounting}, subject.send(:font_settings, [:accounting_underline]))
89
+ assert_equal({:underline => :double_accounting}, subject.send(:font_settings, [:double_accounting_underline]))
90
+ end
91
+
92
+ end
93
+
94
+
95
+
96
+
97
+ class BgSettingsTests < StyleSettingsTests
98
+ desc "bg settings"
99
+
100
+ should "translate color directives" do
101
+ assert_equal({:color => '#FFFFFF', :pattern => :solid}, subject.send(:bg_settings, ['#FFFFFF']))
102
+ end
103
+
104
+ should "translate pattern directives" do
105
+ assert_equal({:pattern => :solid}, subject.send(:bg_settings, [:solid]))
106
+ assert_equal({
107
+ :pattern => :horz_stripe,
108
+ :pattern_color => '#0000FF'
109
+ }, subject.send(:bg_settings, [{:horz_stripe => '#0000FF'}]))
110
+ end
111
+
112
+ end
113
+
114
+
115
+
116
+
117
+
118
+ class BorderSettingsTests < StyleSettingsTests
119
+ desc "border settings"
120
+
121
+ should "translate color directives" do
122
+ assert_equal({:color => '#FFFFFF'}, subject.send(:border_settings, ['#FFFFFF']))
123
+ end
124
+
125
+ should "translate position directives" do
126
+ assert_equal({:position => :top}, subject.send(:border_settings, [:top]))
127
+ end
128
+
129
+ should "translate weight directives" do
130
+ assert_equal({:weight => :thick}, subject.send(:border_settings, [:thick]))
131
+ end
132
+
133
+ should "translate line_style directives" do
134
+ assert_equal({:line_style => :dot}, subject.send(:border_settings, [:dot]))
135
+ end
136
+
137
+ should "translate position specific directives" do
138
+ assert_equal({
139
+ :position => :left,
140
+ :color => '#FFFFFF',
141
+ :weight => :thin
142
+ }, subject.send(:border_left_settings, ['#FFFFFF', :thin]))
143
+ end
144
+
145
+ end
146
+
147
+
148
+
149
+ class ParseSettingsTests < StyleSettingsTests
150
+ desc "settings"
151
+
152
+ should "parse Osheet style objs for their settings" do
153
+ assert_equal({
154
+ :align => {
155
+ :horizontal => :center
156
+ }
157
+ }, subject.send(:style_settings, @workbook.styles.first))
158
+
159
+ assert_equal({
160
+ :border_top => {
161
+ :position=>:top,
162
+ :color=>"#FF0000",
163
+ :weight=>:thin
164
+ },
165
+ :border_right => {
166
+ :position=>:right,
167
+ :color=>"#FF0000",
168
+ :weight=>:thin
169
+ },
170
+ :border_bottom => {
171
+ :position=>:bottom,
172
+ :color=>"#FF0000",
173
+ :weight=>:thin
174
+ },
175
+ :border_left => {
176
+ :position=>:left,
177
+ :color=>"#FF0000",
178
+ :weight=>:thin
179
+ }
180
+ }, subject.send(:style_settings, @workbook.styles.last))
181
+ end
182
+
183
+ should "merge style settings from multiple Osheet style objs" do
184
+ set1 = {
185
+ :font => {
186
+ :color => '#FF0000',
187
+ :name => "Arial"
188
+ }
189
+ }
190
+ set2 = {
191
+ :font => {
192
+ :color => '#0000FF',
193
+ :size => 12
194
+ }
195
+ }
196
+ set3 = {
197
+ :align => {
198
+ :horizontal => :center
199
+ }
200
+ }
201
+
202
+ # should concat keys in both sets
203
+ assert_equal({
204
+ :font => {
205
+ :color => '#0000FF',
206
+ :name => "Arial",
207
+ :size => 12
208
+ }
209
+ }, subject.send(:merged_settings, set1.dup, set2.dup))
210
+
211
+ # should add keys not in first set
212
+ assert_equal({
213
+ :font => {
214
+ :color => '#0000FF',
215
+ :size => 12
216
+ },
217
+ :align => {
218
+ :horizontal => :center
219
+ }
220
+ }, subject.send(:merged_settings, set2.dup, set3.dup))
221
+
222
+ end
223
+
224
+ should "set its value given its set of styles" do
225
+ assert_equal({
226
+ :align => {
227
+ :horizontal => :center
228
+ },
229
+ :font => {
230
+ :bold => true,
231
+ :italic => true,
232
+ :size => 14
233
+ },
234
+ :bg => {
235
+ :pattern => :solid,
236
+ :color => "#FF0000"
237
+ },
238
+ :border_top => {
239
+ :position => :top,
240
+ :color => "#FF0000",
241
+ :weight => :thin
242
+ },
243
+ :border_right => {
244
+ :position => :right,
245
+ :color => "#FF0000",
246
+ :weight => :thin
247
+ },
248
+ :border_bottom => {
249
+ :position => :bottom,
250
+ :color => "#FF0000",
251
+ :weight => :thin
252
+ },
253
+ :border_left => {
254
+ :position => :left,
255
+ :color => "#FF0000",
256
+ :weight => :thin
257
+ }
258
+ }, StyleSettings.new(@workbook.styles).value)
259
+ end
260
+ end
261
+
262
+ end
263
+
@@ -0,0 +1,340 @@
1
+ require "assert"
2
+
3
+ require 'osheet/xmlss_writer'
4
+
5
+ module Osheet::Xmlss
6
+
7
+ class StylesTests < Assert::Context
8
+ before do
9
+ @writer = Osheet::XmlssWriter.new
10
+ @workbook = Osheet::Workbook.new(@writer)
11
+ end
12
+ subject { @writer }
13
+
14
+ should "not have a style cache until its bound to an osheet workbook" do
15
+ writer = Osheet::XmlssWriter.new
16
+ assert_nil writer.style_cache
17
+ writer.bind(@workbook)
18
+ assert_not_nil writer.style_cache
19
+ end
20
+
21
+ should "return no style if no class or format given" do
22
+ assert_nil subject.style(nil)
23
+ assert_nil subject.style('')
24
+ assert_not_nil subject.style('awesome')
25
+ end
26
+
27
+ end
28
+
29
+ class StyleMethTests < StylesTests
30
+ desc "Xmlss style writer"
31
+ before do
32
+ @workbook.style('.font.size') { @workbook.font 14 }
33
+ @workbook.style('.font.weight') { @workbook.font :bold }
34
+ @workbook.style('.font.style') { @workbook.font :italic }
35
+ @workbook.style('.align.center') { @workbook.align :center }
36
+ end
37
+
38
+ should "build a style obj and add it to the writers styles" do
39
+ xmlss_style = subject.style('awesome')
40
+ assert_kind_of ::Xmlss::Style::Base, xmlss_style
41
+ assert_equal '.awesome', xmlss_style.id
42
+ assert_equal 1, subject.style_cache.size
43
+ assert_equal xmlss_style, subject.style_cache[xmlss_style.id]
44
+ end
45
+
46
+ should "write style markup from many matching osheet styles" do
47
+ xmlss_style = subject.style('font size weight style align center')
48
+ assert_equal '.font.size.weight.style.align.center', xmlss_style.id
49
+ end
50
+
51
+ end
52
+
53
+ class AlignmentTests < StylesTests
54
+ desc "Alignment style writer"
55
+ before do
56
+ [ :left, :center, :right,
57
+ :top, :middle, :bottom,
58
+ :wrap
59
+ ].each do |s|
60
+ @workbook.style(".align.#{s}") { @workbook.align s }
61
+ end
62
+ @workbook.style('.align.rotate') { @workbook.align 90 }
63
+ end
64
+
65
+ should "write style markup with no alignment settings if no alignment style match" do
66
+ subject.style('align')
67
+ assert_equal(
68
+ "<Style ss:ID=\".align\"><NumberFormat /></Style>",
69
+ xmlss_style_markup(subject)
70
+ )
71
+ end
72
+
73
+ should "write style markup for horizontal alignment settings" do
74
+ subject.style('align left')
75
+ subject.style('align center')
76
+ subject.style('align right')
77
+ assert_equal(
78
+ "<Style ss:ID=\".align.left\"><Alignment ss:Horizontal=\"Left\" /><NumberFormat /></Style><Style ss:ID=\".align.center\"><Alignment ss:Horizontal=\"Center\" /><NumberFormat /></Style><Style ss:ID=\".align.right\"><Alignment ss:Horizontal=\"Right\" /><NumberFormat /></Style>",
79
+ xmlss_style_markup(subject)
80
+ )
81
+ end
82
+
83
+ should "write style markup for vertical alignment settings" do
84
+ subject.style('align top')
85
+ subject.style('align middle')
86
+ subject.style('align bottom')
87
+ assert_equal(
88
+ "<Style ss:ID=\".align.top\"><Alignment ss:Vertical=\"Top\" /><NumberFormat /></Style><Style ss:ID=\".align.middle\"><Alignment ss:Vertical=\"Center\" /><NumberFormat /></Style><Style ss:ID=\".align.bottom\"><Alignment ss:Vertical=\"Bottom\" /><NumberFormat /></Style>",
89
+ xmlss_style_markup(subject)
90
+ )
91
+ end
92
+
93
+ should "write style markup for text wrap settings" do
94
+ subject.style('align wrap')
95
+ assert_equal(
96
+ "<Style ss:ID=\".align.wrap\"><Alignment ss:WrapText=\"1\" /><NumberFormat /></Style>",
97
+ xmlss_style_markup(subject)
98
+ )
99
+ end
100
+
101
+ should "write style markup for text rotation settings" do
102
+ subject.style('align rotate')
103
+ assert_equal(
104
+ "<Style ss:ID=\".align.rotate\"><Alignment ss:Rotate=\"90\" /><NumberFormat /></Style>",
105
+ xmlss_style_markup(subject)
106
+ )
107
+ end
108
+
109
+ end
110
+
111
+ class FontTests < StylesTests
112
+ desc "Font style writer"
113
+ before do
114
+ [ :underline, :double_underline, :accounting_underline, :double_accounting_underline,
115
+ :subscript, :superscript, :shadow, :strikethrough, :wrap,
116
+ :bold, :italic
117
+ ].each do |s|
118
+ @workbook.style(".font.#{s}") { @workbook.font s }
119
+ end
120
+ @workbook.style('.font.size') { @workbook.font 14 }
121
+ @workbook.style('.font.color') { @workbook.font '#FF0000' }
122
+ @workbook.style('.font.name') { @workbook.font 'Verdana' }
123
+ end
124
+
125
+ should "write style markup with empty font settings if no match" do
126
+ subject.style('font')
127
+ assert_equal(
128
+ "<Style ss:ID=\".font\"><NumberFormat /></Style>",
129
+ xmlss_style_markup(subject)
130
+ )
131
+ end
132
+
133
+ should "write style markup for font underline settings" do
134
+ subject.style('font underline')
135
+ subject.style('font double_underline')
136
+ subject.style('font accounting_underline')
137
+ subject.style('font double_accounting_underline')
138
+ assert_equal(
139
+ "<Style ss:ID=\".font.underline\"><Font ss:Underline=\"Single\" /><NumberFormat /></Style><Style ss:ID=\".font.double_underline\"><Font ss:Underline=\"Double\" /><NumberFormat /></Style><Style ss:ID=\".font.accounting_underline\"><Font ss:Underline=\"SingleAccounting\" /><NumberFormat /></Style><Style ss:ID=\".font.double_accounting_underline\"><Font ss:Underline=\"DoubleAccounting\" /><NumberFormat /></Style>",
140
+ xmlss_style_markup(subject)
141
+ )
142
+
143
+ end
144
+
145
+ should "write style markup for font alignment settings" do
146
+ subject.style('font subscript')
147
+ subject.style('font superscript')
148
+ assert_equal(
149
+ "<Style ss:ID=\".font.subscript\"><Font ss:VerticalAlign=\"Subscript\" /><NumberFormat /></Style><Style ss:ID=\".font.superscript\"><Font ss:VerticalAlign=\"Superscript\" /><NumberFormat /></Style>",
150
+ xmlss_style_markup(subject)
151
+ )
152
+ end
153
+
154
+ should "write style markup for font style settings" do
155
+ subject.style('font bold')
156
+ subject.style('font italic')
157
+ subject.style('font strikethrough')
158
+ subject.style('font shadow')
159
+ assert_equal(
160
+ "<Style ss:ID=\".font.bold\"><Font ss:Bold=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.italic\"><Font ss:Italic=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.strikethrough\"><Font ss:StrikeThrough=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.shadow\"><Font ss:Shadow=\"1\" /><NumberFormat /></Style>",
161
+ xmlss_style_markup(subject)
162
+ )
163
+ end
164
+
165
+ should "write style markup for font size" do
166
+ subject.style('font size')
167
+ assert_equal(
168
+ "<Style ss:ID=\".font.size\"><Font ss:Size=\"14\" /><NumberFormat /></Style>",
169
+ xmlss_style_markup(subject)
170
+ )
171
+ end
172
+
173
+ should "write style markup for font color" do
174
+ subject.style('font color')
175
+ assert_equal(
176
+ "<Style ss:ID=\".font.color\"><Font ss:Color=\"#FF0000\" /><NumberFormat /></Style>",
177
+ xmlss_style_markup(subject)
178
+ )
179
+ end
180
+
181
+ should "write style markup for font name" do
182
+ subject.style('font name')
183
+ assert_equal(
184
+ "<Style ss:ID=\".font.name\"><Font ss:FontName=\"Verdana\" /><NumberFormat /></Style>",
185
+ xmlss_style_markup(subject)
186
+ )
187
+ end
188
+
189
+ end
190
+
191
+ class BgTests < StylesTests
192
+ desc "Bg writer"
193
+ before do
194
+ @workbook.style('.bg.color') { @workbook.bg '#FF0000' }
195
+ @workbook.style('.bg.pattern-only') { @workbook.bg :solid }
196
+ @workbook.style('.bg.pattern-color') { @workbook.bg :horz_stripe => '#0000FF' }
197
+ @workbook.style('.bg.color-first') { @workbook.bg '#00FF00', {:horz_stripe => '#0000FF'} }
198
+ @workbook.style('.bg.pattern-first') { @workbook.bg({:horz_stripe => '#0000FF'}, '#00FF00') }
199
+ end
200
+
201
+ should "write style markup with empty bg settings when no match" do
202
+ subject.style('bg')
203
+ assert_equal(
204
+ "<Style ss:ID=\".bg\"><NumberFormat /></Style>",
205
+ xmlss_style_markup(subject)
206
+ )
207
+ end
208
+
209
+ should "write style markup for bg color and auto set the pattern to solid" do
210
+ subject.style('bg color')
211
+ assert_equal(
212
+ "<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
213
+ xmlss_style_markup(subject)
214
+ )
215
+ end
216
+
217
+ should "write style markup for bg pattern settings" do
218
+ subject.style('bg pattern-only')
219
+ subject.style('bg pattern-only')
220
+ subject.style('bg pattern-color')
221
+ subject.style('bg pattern-color')
222
+ assert_equal(
223
+ "<Style ss:ID=\".bg.pattern-only\"><Interior ss:Pattern=\"Solid\" /><NumberFormat /></Style><Style ss:ID=\".bg.pattern-color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
224
+ xmlss_style_markup(subject)
225
+ )
226
+ end
227
+
228
+ should "write style markup setting pattern to solid when setting bg color" do
229
+ subject.style('bg color')
230
+ assert_equal(
231
+ "<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
232
+ xmlss_style_markup(subject)
233
+ )
234
+ end
235
+
236
+ should "write style markup setting pattern to pattern setting when first setting bg color then pattern" do
237
+ subject.style('bg color-first')
238
+ assert_equal(
239
+ "<Style ss:ID=\".bg.color-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
240
+ xmlss_style_markup(subject)
241
+ )
242
+ end
243
+
244
+ should "write style markup setting pattern to pattern setting when first setting bg pattern then color" do
245
+ subject.style('bg pattern-first')
246
+ assert_equal(
247
+ "<Style ss:ID=\".bg.pattern-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
248
+ xmlss_style_markup(subject)
249
+ )
250
+ end
251
+
252
+ end
253
+
254
+ class BorderTests < StylesTests
255
+ desc "Font border writer"
256
+ before do
257
+ ::Osheet::Style::BORDER_POSITIONS.each do |p|
258
+ @workbook.style(".border.#{p}") { @workbook.send("border_#{p}", :thin) }
259
+ end
260
+ [:hairline, :thin, :medium, :thick].each do |w|
261
+ @workbook.style(".border.#{w}") { @workbook.border_top w }
262
+ end
263
+ [:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
264
+ @workbook.style(".border.#{s}") { @workbook.border_top s }
265
+ end
266
+ @workbook.style('.border.color') { @workbook.border_top '#FF0000' }
267
+ @workbook.style('.border.all') { @workbook.border :thick, :dash, '#FF0000' }
268
+ end
269
+
270
+ should "write style markup with empty border settings when no match" do
271
+ subject.style('border')
272
+ assert_equal(
273
+ "<Style ss:ID=\".border\"><NumberFormat /></Style>",
274
+ xmlss_style_markup(subject)
275
+ )
276
+ end
277
+
278
+ should "write style markup with identical settings for all positions when using 'border'" do
279
+ subject.style('border all')
280
+ assert_equal(
281
+ "<Style ss:ID=\".border.all\"><Borders><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Top\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Right\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Bottom\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Left\" ss:Weight=\"3\" /></Borders><NumberFormat /></Style>",
282
+ xmlss_style_markup(subject)
283
+ )
284
+ end
285
+
286
+ should "write style markup for border specific positions" do
287
+ ::Osheet::Style::BORDER_POSITIONS.each do |p|
288
+ subject.style("border #{p}")
289
+ end
290
+ assert_equal(
291
+ "<Style ss:ID=\".border.top\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.right\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Right\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.bottom\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Bottom\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.left\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Left\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
292
+ xmlss_style_markup(subject)
293
+ )
294
+ end
295
+
296
+ should "write style markup for border weight settings" do
297
+ [:hairline, :thin, :medium, :thick].each do |w|
298
+ subject.style("border #{w}")
299
+ end
300
+ assert_equal(
301
+ "<Style ss:ID=\".border.hairline\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"0\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.thin\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.medium\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"2\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.thick\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"3\" /></Borders><NumberFormat /></Style>",
302
+ xmlss_style_markup(subject)
303
+ )
304
+ end
305
+
306
+ should "write style markup for border style settings" do
307
+ [:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
308
+ subject.style("border #{s}")
309
+ end
310
+ assert_equal(
311
+ "<Style ss:ID=\".border.none\"><Borders><Border ss:LineStyle=\"None\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.continuous\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash\"><Borders><Border ss:LineStyle=\"Dash\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dot\"><Borders><Border ss:LineStyle=\"Dot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash_dot\"><Borders><Border ss:LineStyle=\"DashDot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash_dot_dot\"><Borders><Border ss:LineStyle=\"DashDotDot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
312
+ xmlss_style_markup(subject)
313
+ )
314
+ end
315
+
316
+ should "write style markup for border color" do
317
+ subject.style('border color')
318
+ assert_equal(
319
+ "<Style ss:ID=\".border.color\"><Borders><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
320
+ xmlss_style_markup(subject)
321
+ )
322
+ end
323
+
324
+ end
325
+
326
+ class NumberFormatTests < StylesTests
327
+ desc "Xmlss style number format writer"
328
+
329
+ should "write style markup with formatting" do
330
+ subject.style('', Osheet::Format.new(:text))
331
+ subject.style('', Osheet::Format.new(:datetime, 'mm/dd/yy'))
332
+ assert_equal(
333
+ "<Style ss:ID=\"..text\"><NumberFormat ss:Format=\"@\" /></Style><Style ss:ID=\"..datetime_mm/dd/yy\"><NumberFormat ss:Format=\"mm/dd/yy\" /></Style>",
334
+ xmlss_style_markup(subject)
335
+ )
336
+ end
337
+
338
+ end
339
+
340
+ end