html-table 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +3 -1
  3. data.tar.gz.sig +0 -0
  4. data/CHANGES +159 -155
  5. data/MANIFEST +59 -59
  6. data/README +132 -132
  7. data/certs/djberg96_pub.pem +22 -17
  8. data/doc/attributes.rdoc +143 -143
  9. data/doc/table.rdoc +158 -158
  10. data/doc/table_body.rdoc +9 -9
  11. data/doc/table_caption.rdoc +9 -9
  12. data/doc/table_colgroup.rdoc +8 -8
  13. data/doc/table_colgroup_col.rdoc +9 -9
  14. data/doc/table_content.rdoc +15 -15
  15. data/doc/table_foot.rdoc +8 -8
  16. data/doc/table_head.rdoc +11 -11
  17. data/doc/table_row.rdoc +105 -105
  18. data/doc/table_row_data.rdoc +92 -92
  19. data/doc/table_row_header.rdoc +7 -7
  20. data/examples/advanced.rb +128 -128
  21. data/examples/intermediate1.rb +72 -72
  22. data/examples/intermediate2.rb +62 -62
  23. data/examples/intermediate3.rb +46 -46
  24. data/examples/simple1.rb +39 -39
  25. data/examples/simple2.rb +47 -47
  26. data/examples/simple3.rb +41 -41
  27. data/html-table.gemspec +28 -28
  28. data/lib/html-table.rb +1 -1
  29. data/lib/html/attribute_handler.rb +403 -403
  30. data/lib/html/body.rb +37 -37
  31. data/lib/html/caption.rb +49 -49
  32. data/lib/html/col.rb +41 -41
  33. data/lib/html/colgroup.rb +113 -113
  34. data/lib/html/content.rb +18 -18
  35. data/lib/html/data.rb +69 -69
  36. data/lib/html/foot.rb +49 -49
  37. data/lib/html/head.rb +49 -49
  38. data/lib/html/header.rb +65 -65
  39. data/lib/html/html_handler.rb +120 -120
  40. data/lib/html/row.rb +188 -188
  41. data/lib/html/table.rb +323 -323
  42. data/lib/html/tablesection.rb +48 -48
  43. data/lib/html/tag_handler.rb +121 -121
  44. data/test/test_attribute_handler.rb +361 -361
  45. data/test/test_body.rb +87 -87
  46. data/test/test_caption.rb +80 -80
  47. data/test/test_col.rb +40 -40
  48. data/test/test_colgroup.rb +89 -89
  49. data/test/test_data.rb +77 -77
  50. data/test/test_foot.rb +111 -111
  51. data/test/test_head.rb +104 -104
  52. data/test/test_header.rb +77 -77
  53. data/test/test_html_handler.rb +37 -37
  54. data/test/test_row.rb +141 -141
  55. data/test/test_table.rb +159 -158
  56. data/test/test_tablesection.rb +42 -42
  57. data/test/test_tag_handler.rb +90 -90
  58. metadata +25 -20
  59. metadata.gz.sig +0 -0
