osheet 1.0.0.rc.1 → 1.0.0.rc.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,263 +0,0 @@
1
- require "assert"
2
-
3
- require 'osheet/xmlss_writer/style_settings'
4
-
5
- module Osheet
6
-
7
- class XmlssWriterStyleSettingsTests < Assert::Context
8
- desc "the style writer when building"
9
- before do
10
- @settings = XmlssWriter::StyleSettings.new([])
11
- @workbook = 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 = XmlssWriter::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 XmlssWriterAlignmentSettingsTests < XmlssWriterStyleSettingsTests
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 XmlssWriterFontSettingsTests < XmlssWriterStyleSettingsTests
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 XmlssWriterBgSettingsTests < XmlssWriterStyleSettingsTests
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 XmlssWriterBorderSettingsTests < XmlssWriterStyleSettingsTests
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 XmlssWriterParseSettingsTests < XmlssWriterStyleSettingsTests
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
- }, XmlssWriter::StyleSettings.new(@workbook.styles).value)
259
- end
260
- end
261
-
262
- end
263
-
@@ -1,334 +0,0 @@
1
- require "assert"
2
-
3
- require 'osheet/xmlss_writer'
4
-
5
- module Osheet
6
-
7
- class XmlssWriterStylesTest < Assert::Context
8
- before do
9
- @writer = XmlssWriter.new
10
- @workbook = 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 = XmlssWriter.new
16
- assert_nil writer.style_cache
17
- writer.bind(@workbook)
18
- assert_not_nil writer.style_cache
19
- end
20
-
21
- end
22
-
23
- class XmlssWriterStyleTests < XmlssWriterStylesTest
24
- desc "Xmlss style writer"
25
- before do
26
- @workbook.style('.font.size') { @workbook.font 14 }
27
- @workbook.style('.font.weight') { @workbook.font :bold }
28
- @workbook.style('.font.style') { @workbook.font :italic }
29
- @workbook.style('.align.center') { @workbook.align :center }
30
- end
31
-
32
- should "build a style obj and add it to the writers styles" do
33
- xmlss_style = subject.style('awesome')
34
- assert_kind_of ::Xmlss::Style::Base, xmlss_style
35
- assert_equal '.awesome', xmlss_style.id
36
- assert_equal 1, subject.style_cache.size
37
- assert_equal xmlss_style, subject.style_cache[xmlss_style.id]
38
- end
39
-
40
- should "write style markup from many matching osheet styles" do
41
- xmlss_style = subject.style('font size weight style align center')
42
- assert_equal '.font.size.weight.style.align.center', xmlss_style.id
43
- end
44
-
45
- end
46
-
47
- class XmlssWriterAlignmentTests < XmlssWriterStylesTest
48
- desc "Alignment style writer"
49
- before do
50
- [ :left, :center, :right,
51
- :top, :middle, :bottom,
52
- :wrap
53
- ].each do |s|
54
- @workbook.style(".align.#{s}") { @workbook.align s }
55
- end
56
- @workbook.style('.align.rotate') { @workbook.align 90 }
57
- end
58
-
59
- should "write style markup with no alignment settings if no alignment style match" do
60
- subject.style('align')
61
- assert_equal(
62
- "<Style ss:ID=\".align\"><NumberFormat /></Style>",
63
- xmlss_style_markup(subject)
64
- )
65
- end
66
-
67
- should "write style markup for horizontal alignment settings" do
68
- subject.style('align left')
69
- subject.style('align center')
70
- subject.style('align right')
71
- assert_equal(
72
- "<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>",
73
- xmlss_style_markup(subject)
74
- )
75
- end
76
-
77
- should "write style markup for vertical alignment settings" do
78
- subject.style('align top')
79
- subject.style('align middle')
80
- subject.style('align bottom')
81
- assert_equal(
82
- "<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>",
83
- xmlss_style_markup(subject)
84
- )
85
- end
86
-
87
- should "write style markup for text wrap settings" do
88
- subject.style('align wrap')
89
- assert_equal(
90
- "<Style ss:ID=\".align.wrap\"><Alignment ss:WrapText=\"1\" /><NumberFormat /></Style>",
91
- xmlss_style_markup(subject)
92
- )
93
- end
94
-
95
- should "write style markup for text rotation settings" do
96
- subject.style('align rotate')
97
- assert_equal(
98
- "<Style ss:ID=\".align.rotate\"><Alignment ss:Rotate=\"90\" /><NumberFormat /></Style>",
99
- xmlss_style_markup(subject)
100
- )
101
- end
102
-
103
- end
104
-
105
- class XmlssWriterFontTests < XmlssWriterStylesTest
106
- desc "Font style writer"
107
- before do
108
- [ :underline, :double_underline, :accounting_underline, :double_accounting_underline,
109
- :subscript, :superscript, :shadow, :strikethrough, :wrap,
110
- :bold, :italic
111
- ].each do |s|
112
- @workbook.style(".font.#{s}") { @workbook.font s }
113
- end
114
- @workbook.style('.font.size') { @workbook.font 14 }
115
- @workbook.style('.font.color') { @workbook.font '#FF0000' }
116
- @workbook.style('.font.name') { @workbook.font 'Verdana' }
117
- end
118
-
119
- should "write style markup with empty font settings if no match" do
120
- subject.style('font')
121
- assert_equal(
122
- "<Style ss:ID=\".font\"><NumberFormat /></Style>",
123
- xmlss_style_markup(subject)
124
- )
125
- end
126
-
127
- should "write style markup for font underline settings" do
128
- subject.style('font underline')
129
- subject.style('font double_underline')
130
- subject.style('font accounting_underline')
131
- subject.style('font double_accounting_underline')
132
- assert_equal(
133
- "<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>",
134
- xmlss_style_markup(subject)
135
- )
136
-
137
- end
138
-
139
- should "write style markup for font alignment settings" do
140
- subject.style('font subscript')
141
- subject.style('font superscript')
142
- assert_equal(
143
- "<Style ss:ID=\".font.subscript\"><Font ss:VerticalAlign=\"Subscript\" /><NumberFormat /></Style><Style ss:ID=\".font.superscript\"><Font ss:VerticalAlign=\"Superscript\" /><NumberFormat /></Style>",
144
- xmlss_style_markup(subject)
145
- )
146
- end
147
-
148
- should "write style markup for font style settings" do
149
- subject.style('font bold')
150
- subject.style('font italic')
151
- subject.style('font strikethrough')
152
- subject.style('font shadow')
153
- assert_equal(
154
- "<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>",
155
- xmlss_style_markup(subject)
156
- )
157
- end
158
-
159
- should "write style markup for font size" do
160
- subject.style('font size')
161
- assert_equal(
162
- "<Style ss:ID=\".font.size\"><Font ss:Size=\"14\" /><NumberFormat /></Style>",
163
- xmlss_style_markup(subject)
164
- )
165
- end
166
-
167
- should "write style markup for font color" do
168
- subject.style('font color')
169
- assert_equal(
170
- "<Style ss:ID=\".font.color\"><Font ss:Color=\"#FF0000\" /><NumberFormat /></Style>",
171
- xmlss_style_markup(subject)
172
- )
173
- end
174
-
175
- should "write style markup for font name" do
176
- subject.style('font name')
177
- assert_equal(
178
- "<Style ss:ID=\".font.name\"><Font ss:FontName=\"Verdana\" /><NumberFormat /></Style>",
179
- xmlss_style_markup(subject)
180
- )
181
- end
182
-
183
- end
184
-
185
- class XmlssWriterBgTests < XmlssWriterStylesTest
186
- desc "Bg writer"
187
- before do
188
- @workbook.style('.bg.color') { @workbook.bg '#FF0000' }
189
- @workbook.style('.bg.pattern-only') { @workbook.bg :solid }
190
- @workbook.style('.bg.pattern-color') { @workbook.bg :horz_stripe => '#0000FF' }
191
- @workbook.style('.bg.color-first') { @workbook.bg '#00FF00', {:horz_stripe => '#0000FF'} }
192
- @workbook.style('.bg.pattern-first') { @workbook.bg({:horz_stripe => '#0000FF'}, '#00FF00') }
193
- end
194
-
195
- should "write style markup with empty bg settings when no match" do
196
- subject.style('bg')
197
- assert_equal(
198
- "<Style ss:ID=\".bg\"><NumberFormat /></Style>",
199
- xmlss_style_markup(subject)
200
- )
201
- end
202
-
203
- should "write style markup for bg color and auto set the pattern to solid" do
204
- subject.style('bg color')
205
- assert_equal(
206
- "<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
207
- xmlss_style_markup(subject)
208
- )
209
- end
210
-
211
- should "write style markup for bg pattern settings" do
212
- subject.style('bg pattern-only')
213
- subject.style('bg pattern-only')
214
- subject.style('bg pattern-color')
215
- subject.style('bg pattern-color')
216
- assert_equal(
217
- "<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>",
218
- xmlss_style_markup(subject)
219
- )
220
- end
221
-
222
- should "write style markup setting pattern to solid when setting bg color" do
223
- subject.style('bg color')
224
- assert_equal(
225
- "<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
226
- xmlss_style_markup(subject)
227
- )
228
- end
229
-
230
- should "write style markup setting pattern to pattern setting when first setting bg color then pattern" do
231
- subject.style('bg color-first')
232
- assert_equal(
233
- "<Style ss:ID=\".bg.color-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
234
- xmlss_style_markup(subject)
235
- )
236
- end
237
-
238
- should "write style markup setting pattern to pattern setting when first setting bg pattern then color" do
239
- subject.style('bg pattern-first')
240
- assert_equal(
241
- "<Style ss:ID=\".bg.pattern-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
242
- xmlss_style_markup(subject)
243
- )
244
- end
245
-
246
- end
247
-
248
- class XmlssWriterBorderTests < XmlssWriterStylesTest
249
- desc "Font border writer"
250
- before do
251
- ::Osheet::Style::BORDER_POSITIONS.each do |p|
252
- @workbook.style(".border.#{p}") { @workbook.send("border_#{p}", :thin) }
253
- end
254
- [:hairline, :thin, :medium, :thick].each do |w|
255
- @workbook.style(".border.#{w}") { @workbook.border_top w }
256
- end
257
- [:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
258
- @workbook.style(".border.#{s}") { @workbook.border_top s }
259
- end
260
- @workbook.style('.border.color') { @workbook.border_top '#FF0000' }
261
- @workbook.style('.border.all') { @workbook.border :thick, :dash, '#FF0000' }
262
- end
263
-
264
- should "write style markup with empty border settings when no match" do
265
- subject.style('border')
266
- assert_equal(
267
- "<Style ss:ID=\".border\"><NumberFormat /></Style>",
268
- xmlss_style_markup(subject)
269
- )
270
- end
271
-
272
- should "write style markup with identical settings for all positions when using 'border'" do
273
- subject.style('border all')
274
- assert_equal(
275
- "<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>",
276
- xmlss_style_markup(subject)
277
- )
278
- end
279
-
280
- should "write style markup for border specific positions" do
281
- ::Osheet::Style::BORDER_POSITIONS.each do |p|
282
- subject.style("border #{p}")
283
- end
284
- assert_equal(
285
- "<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>",
286
- xmlss_style_markup(subject)
287
- )
288
- end
289
-
290
- should "write style markup for border weight settings" do
291
- [:hairline, :thin, :medium, :thick].each do |w|
292
- subject.style("border #{w}")
293
- end
294
- assert_equal(
295
- "<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>",
296
- xmlss_style_markup(subject)
297
- )
298
- end
299
-
300
- should "write style markup for border style settings" do
301
- [:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
302
- subject.style("border #{s}")
303
- end
304
- assert_equal(
305
- "<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>",
306
- xmlss_style_markup(subject)
307
- )
308
- end
309
-
310
- should "write style markup for border color" do
311
- subject.style('border color')
312
- assert_equal(
313
- "<Style ss:ID=\".border.color\"><Borders><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
314
- xmlss_style_markup(subject)
315
- )
316
- end
317
-
318
- end
319
-
320
- class XmlssWriterNumberFormatTests < XmlssWriterStylesTest
321
- desc "Xmlss style number format writer"
322
-
323
- should "write style markup with formatting" do
324
- subject.style('', Osheet::Format.new(:text))
325
- subject.style('', Osheet::Format.new(:datetime, 'mm/dd/yy'))
326
- assert_equal(
327
- "<Style ss:ID=\"..text\"><NumberFormat ss:Format=\"@\" /></Style><Style ss:ID=\"..datetime_mm/dd/yy\"><NumberFormat ss:Format=\"mm/dd/yy\" /></Style>",
328
- xmlss_style_markup(subject)
329
- )
330
- end
331
-
332
- end
333
-
334
- end
@@ -1,91 +0,0 @@
1
- require "assert"
2
- require 'osheet/xmlss_writer'
3
-
4
- module Osheet
5
-
6
- class XmlssWriterTest < Assert::Context
7
- desc "the xmlss writer"
8
- before do
9
- @writer = XmlssWriter.new
10
- @workbook = Workbook.new(@writer)
11
- end
12
- subject { @writer }
13
-
14
- should have_reader :style_cache, :xmlss_workbook
15
- should have_instance_methods :bind, :to_s, :to_data, :to_file
16
-
17
- should have_instance_methods :worksheet, :column, :row, :cell
18
- should have_instance_methods :style
19
- should have_instance_methods :name
20
- should have_instance_methods :width, :height
21
- should have_instance_methods :autofit, :autofit?, :hidden, :hidden?
22
- should have_instance_methods :data, :format, :href, :formula
23
- should have_instance_methods :index, :rowspan, :colspan
24
-
25
- end
26
-
27
- class XmlssWriterWorkbookTests < XmlssWriterTest
28
- before do
29
- @workbook.worksheet("testsheet1")
30
- end
31
-
32
- should "not allow multiple worksheets with the same name" do
33
- assert_raises ArgumentError do
34
- subject.worksheet(Worksheet.new("testsheet1"))
35
- end
36
- assert_nothing_raised do
37
- subject.worksheet(Worksheet.new("testsheet2"))
38
- subject.worksheet(Worksheet.new) {
39
- subject.name 'testsheet3'
40
- }
41
- subject.worksheet(Worksheet.new) {
42
- subject.name 'testsheet4'
43
- }
44
- end
45
- end
46
-
47
- end
48
-
49
- class XmlssWriterToFileTests < XmlssWriterTest
50
- desc "used with a workbook"
51
- before do
52
- Workbook.new(@writer) {
53
- title "written"
54
- worksheet {
55
- name "Test!"
56
- column
57
- row {
58
- cell {
59
- data 1
60
- format :number
61
- }
62
- }
63
- }
64
- }
65
- end
66
-
67
- should "write workbook markup" do
68
- assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"><Styles><Style ss:ID=\"..number_none_0_nocomma_black\"><NumberFormat ss:Format=\"0\" /></Style></Styles><Worksheet ss:Name=\"Test!\"><Table><Column /><Row><Cell ss:StyleID=\"..number_none_0_nocomma_black\"><Data ss:Type=\"Number\">1</Data></Cell></Row></Table></Worksheet></Workbook>", @writer.to_s
69
- end
70
-
71
- should "return string xml data" do
72
- xml_data = subject.to_s
73
- assert_kind_of ::String, xml_data
74
- assert_match /^<\?xml/, xml_data
75
- assert_equal xml_data, subject.to_data
76
- end
77
-
78
- should "write xml data to a file path" do
79
- path = subject.to_file("./tmp/base_test.xls")
80
- assert_kind_of ::String, path
81
- assert_equal './tmp/base_test.xls', path
82
- assert File.exists?(path)
83
-
84
- File.open(path) do |f|
85
- assert_equal subject.to_data, f.read
86
- end
87
- end
88
-
89
- end
90
-
91
- end