html-table 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -1
- data/MANIFEST +0 -1
- data/Rakefile +24 -24
- data/doc/table_content.rdoc +15 -15
- data/html-table-1.3.2.gem +0 -0
- data/html-table.gemspec +25 -0
- data/lib/html/attribute_handler.rb +411 -411
- data/lib/html/body.rb +38 -38
- data/lib/html/caption.rb +48 -46
- data/lib/html/col.rb +41 -38
- data/lib/html/colgroup.rb +113 -110
- data/lib/html/content.rb +18 -18
- data/lib/html/data.rb +68 -65
- data/lib/html/foot.rb +49 -49
- data/lib/html/head.rb +49 -49
- data/lib/html/header.rb +65 -65
- data/lib/html/html_handler.rb +120 -120
- data/lib/html/row.rb +188 -185
- data/lib/html/table.rb +311 -255
- data/lib/html/tablesection.rb +48 -45
- data/lib/html/tag_handler.rb +123 -123
- data/test/tc_attribute_handler.rb +263 -273
- data/test/tc_body.rb +87 -97
- data/test/tc_caption.rb +80 -90
- data/test/tc_col.rb +40 -50
- data/test/tc_colgroup.rb +89 -99
- data/test/tc_data.rb +77 -87
- data/test/tc_foot.rb +108 -118
- data/test/tc_head.rb +104 -114
- data/test/tc_header.rb +77 -87
- data/test/tc_html_handler.rb +37 -47
- data/test/tc_row.rb +141 -151
- data/test/tc_table.rb +154 -163
- data/test/tc_tablesection.rb +42 -52
- data/test/tc_tag_handler.rb +82 -92
- metadata +29 -10
- data/test/ts_all.rb +0 -24
data/test/tc_table.rb
CHANGED
@@ -1,163 +1,154 @@
|
|
1
|
-
|
2
|
-
# tc_table.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table class
|
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
|
-
end
|
30
|
-
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
assert_nothing_raised{ Table.
|
35
|
-
assert_nothing_raised{ Table.
|
36
|
-
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def
|
41
|
-
assert_respond_to(Table, :
|
42
|
-
assert_respond_to(Table, :
|
43
|
-
assert_nothing_raised{ Table.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
assert_nothing_raised{
|
53
|
-
assert_raises(
|
54
|
-
end
|
55
|
-
|
56
|
-
def
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
assert_raises(ArgumentError){ @t[
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
assert_raises(ArgumentTypeError){ @t
|
88
|
-
assert_raises(ArgumentTypeError){ @t
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
html
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
@t.
|
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
|
-
@t.
|
140
|
-
assert_equal(html
|
141
|
-
end
|
142
|
-
|
143
|
-
def
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
assert_nothing_raised{ Table.global_end_tags = false }
|
156
|
-
assert_nothing_raised{ Table.global_end_tags = true }
|
157
|
-
assert_raises(ArgumentTypeError){ Table.global_end_tags = "foo" }
|
158
|
-
end
|
159
|
-
|
160
|
-
def teardown
|
161
|
-
@t = nil
|
162
|
-
end
|
163
|
-
end
|
1
|
+
#######################################################################
|
2
|
+
# tc_table.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HTML::Table class. This test case should be run
|
5
|
+
# via the 'rake test' task.
|
6
|
+
#######################################################################
|
7
|
+
require 'test/unit'
|
8
|
+
require 'html/table'
|
9
|
+
require 'strongtyping'
|
10
|
+
include StrongTyping
|
11
|
+
include HTML
|
12
|
+
|
13
|
+
class TC_HTML_Table < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@t = Table.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_version
|
19
|
+
assert_equal('1.3.2', Table::VERSION)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_constructor
|
23
|
+
assert_nothing_raised{ Table.new }
|
24
|
+
assert_nothing_raised{ Table.new('foo') }
|
25
|
+
assert_nothing_raised{ Table.new(1) }
|
26
|
+
assert_nothing_raised{ Table.new(%w/foo bar baz/) }
|
27
|
+
assert_nothing_raised{ Table.new([1,2,3]) }
|
28
|
+
assert_nothing_raised{ Table.new([[1,2,3],['foo','bar']]) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_html_case
|
32
|
+
assert_respond_to(Table, :html_case)
|
33
|
+
assert_respond_to(Table, :html_case=)
|
34
|
+
assert_nothing_raised{ Table.html_case = 'upper' }
|
35
|
+
assert_nothing_raised{ Table.html_case = 'lower' }
|
36
|
+
assert_raises(ArgumentError){ Table.html_case = 'foo' }
|
37
|
+
assert_raises(ArgumentTypeError){ Table.html_case = 7 }
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_indent_level
|
41
|
+
assert_respond_to(Table, :indent_level)
|
42
|
+
assert_respond_to(Table, :indent_level=)
|
43
|
+
assert_nothing_raised{ Table.indent_level = 0 }
|
44
|
+
assert_raises(ArgumentTypeError){ Table.indent_level = 'foo' }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_index
|
48
|
+
assert_raises(ArgumentTypeError){ @t[0] = 'foo' }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_caption_index_constraints
|
52
|
+
assert_nothing_raised{ @t[0] = Table::Caption.new }
|
53
|
+
assert_raises(ArgumentError){ @t[1] = Table::Caption.new }
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_head_index_constraints
|
57
|
+
assert_nothing_raised{ @t[0] = Table::Head.create }
|
58
|
+
assert_raises(ArgumentError){ @t[1] = Table::Head.create }
|
59
|
+
assert_raises(ArgumentError){ @t[2] = Table::Head.create }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_foot_index_constraints
|
63
|
+
assert_nothing_raised{
|
64
|
+
@t[0] = Table::Caption.new
|
65
|
+
@t[-1] = Table::Foot.create
|
66
|
+
}
|
67
|
+
assert_raises(ArgumentError){ @t[0] = Table::Foot.create }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_unshift_constraints
|
71
|
+
assert_nothing_raised{ @t.unshift Table::Row.new }
|
72
|
+
assert_raises(ArgumentTypeError){ @t.unshift Table::Row::Data.new }
|
73
|
+
assert_raises(ArgumentTypeError){ @t.unshift 'foo' }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_push_constraints
|
77
|
+
assert_nothing_raised{ @t.push Table::Row.new }
|
78
|
+
assert_raises(ArgumentTypeError){ @t.push('foo') }
|
79
|
+
assert_raises(ArgumentTypeError){ @t.push(7) }
|
80
|
+
assert_raises(ArgumentTypeError){ @t.push(nil) }
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_double_arrow_constraints
|
84
|
+
assert_nothing_raised{ @t << Table::Row.new }
|
85
|
+
assert_nothing_raised{ @t << Table::Row.new << Table::Row.new }
|
86
|
+
assert_raises(ArgumentTypeError){ @t << 'foo' }
|
87
|
+
assert_raises(ArgumentTypeError){ @t << 7 }
|
88
|
+
assert_raises(ArgumentTypeError){ @t << nil }
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_basic
|
92
|
+
html = "<table>\n</table>"
|
93
|
+
assert_equal(html, @t.html)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_with_attributes
|
97
|
+
html = "<table border=1 align='left' nowrap>\n</table>"
|
98
|
+
@t.border = 1
|
99
|
+
@t.align = 'left'
|
100
|
+
@t.nowrap = true
|
101
|
+
assert_equal(html, @t.html)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_add_row_push
|
105
|
+
html = '<table><tr></tr></table>'
|
106
|
+
@t.push(Table::Row.new)
|
107
|
+
assert_equal(html, @t.html.gsub(/\s+/,''))
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_add_row_by_index
|
111
|
+
html = '<table><tr></tr></table>'
|
112
|
+
@t[0] = Table::Row.new
|
113
|
+
assert_equal(html, @t.html.gsub(/\s+/,''))
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_add_multiple_rows
|
117
|
+
html = '<table><tr></tr><tr></tr></table>'
|
118
|
+
@t.push Table::Row.new, Table::Row.new
|
119
|
+
assert_equal(html, @t.html.gsub(/\s+/,''))
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_add_single_data_element
|
123
|
+
html = '<table><tr><td>hello</td></tr></table>'
|
124
|
+
@t.content = 'hello'
|
125
|
+
assert_equal(html, @t.html.gsub(/\s+/,''))
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_add_multiple_data_elements
|
129
|
+
html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
|
130
|
+
@t.content = 'hello','world'
|
131
|
+
assert_equal(html, @t.html.gsub(/\s+/,''))
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_configure_row
|
135
|
+
html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
|
136
|
+
html << '</table>'
|
137
|
+
@t.push Table::Row::Data.new{ |d| d.content = 'hello' }
|
138
|
+
@t.configure(0){ |t| t.align = 'center' }
|
139
|
+
@t.configure(0,0){ |d| d.bgcolor = 'red' }
|
140
|
+
assert_equal(html, @t.html.gsub(/\s{2,}|\n+/,''))
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_global_end_tags
|
144
|
+
assert_respond_to(Table,:global_end_tags?)
|
145
|
+
assert_respond_to(Table,:global_end_tags=)
|
146
|
+
assert_nothing_raised{ Table.global_end_tags = false }
|
147
|
+
assert_nothing_raised{ Table.global_end_tags = true }
|
148
|
+
assert_raises(ArgumentTypeError){ Table.global_end_tags = 'foo' }
|
149
|
+
end
|
150
|
+
|
151
|
+
def teardown
|
152
|
+
@t = nil
|
153
|
+
end
|
154
|
+
end
|
data/test/tc_tablesection.rb
CHANGED
@@ -1,52 +1,42 @@
|
|
1
|
-
################################################
|
2
|
-
# tc_tablesection.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::TableSection class
|
5
|
-
################################################
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
assert_raises(ArgumentTypeError){
|
30
|
-
assert_nothing_raised{ Table::
|
31
|
-
end
|
32
|
-
|
33
|
-
def
|
34
|
-
assert_raises(ArgumentTypeError){ @ts
|
35
|
-
assert_nothing_raised{ @ts
|
36
|
-
end
|
37
|
-
|
38
|
-
def
|
39
|
-
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_unshift
|
44
|
-
assert_raises(ArgumentTypeError){ @ts.unshift("foo") }
|
45
|
-
assert_nothing_raised{ @ts.unshift(Table::Row.new) }
|
46
|
-
end
|
47
|
-
|
48
|
-
def teardown
|
49
|
-
@t = nil
|
50
|
-
@ts = nil
|
51
|
-
end
|
52
|
-
end
|
1
|
+
################################################
|
2
|
+
# tc_tablesection.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::TableSection class
|
5
|
+
################################################
|
6
|
+
require "test/unit"
|
7
|
+
require "html/table"
|
8
|
+
include HTML
|
9
|
+
|
10
|
+
class TC_HTML_Table_TableSection < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@t = Table.new
|
13
|
+
@ts = Table::TableSection.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_indent_level
|
17
|
+
assert_respond_to(Table::Caption,:indent_level)
|
18
|
+
assert_respond_to(Table::Caption,:indent_level=)
|
19
|
+
assert_raises(ArgumentTypeError){ Table::Caption.indent_level = "foo" }
|
20
|
+
assert_nothing_raised{ Table::Caption.indent_level = 3 }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_indices
|
24
|
+
assert_raises(ArgumentTypeError){ @ts[0] = "foo" }
|
25
|
+
assert_nothing_raised{ @ts[0] = Table::Row.new }
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_push
|
29
|
+
assert_raises(ArgumentTypeError){ @ts.push("foo") }
|
30
|
+
assert_nothing_raised{ @ts.push(Table::Row.new) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_unshift
|
34
|
+
assert_raises(ArgumentTypeError){ @ts.unshift("foo") }
|
35
|
+
assert_nothing_raised{ @ts.unshift(Table::Row.new) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def teardown
|
39
|
+
@t = nil
|
40
|
+
@ts = nil
|
41
|
+
end
|
42
|
+
end
|
data/test/tc_tag_handler.rb
CHANGED
@@ -1,92 +1,82 @@
|
|
1
|
-
############################################################################
|
2
|
-
# tc_tag_handler.rb
|
3
|
-
#
|
4
|
-
# Test suite for the TagHandler module. For these tests, we'll use an
|
5
|
-
# instance of the Table class where the module has been mixed in.
|
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
|
-
assert_respond_to(@content, :underline)
|
84
|
-
assert_respond_to(@content, :underline)
|
85
|
-
assert_nothing_raised{ @content.underline }
|
86
|
-
assert_nothing_raised{ @content.underline = true }
|
87
|
-
end
|
88
|
-
|
89
|
-
def teardown
|
90
|
-
@content = nil
|
91
|
-
end
|
92
|
-
end
|
1
|
+
############################################################################
|
2
|
+
# tc_tag_handler.rb
|
3
|
+
#
|
4
|
+
# Test suite for the TagHandler 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_TagHandler < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@content = Table::Content.new('test')
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_bold
|
17
|
+
assert_respond_to(@content, :bold)
|
18
|
+
assert_respond_to(@content, :bold=)
|
19
|
+
assert_nothing_raised{ @content.bold }
|
20
|
+
assert_nothing_raised{ @content.bold = true }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_big
|
24
|
+
assert_respond_to(@content, :big)
|
25
|
+
assert_respond_to(@content, :big=)
|
26
|
+
assert_nothing_raised{ @content.big }
|
27
|
+
assert_nothing_raised{ @content.big = true }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_blink
|
31
|
+
assert_respond_to(@content, :blink)
|
32
|
+
assert_respond_to(@content, :blink=)
|
33
|
+
assert_nothing_raised{ @content.blink }
|
34
|
+
assert_nothing_raised{ @content.blink = true }
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_italic
|
38
|
+
assert_respond_to(@content, :italic)
|
39
|
+
assert_respond_to(@content, :italic=)
|
40
|
+
assert_nothing_raised{ @content.italic }
|
41
|
+
assert_nothing_raised{ @content.italic = true }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_strike
|
45
|
+
assert_respond_to(@content, :strike)
|
46
|
+
assert_respond_to(@content, :strike=)
|
47
|
+
assert_nothing_raised{ @content.strike }
|
48
|
+
assert_nothing_raised{ @content.strike = true }
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_sub
|
52
|
+
assert_respond_to(@content, :sub)
|
53
|
+
assert_respond_to(@content, :sub)
|
54
|
+
assert_nothing_raised{ @content.sub }
|
55
|
+
assert_nothing_raised{ @content.sub = true }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_sup
|
59
|
+
assert_respond_to(@content, :sup)
|
60
|
+
assert_respond_to(@content, :sup)
|
61
|
+
assert_nothing_raised{ @content.sup }
|
62
|
+
assert_nothing_raised{ @content.sup = true }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_tt
|
66
|
+
assert_respond_to(@content, :tt)
|
67
|
+
assert_respond_to(@content, :tt)
|
68
|
+
assert_nothing_raised{ @content.tt }
|
69
|
+
assert_nothing_raised{ @content.tt = true }
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_underline
|
73
|
+
assert_respond_to(@content, :underline)
|
74
|
+
assert_respond_to(@content, :underline)
|
75
|
+
assert_nothing_raised{ @content.underline }
|
76
|
+
assert_nothing_raised{ @content.underline = true }
|
77
|
+
end
|
78
|
+
|
79
|
+
def teardown
|
80
|
+
@content = nil
|
81
|
+
end
|
82
|
+
end
|