@@ -1,48 +1,48 @@
1
- module HTML
2
- # Superclass for THEAD, TBODY, TFOOT
3
- #
4
- class Table::TableSection < Array
5
- include AttributeHandler
6
- include HtmlHandler
7
-
8
- def initialize(&block)
9
- instance_eval(&block) if block_given?
10
- end
11
-
12
- # Adds a Table::Row object as content. The +arg+ is passed as the value
13
- # to the Table::Row constructor.
14
- #
15
- def content=(arg)
16
- tr = Table::Row.new(arg)
17
- self.push(tr)
18
- end
19
-
20
- def self.indent_level
21
- @indent_level
22
- end
23
-
24
- def self.indent_level=(num)
25
- expect(num, Integer)
26
- raise ArgumentError, "indent_level must be >= 0" if num < 0
27
- @indent_level = num
28
- end
29
-
30
- def []=(index,obj)
31
- expect(obj,Table::Row)
32
- super
33
- end
34
-
35
- def push(*args)
36
- args.each{ |obj| expect(obj,Table::Row) }
37
- super
38
- end
39
-
40
- def unshift(obj)
41
- expect(obj,Table::Row)
42
- super
43
- end
44
-
45
- alias to_s html
46
- alias to_str html
47
- end
48
- end
1
+ module HTML
2
+ # Superclass for THEAD, TBODY, TFOOT
3
+ #
4
+ class Table::TableSection < Array
5
+ include AttributeHandler
6
+ include HtmlHandler
7
+
8
+ def initialize(&block)
9
+ instance_eval(&block) if block_given?
10
+ end
11
+
12
+ # Adds a Table::Row object as content. The +arg+ is passed as the value
13
+ # to the Table::Row constructor.
14
+ #
15
+ def content=(arg)
16
+ tr = Table::Row.new(arg)
17
+ self.push(tr)
18
+ end
19
+
20
+ def self.indent_level
21
+ @indent_level
22
+ end
23
+
24
+ def self.indent_level=(num)
25
+ expect(num, Integer)
26
+ raise ArgumentError, "indent_level must be >= 0" if num < 0
27
+ @indent_level = num
28
+ end
29
+
30
+ def []=(index,obj)
31
+ expect(obj,Table::Row)
32
+ super
33
+ end
34
+
35
+ def push(*args)
36
+ args.each{ |obj| expect(obj,Table::Row) }
37
+ super
38
+ end
39
+
40
+ def unshift(obj)
41
+ expect(obj,Table::Row)
42
+ super
43
+ end
44
+
45
+ alias to_s html
46
+ alias to_str html
47
+ end
48
+ end
@@ -1,121 +1,121 @@
1
- ###################################################################
2
- # tag_handler.rb
3
- #
4
- # Module for handling standard html physical tags (<b>, <i>, etc).
5
- # Only used for Table::Content objects, which are in turn used by
6
- # Table::Row::Data, Table::Row::Header and Table::Caption.
7
- ###################################################################
8
- module TagHandler
9
- def bold(bool = nil)
10
- @bold ||= nil
11
- self.bold = bool if bool
12
- @bold
13
- end
14
-
15
- def bold=(bool)
16
- handle_physical_tag('b', bool)
17
- @bold = bool
18
- end
19
-
20
- def big(bool = nil)
21
- @big ||= nil
22
- self.big = bool if bool
23
- @big
24
- end
25
-
26
- def big=(bool)
27
- handle_physical_tag('big', bool)
28
- @big = bool
29
- end
30
-
31
- def blink(bool = nil)
32
- @blink ||= nil
33
- self.blink = bool if bool
34
- @blink
35
- end
36
-
37
- def blink=(bool)
38
- warn BlinkWarning, "The 'blink' tag is very annoying. Please reconsider."
39
- handle_physical_tag('blink', bool)
40
- @blink = bool
41
- end
42
-
43
- def italic(bool = nil)
44
- @italic ||= nil
45
- self.italic = bool if bool
46
- @italic
47
- end
48
-
49
- def italic=(bool)
50
- handle_physical_tag('i', bool)
51
- @italic = bool
52
- end
53
-
54
- def strike(bool = nil)
55
- @strike ||= nil
56
- self.strike = bool if bool
57
- @strike
58
- end
59
-
60
- def strike=(bool)
61
- handle_physical_tag('strike', bool)
62
- @strike = bool
63
- end
64
-
65
- def sub(bool = nil)
66
- @sub ||= nil
67
- self.sub = bool if bool
68
- @sub
69
- end
70
-
71
- def sub=(bool)
72
- handle_physical_tag('sub', bool)
73
- @sub = bool
74
- end
75
-
76
- def sup(bool = nil)
77
- @sup ||= nil
78
- self.sup = bool if bool
79
- @sup
80
- end
81
-
82
- def sup=(bool)
83
- handle_physical_tag('sup', bool)
84
- @sup = bool
85
- end
86
-
87
- def tt(bool = nil)
88
- @tt ||= nil
89
- self.tt = bool if bool
90
- @tt
91
- end
92
-
93
- def tt=(bool)
94
- handle_physical_tag('tt', bool)
95
- @tt = bool
96
- end
97
-
98
- def underline(bool = nil)
99
- @underline ||= nil
100
- self.underline = bool if bool
101
- @underline
102
- end
103
-
104
- def underline=(bool)
105
- handle_physical_tag('u', bool)
106
- @bool = bool
107
- end
108
-
109
- private
110
-
111
- def handle_physical_tag(tag, bool)
112
- begin_tag = "<#{tag}>"
113
- end_tag = "</#{tag}>"
114
-
115
- if bool
116
- self.replace(begin_tag << self << end_tag)
117
- else
118
- self.replace(self.gsub(/#{begin_tag}|#{end_tag}/,''))
119
- end
120
- end
121
- end
1
+ ###################################################################
2
+ # tag_handler.rb
3
+ #
4
+ # Module for handling standard html physical tags (<b>, <i>, etc).
5
+ # Only used for Table::Content objects, which are in turn used by
6
+ # Table::Row::Data, Table::Row::Header and Table::Caption.
7
+ ###################################################################
8
+ module TagHandler
9
+ def bold(bool = nil)
10
+ @bold ||= nil
11
+ self.bold = bool if bool
12
+ @bold
13
+ end
14
+
15
+ def bold=(bool)
16
+ handle_physical_tag('b', bool)
17
+ @bold = bool
18
+ end
19
+
20
+ def big(bool = nil)
21
+ @big ||= nil
22
+ self.big = bool if bool
23
+ @big
24
+ end
25
+
26
+ def big=(bool)
27
+ handle_physical_tag('big', bool)
28
+ @big = bool
29
+ end
30
+
31
+ def blink(bool = nil)
32
+ @blink ||= nil
33
+ self.blink = bool if bool
34
+ @blink
35
+ end
36
+
37
+ def blink=(bool)
38
+ warn BlinkWarning, "The 'blink' tag is very annoying. Please reconsider."
39
+ handle_physical_tag('blink', bool)
40
+ @blink = bool
41
+ end
42
+
43
+ def italic(bool = nil)
44
+ @italic ||= nil
45
+ self.italic = bool if bool
46
+ @italic
47
+ end
48
+
49
+ def italic=(bool)
50
+ handle_physical_tag('i', bool)
51
+ @italic = bool
52
+ end
53
+
54
+ def strike(bool = nil)
55
+ @strike ||= nil
56
+ self.strike = bool if bool
57
+ @strike
58
+ end
59
+
60
+ def strike=(bool)
61
+ handle_physical_tag('strike', bool)
62
+ @strike = bool
63
+ end
64
+
65
+ def sub(bool = nil)
66
+ @sub ||= nil
67
+ self.sub = bool if bool
68
+ @sub
69
+ end
70
+
71
+ def sub=(bool)
72
+ handle_physical_tag('sub', bool)
73
+ @sub = bool
74
+ end
75
+
76
+ def sup(bool = nil)
77
+ @sup ||= nil
78
+ self.sup = bool if bool
79
+ @sup
80
+ end
81
+
82
+ def sup=(bool)
83
+ handle_physical_tag('sup', bool)
84
+ @sup = bool
85
+ end
86
+
87
+ def tt(bool = nil)
88
+ @tt ||= nil
89
+ self.tt = bool if bool
90
+ @tt
91
+ end
92
+
93
+ def tt=(bool)
94
+ handle_physical_tag('tt', bool)
95
+ @tt = bool
96
+ end
97
+
98
+ def underline(bool = nil)
99
+ @underline ||= nil
100
+ self.underline = bool if bool
101
+ @underline
102
+ end
103
+
104
+ def underline=(bool)
105
+ handle_physical_tag('u', bool)
106
+ @bool = bool
107
+ end
108
+
109
+ private
110
+
111
+ def handle_physical_tag(tag, bool)
112
+ begin_tag = "<#{tag}>"
113
+ end_tag = "</#{tag}>"
114
+
115
+ if bool
116
+ self.replace(begin_tag << self << end_tag)
117
+ else
118
+ self.replace(self.gsub(/#{begin_tag}|#{end_tag}/,''))
119
+ end
120
+ end
121
+ end
@@ -1,361 +1,361 @@
1
- ############################################################################
2
- # test_attribute_handler.rb
3
- #
4
- # Test suite for the AttributeHandler module. For these tests, we'll use an
5
- # instance of the Table class where the module has been mixed in.
6
- ############################################################################
7
- require 'test-unit'
8
- require 'html/table'
9
- include HTML
10
-
11
- class TC_AttributeHandler < Test::Unit::TestCase
12
- def self.startup
13
- NonStandardExtensionWarning.disable
14
- end
15
-
16
- def setup
17
- @table = Table.new(['foo',1,'bar'])
18
- end
19
-
20
- def test_abbr_basic
21
- assert_respond_to(@table, :abbr)
22
- assert_respond_to(@table, :abbr=)
23
- end
24
-
25
- def test_abbr
26
- assert_nothing_raised{ @table.abbr }
27
- assert_nil(@table.abbr)
28
- assert_nothing_raised{ @table.abbr = 'foo' }
29
- assert_equal('foo', @table.abbr)
30
- end
31
-
32
- def test_align_basic
33
- assert_respond_to(@table, :align)
34
- assert_respond_to(@table, :align=)
35
- end
36
-
37
- def test_align
38
- assert_nothing_raised{ @table.align }
39
- assert_nil(@table.align)
40
- assert_nothing_raised{ @table.align = 'center' }
41
- assert_equal('center', @table.align)
42
- end
43
-
44
- def test_align_expected_errors
45
- assert_raises(ArgumentError){ @table.align = 'foo' }
46
- end
47
-
48
- def test_axis
49
- assert_respond_to(@table, :axis)
50
- assert_respond_to(@table, :axis=)
51
- assert_nothing_raised{ @table.axis }
52
- assert_nothing_raised{ @table.axis = 'foo' }
53
- end
54
-
55
- def test_background_basic
56
- assert_respond_to(@table, :background)
57
- assert_respond_to(@table, :background=)
58
- end
59
-
60
- def test_background
61
- assert_nothing_raised{ @table.background }
62
- assert_nil(@table.background)
63
- assert_nothing_raised{ @table.background = 'foo' }
64
- assert_equal('foo', @table.background)
65
- end
66
-
67
- def test_background_expected_errors
68
- assert_raises(TypeError){ @table.background = 1 }
69
- end
70
-
71
- def test_bgcolor_basic
72
- assert_respond_to(@table, :bgcolor)
73
- assert_respond_to(@table, :bgcolor=)
74
- end
75
-
76
- def test_bgcolor
77
- assert_nothing_raised{ @table.bgcolor }
78
- assert_nil(@table.bgcolor)
79
- assert_nothing_raised{ @table.bgcolor = 'foo' }
80
- assert_equal('foo', @table.bgcolor)
81
- end
82
-
83
- def test_border_basic
84
- assert_respond_to(@table, :border)
85
- assert_respond_to(@table, :border=)
86
- end
87
-
88
- def test_border
89
- assert_nothing_raised{ @table.border }
90
- assert_nothing_raised{ @table.border = 2 }
91
- assert_nothing_raised{ @table.border = true }
92
- assert_nothing_raised{ @table.border = false }
93
- end
94
-
95
- def test_bordercolor_basic
96
- assert_respond_to(@table, :bordercolor)
97
- assert_respond_to(@table, :bordercolor=)
98
- end
99
-
100
- def test_bordercolor
101
- assert_nothing_raised{ @table.bordercolor }
102
- assert_nil(@table.bordercolor)
103
- assert_nothing_raised{ @table.bordercolor = 'foo' }
104
- assert_equal('foo', @table.bordercolor)
105
- end
106
-
107
- def test_bordercolordark_basic
108
- assert_respond_to(@table, :bordercolordark)
109
- assert_respond_to(@table, :bordercolordark=)
110
- end
111
-
112
- def test_bordercolordark
113
- assert_nothing_raised{ @table.bordercolordark }
114
- assert_nil(@table.bordercolordark)
115
- assert_nothing_raised{ @table.bordercolordark = 'foo' }
116
- assert_equal('foo', @table.bordercolordark)
117
- end
118
-
119
- def test_bordercolorlight
120
- assert_respond_to(@table, :bordercolorlight)
121
- assert_respond_to(@table, :bordercolorlight=)
122
- assert_nothing_raised{ @table.bordercolorlight }
123
- assert_nothing_raised{ @table.bordercolorlight = 'foo' }
124
- end
125
-
126
- def test_cellpadding
127
- assert_respond_to(@table, :cellpadding)
128
- assert_respond_to(@table, :cellpadding=)
129
- assert_nothing_raised{ @table.cellpadding }
130
- assert_nothing_raised{ @table.cellpadding = 1 }
131
- end
132
-
133
- def test_cellpadding_expected_errors
134
- assert_raises(ArgumentError){ @table.cellpadding = -1 }
135
- end
136
-
137
- def test_cellspacing
138
- assert_respond_to(@table, :cellspacing)
139
- assert_respond_to(@table, :cellspacing=)
140
- assert_nothing_raised{ @table.cellspacing }
141
- assert_nothing_raised{ @table.cellspacing = 1 }
142
- end
143
-
144
- def test_cellspacing_expected_errors
145
- assert_raises(ArgumentError){ @table.cellspacing = -1 }
146
- end
147
-
148
- def test_char
149
- assert_respond_to(@table, :char)
150
- assert_respond_to(@table, :char=)
151
- assert_nothing_raised{ @table.char }
152
- assert_nothing_raised{ @table.char = 'x' }
153
- end
154
-
155
- def test_char_expected_errors
156
- assert_raises(ArgumentError){ @table.char = 'xx' }
157
- end
158
-
159
- def test_charoff
160
- assert_respond_to(@table, :charoff)
161
- assert_respond_to(@table, :charoff=)
162
- assert_nothing_raised{ @table.charoff }
163
- assert_nothing_raised{ @table.charoff = 1 }
164
- end
165
-
166
- def test_charoff_expected_errors
167
- assert_raises(ArgumentError){ @table.charoff = -1 }
168
- end
169
-
170
- def test_class
171
- assert_respond_to(@table, :class_)
172
- assert_respond_to(@table, :class_=)
173
- assert_nothing_raised{ @table.class_ }
174
- assert_nothing_raised{ @table.class_ = 'myclass' }
175
- end
176
-
177
- def test_col
178
- assert_respond_to(@table, :col)
179
- assert_respond_to(@table, :col=)
180
- assert_nothing_raised{ @table.col }
181
- assert_nothing_raised{ @table.col = 1 }
182
- end
183
-
184
- def test_col_expected_errors
185
- assert_raises(ArgumentError){ @table.col = -1 }
186
- end
187
-
188
- def test_colspan
189
- assert_respond_to(@table, :colspan)
190
- assert_respond_to(@table, :colspan=)
191
- assert_nothing_raised{ @table.colspan }
192
- assert_nothing_raised{ @table.colspan = 1 }
193
- end
194
-
195
- def test_colspan_expected_errors
196
- assert_raises(ArgumentError){ @table.colspan = -1 }
197
- end
198
-
199
- def test_configure
200
- assert_respond_to(@table, :configure)
201
- assert_nothing_raised{ @table.configure(0){} }
202
- assert_nothing_raised{ @table.configure(0,0){} }
203
- end
204
-
205
- def test_configure_expected_errors
206
- assert_raises(ArgumentError){ @table.configure(0,0,0){} }
207
- end
208
-
209
- ########################################################################
210
- # This test could probably be broken out into separate tests for each
211
- # type that we want to add as content.
212
- ########################################################################
213
- def test_content
214
- assert_respond_to(@table, :content)
215
- assert_respond_to(@table, :content=)
216
- assert_nothing_raised{ @table.content = 'foo' }
217
- assert_nothing_raised{ @table.content = 123 }
218
- assert_nothing_raised{ @table.content = ['one',2,'three'] }
219
- assert_nothing_raised{ @table.content = [['foo','bar'],[1,2,3]] }
220
- assert_nothing_raised{ @table.content = Table::Row.new }
221
- assert_nothing_raised{ @table.content = Table::Row::Data.new }
222
- assert_nothing_raised{ @table.content = Table::Row::Header.new }
223
- assert_nothing_raised{ @table.content = Table::Head.create }
224
- assert_nothing_raised{ @table.content = Table::Foot.create }
225
- assert_nothing_raised{ @table.content = Table::Body.new }
226
- end
227
-
228
- def test_frame
229
- assert_respond_to(@table, :frame)
230
- assert_respond_to(@table, :frame=)
231
- assert_nothing_raised{ @table.frame }
232
- assert_nothing_raised{ @table.frame = 'below' }
233
- end
234
-
235
- def test_frame_expected_errors
236
- assert_raises(ArgumentError){ @table.frame = 'foo' }
237
- end
238
-
239
- def test_height
240
- assert_respond_to(@table, :height)
241
- assert_respond_to(@table, :height=)
242
- assert_nothing_raised{ @table.height }
243
- assert_nothing_raised{ @table.height = 1 }
244
- end
245
-
246
- def test_height_expected_errors
247
- assert_raises(ArgumentError){ @table.height = -1 }
248
- end
249
-
250
- def test_hspace
251
- assert_respond_to(@table, :hspace)
252
- assert_respond_to(@table, :hspace=)
253
- assert_nothing_raised{ @table.hspace }
254
- assert_nothing_raised{ @table.hspace = 1 }
255
- end
256
-
257
- def test_hspace_expected_errors
258
- assert_raises(ArgumentError){ @table.hspace = -1 }
259
- end
260
-
261
- def test_nowrap
262
- assert_respond_to(@table, :nowrap)
263
- assert_respond_to(@table, :nowrap=)
264
- assert_nothing_raised{ @table.nowrap }
265
- assert_nothing_raised{ @table.nowrap = false }
266
- end
267
-
268
- def test_nowrap_expected_errors
269
- assert_raises(TypeError){ @table.nowrap = 'foo' }
270
- end
271
-
272
- def test_rowspan
273
- assert_respond_to(@table, :rowspan)
274
- assert_respond_to(@table, :rowspan=)
275
- assert_nothing_raised{ @table.rowspan }
276
- assert_nothing_raised{ @table.rowspan = 1 }
277
- end
278
-
279
- def test_rowspan_expected_errors
280
- assert_raises(ArgumentError){ @table.rowspan = -1 }
281
- end
282
-
283
- def test_rules
284
- assert_respond_to(@table, :rules)
285
- assert_respond_to(@table, :rules=)
286
- assert_nothing_raised{ @table.rules }
287
- assert_nothing_raised{ @table.rules = 'all' }
288
- end
289
-
290
- def test_rules_expected_errors
291
- assert_raises(ArgumentError){ @table.rules = 'foo' }
292
- end
293
-
294
- def test_span
295
- assert_respond_to(@table, :span)
296
- assert_respond_to(@table, :span=)
297
- assert_nothing_raised{ @table.span }
298
- assert_nothing_raised{ @table.span = 1 }
299
- end
300
-
301
- def test_span_expected_errors
302
- assert_raises(ArgumentError){ @table.span = -1 }
303
- end
304
-
305
- def test_style
306
- assert_respond_to(@table, :style)
307
- assert_respond_to(@table, :style=)
308
- assert_nothing_raised{ @table.style }
309
- assert_nothing_raised{ @table.style = 'color: blue' }
310
- end
311
-
312
- def test_summary
313
- assert_respond_to(@table, :summary)
314
- assert_respond_to(@table, :summary=)
315
- assert_nothing_raised{ @table.summary }
316
- assert_nothing_raised{ @table.summary = 'foo' }
317
- assert_nothing_raised{ @table.summary = 1 }
318
- end
319
-
320
- def test_valign
321
- assert_respond_to(@table, :valign)
322
- assert_respond_to(@table, :valign=)
323
- assert_nothing_raised{ @table.valign }
324
- assert_nothing_raised{ @table.valign = 'center' }
325
- end
326
-
327
- def test_valign_expected_errors
328
- assert_raises(ArgumentError){ @table.valign = 'foo' }
329
- end
330
-
331
- def test_vspace
332
- assert_respond_to(@table, :vspace)
333
- assert_respond_to(@table, :vspace=)
334
- assert_nothing_raised{ @table.vspace }
335
- assert_nothing_raised{ @table.vspace = 1 }
336
- end
337
-
338
- def test_vspace_expected_errors
339
- assert_raises(ArgumentError){ @table.vspace = -1 }
340
- end
341
-
342
- def test_width
343
- assert_respond_to(@table, :width)
344
- assert_respond_to(@table, :width=)
345
- assert_nothing_raised{ @table.width}
346
- assert_nothing_raised{ @table.width = 10 }
347
- assert_nothing_raised{ @table.width = '5%' }
348
- end
349
-
350
- def test_width_expected_errors
351
- assert_raises(ArgumentError){ @table.width = -1 }
352
- end
353
-
354
- def teardown
355
- @table = nil
356
- end
357
-
358
- def self.shutdown
359
- NonStandardExtensionWarning.enable
360
- end
361
- end
1
+ ############################################################################
2
+ # test_attribute_handler.rb
3
+ #
4
+ # Test suite for the AttributeHandler module. For these tests, we'll use an
5
+ # instance of the Table class where the module has been mixed in.
6
+ ############################################################################
7
+ require 'test-unit'
8
+ require 'html/table'
9
+ include HTML
10
+
11
+ class TC_AttributeHandler < Test::Unit::TestCase
12
+ def self.startup
13
+ NonStandardExtensionWarning.disable
14
+ end
15
+
16
+ def setup
17
+ @table = Table.new(['foo',1,'bar'])
18
+ end
19
+
20
+ def test_abbr_basic
21
+ assert_respond_to(@table, :abbr)
22
+ assert_respond_to(@table, :abbr=)
23
+ end
24
+
25
+ def test_abbr
26
+ assert_nothing_raised{ @table.abbr }
27
+ assert_nil(@table.abbr)
28
+ assert_nothing_raised{ @table.abbr = 'foo' }
29
+ assert_equal('foo', @table.abbr)
30
+ end
31
+
32
+ def test_align_basic
33
+ assert_respond_to(@table, :align)
34
+ assert_respond_to(@table, :align=)
35
+ end
36
+
37
+ def test_align
38
+ assert_nothing_raised{ @table.align }
39
+ assert_nil(@table.align)
40
+ assert_nothing_raised{ @table.align = 'center' }
41
+ assert_equal('center', @table.align)
42
+ end
43
+
44
+ def test_align_expected_errors
45
+ assert_raises(ArgumentError){ @table.align = 'foo' }
46
+ end
47
+
48
+ def test_axis
49
+ assert_respond_to(@table, :axis)
50
+ assert_respond_to(@table, :axis=)
51
+ assert_nothing_raised{ @table.axis }
52
+ assert_nothing_raised{ @table.axis = 'foo' }
53
+ end
54
+
55
+ def test_background_basic
56
+ assert_respond_to(@table, :background)
57
+ assert_respond_to(@table, :background=)
58
+ end
59
+
60
+ def test_background
61
+ assert_nothing_raised{ @table.background }
62
+ assert_nil(@table.background)
63
+ assert_nothing_raised{ @table.background = 'foo' }
64
+ assert_equal('foo', @table.background)
65
+ end
66
+
67
+ def test_background_expected_errors
68
+ assert_raises(TypeError){ @table.background = 1 }
69
+ end
70
+
71
+ def test_bgcolor_basic
72
+ assert_respond_to(@table, :bgcolor)
73
+ assert_respond_to(@table, :bgcolor=)
74
+ end
75
+
76
+ def test_bgcolor
77
+ assert_nothing_raised{ @table.bgcolor }
78
+ assert_nil(@table.bgcolor)
79
+ assert_nothing_raised{ @table.bgcolor = 'foo' }
80
+ assert_equal('foo', @table.bgcolor)
81
+ end
82
+
83
+ def test_border_basic
84
+ assert_respond_to(@table, :border)
85
+ assert_respond_to(@table, :border=)
86
+ end
87
+
88
+ def test_border
89
+ assert_nothing_raised{ @table.border }
90
+ assert_nothing_raised{ @table.border = 2 }
91
+ assert_nothing_raised{ @table.border = true }
92
+ assert_nothing_raised{ @table.border = false }
93
+ end
94
+
95
+ def test_bordercolor_basic
96
+ assert_respond_to(@table, :bordercolor)
97
+ assert_respond_to(@table, :bordercolor=)
98
+ end
99
+
100
+ def test_bordercolor
101
+ assert_nothing_raised{ @table.bordercolor }
102
+ assert_nil(@table.bordercolor)
103
+ assert_nothing_raised{ @table.bordercolor = 'foo' }
104
+ assert_equal('foo', @table.bordercolor)
105
+ end
106
+
107
+ def test_bordercolordark_basic
108
+ assert_respond_to(@table, :bordercolordark)
109
+ assert_respond_to(@table, :bordercolordark=)
110
+ end
111
+
112
+ def test_bordercolordark
113
+ assert_nothing_raised{ @table.bordercolordark }
114
+ assert_nil(@table.bordercolordark)
115
+ assert_nothing_raised{ @table.bordercolordark = 'foo' }
116
+ assert_equal('foo', @table.bordercolordark)
117
+ end
118
+
119
+ def test_bordercolorlight
120
+ assert_respond_to(@table, :bordercolorlight)
121
+ assert_respond_to(@table, :bordercolorlight=)
122
+ assert_nothing_raised{ @table.bordercolorlight }
123
+ assert_nothing_raised{ @table.bordercolorlight = 'foo' }
124
+ end
125
+
126
+ def test_cellpadding
127
+ assert_respond_to(@table, :cellpadding)
128
+ assert_respond_to(@table, :cellpadding=)
129
+ assert_nothing_raised{ @table.cellpadding }
130
+ assert_nothing_raised{ @table.cellpadding = 1 }
131
+ end
132
+
133
+ def test_cellpadding_expected_errors
134
+ assert_raises(ArgumentError){ @table.cellpadding = -1 }
135
+ end
136
+
137
+ def test_cellspacing
138
+ assert_respond_to(@table, :cellspacing)
139
+ assert_respond_to(@table, :cellspacing=)
140
+ assert_nothing_raised{ @table.cellspacing }
141
+ assert_nothing_raised{ @table.cellspacing = 1 }
142
+ end
143
+
144
+ def test_cellspacing_expected_errors
145
+ assert_raises(ArgumentError){ @table.cellspacing = -1 }
146
+ end
147
+
148
+ def test_char
149
+ assert_respond_to(@table, :char)
150
+ assert_respond_to(@table, :char=)
151
+ assert_nothing_raised{ @table.char }
152
+ assert_nothing_raised{ @table.char = 'x' }
153
+ end
154
+
155
+ def test_char_expected_errors
156
+ assert_raises(ArgumentError){ @table.char = 'xx' }
157
+ end
158
+
159
+ def test_charoff
160
+ assert_respond_to(@table, :charoff)
161
+ assert_respond_to(@table, :charoff=)
162
+ assert_nothing_raised{ @table.charoff }
163
+ assert_nothing_raised{ @table.charoff = 1 }
164
+ end
165
+
166
+ def test_charoff_expected_errors
167
+ assert_raises(ArgumentError){ @table.charoff = -1 }
168
+ end
169
+
170
+ def test_class
171
+ assert_respond_to(@table, :class_)
172
+ assert_respond_to(@table, :class_=)
173
+ assert_nothing_raised{ @table.class_ }
174
+ assert_nothing_raised{ @table.class_ = 'myclass' }
175
+ end
176
+
177
+ def test_col
178
+ assert_respond_to(@table, :col)
179
+ assert_respond_to(@table, :col=)
180
+ assert_nothing_raised{ @table.col }
181
+ assert_nothing_raised{ @table.col = 1 }
182
+ end
183
+
184
+ def test_col_expected_errors
185
+ assert_raises(ArgumentError){ @table.col = -1 }
186
+ end
187
+
188
+ def test_colspan
189
+ assert_respond_to(@table, :colspan)
190
+ assert_respond_to(@table, :colspan=)
191
+ assert_nothing_raised{ @table.colspan }
192
+ assert_nothing_raised{ @table.colspan = 1 }
193
+ end
194
+
195
+ def test_colspan_expected_errors
196
+ assert_raises(ArgumentError){ @table.colspan = -1 }
197
+ end
198
+
199
+ def test_configure
200
+ assert_respond_to(@table, :configure)
201
+ assert_nothing_raised{ @table.configure(0){} }
202
+ assert_nothing_raised{ @table.configure(0,0){} }
203
+ end
204
+
205
+ def test_configure_expected_errors
206
+ assert_raises(ArgumentError){ @table.configure(0,0,0){} }
207
+ end
208
+
209
+ ########################################################################
210
+ # This test could probably be broken out into separate tests for each
211
+ # type that we want to add as content.
212
+ ########################################################################
213
+ def test_content
214
+ assert_respond_to(@table, :content)
215
+ assert_respond_to(@table, :content=)
216
+ assert_nothing_raised{ @table.content = 'foo' }
217
+ assert_nothing_raised{ @table.content = 123 }
218
+ assert_nothing_raised{ @table.content = ['one',2,'three'] }
219
+ assert_nothing_raised{ @table.content = [['foo','bar'],[1,2,3]] }
220
+ assert_nothing_raised{ @table.content = Table::Row.new }
221
+ assert_nothing_raised{ @table.content = Table::Row::Data.new }
222
+ assert_nothing_raised{ @table.content = Table::Row::Header.new }
223
+ assert_nothing_raised{ @table.content = Table::Head.create }
224
+ assert_nothing_raised{ @table.content = Table::Foot.create }
225
+ assert_nothing_raised{ @table.content = Table::Body.new }
226
+ end
227
+
228
+ def test_frame
229
+ assert_respond_to(@table, :frame)
230
+ assert_respond_to(@table, :frame=)
231
+ assert_nothing_raised{ @table.frame }
232
+ assert_nothing_raised{ @table.frame = 'below' }
233
+ end
234
+
235
+ def test_frame_expected_errors
236
+ assert_raises(ArgumentError){ @table.frame = 'foo' }
237
+ end
238
+
239
+ def test_height
240
+ assert_respond_to(@table, :height)
241
+ assert_respond_to(@table, :height=)
242
+ assert_nothing_raised{ @table.height }
243
+ assert_nothing_raised{ @table.height = 1 }
244
+ end
245
+
246
+ def test_height_expected_errors
247
+ assert_raises(ArgumentError){ @table.height = -1 }
248
+ end
249
+
250
+ def test_hspace
251
+ assert_respond_to(@table, :hspace)
252
+ assert_respond_to(@table, :hspace=)
253
+ assert_nothing_raised{ @table.hspace }
254
+ assert_nothing_raised{ @table.hspace = 1 }
255
+ end
256
+
257
+ def test_hspace_expected_errors
258
+ assert_raises(ArgumentError){ @table.hspace = -1 }
259
+ end
260
+
261
+ def test_nowrap
262
+ assert_respond_to(@table, :nowrap)
263
+ assert_respond_to(@table, :nowrap=)
264
+ assert_nothing_raised{ @table.nowrap }
265
+ assert_nothing_raised{ @table.nowrap = false }
266
+ end
267
+
268
+ def test_nowrap_expected_errors
269
+ assert_raises(TypeError){ @table.nowrap = 'foo' }
270
+ end
271
+
272
+ def test_rowspan
273
+ assert_respond_to(@table, :rowspan)
274
+ assert_respond_to(@table, :rowspan=)
275
+ assert_nothing_raised{ @table.rowspan }
276
+ assert_nothing_raised{ @table.rowspan = 1 }
277
+ end
278
+
279
+ def test_rowspan_expected_errors
280
+ assert_raises(ArgumentError){ @table.rowspan = -1 }
281
+ end
282
+
283
+ def test_rules
284
+ assert_respond_to(@table, :rules)
285
+ assert_respond_to(@table, :rules=)
286
+ assert_nothing_raised{ @table.rules }
287
+ assert_nothing_raised{ @table.rules = 'all' }
288
+ end
289
+
290
+ def test_rules_expected_errors
291
+ assert_raises(ArgumentError){ @table.rules = 'foo' }
292
+ end
293
+
294
+ def test_span
295
+ assert_respond_to(@table, :span)
296
+ assert_respond_to(@table, :span=)
297
+ assert_nothing_raised{ @table.span }
298
+ assert_nothing_raised{ @table.span = 1 }
299
+ end
300
+
301
+ def test_span_expected_errors
302
+ assert_raises(ArgumentError){ @table.span = -1 }
303
+ end
304
+
305
+ def test_style
306
+ assert_respond_to(@table, :style)
307
+ assert_respond_to(@table, :style=)
308
+ assert_nothing_raised{ @table.style }
309
+ assert_nothing_raised{ @table.style = 'color: blue' }
310
+ end
311
+
312
+ def test_summary
313
+ assert_respond_to(@table, :summary)
314
+ assert_respond_to(@table, :summary=)
315
+ assert_nothing_raised{ @table.summary }
316
+ assert_nothing_raised{ @table.summary = 'foo' }
317
+ assert_nothing_raised{ @table.summary = 1 }
318
+ end
319
+
320
+ def test_valign
321
+ assert_respond_to(@table, :valign)
322
+ assert_respond_to(@table, :valign=)
323
+ assert_nothing_raised{ @table.valign }
324
+ assert_nothing_raised{ @table.valign = 'center' }
325
+ end
326
+
327
+ def test_valign_expected_errors
328
+ assert_raises(ArgumentError){ @table.valign = 'foo' }
329
+ end
330
+
331
+ def test_vspace
332
+ assert_respond_to(@table, :vspace)
333
+ assert_respond_to(@table, :vspace=)
334
+ assert_nothing_raised{ @table.vspace }
335
+ assert_nothing_raised{ @table.vspace = 1 }
336
+ end
337
+
338
+ def test_vspace_expected_errors
339
+ assert_raises(ArgumentError){ @table.vspace = -1 }
340
+ end
341
+
342
+ def test_width
343
+ assert_respond_to(@table, :width)
344
+ assert_respond_to(@table, :width=)
345
+ assert_nothing_raised{ @table.width}
346
+ assert_nothing_raised{ @table.width = 10 }
347
+ assert_nothing_raised{ @table.width = '5%' }
348
+ end
349
+
350
+ def test_width_expected_errors
351
+ assert_raises(ArgumentError){ @table.width = -1 }
352
+ end
353
+
354
+ def teardown
355
+ @table = nil
356
+ end
357
+
358
+ def self.shutdown
359
+ NonStandardExtensionWarning.enable
360
+ end
361
+ end