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_header.rb
CHANGED
@@ -1,87 +1,77 @@
|
|
1
|
-
################################################
|
2
|
-
# tc_header.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Row::Header 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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@th.
|
44
|
-
assert_equal(html,@th.html.gsub(/\s{2,}
|
45
|
-
end
|
46
|
-
|
47
|
-
def
|
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
|
-
assert_respond_to(Table::Row::Header,:end_tags=)
|
79
|
-
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = "foo" }
|
80
|
-
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = 1 }
|
81
|
-
assert_nothing_raised{ Table::Row::Header.end_tags = true }
|
82
|
-
end
|
83
|
-
|
84
|
-
def teardown
|
85
|
-
@th = nil
|
86
|
-
end
|
87
|
-
end
|
1
|
+
################################################
|
2
|
+
# tc_header.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Row::Header class
|
5
|
+
################################################
|
6
|
+
require "test/unit"
|
7
|
+
require "html/table"
|
8
|
+
include HTML
|
9
|
+
|
10
|
+
class TC_HTML_Table_Row_Header < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@th = Table::Row::Header.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic
|
16
|
+
html = "<th></th>"
|
17
|
+
assert_equal(html,@th.html.gsub(/\s+/,''))
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_constructor
|
21
|
+
assert_nothing_raised{ Table::Row::Header.new }
|
22
|
+
assert_nothing_raised{ Table::Row::Header.new("foo") }
|
23
|
+
assert_nothing_raised{ Table::Row::Header.new(1) }
|
24
|
+
assert_nothing_raised{ Table::Row::Header.new(%w/foo bar baz/) }
|
25
|
+
assert_nothing_raised{ Table::Row::Header.new([1,2,3]) }
|
26
|
+
assert_nothing_raised{ Table::Row::Header.new([[1,2,3],["foo","bar"]]) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_with_attributes
|
30
|
+
html = "<th align='left' colspan=3 nowrap></th>"
|
31
|
+
@th.align = 'left'
|
32
|
+
@th.colspan = 3
|
33
|
+
@th.nowrap = true
|
34
|
+
assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_configure_not_allowed
|
38
|
+
assert_raises(NoMethodError){ @th.configure }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_add_content
|
42
|
+
html = "<th>hello world</th>"
|
43
|
+
@th.content = "hello world"
|
44
|
+
assert_equal(html,@th.html.gsub(/\s{2,}/,''))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_add_multiple_content_items
|
48
|
+
html = "<th>hello world</th>"
|
49
|
+
@th.content = "hello"," world"
|
50
|
+
assert_equal(html,@th.html.gsub(/\s{2,}/,''))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_content_in_constructor
|
54
|
+
html = "<th>hello world</th>"
|
55
|
+
th = Table::Row::Header.new("hello world")
|
56
|
+
assert_equal(html,th.html.gsub(/\s{2,}/,''))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_indent_level
|
60
|
+
assert_respond_to(Table::Row::Header,:indent_level)
|
61
|
+
assert_respond_to(Table::Row::Header,:indent_level=)
|
62
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.indent_level = "foo" }
|
63
|
+
assert_nothing_raised{ Table::Row::Header.indent_level = 6 }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_end_tags
|
67
|
+
assert_respond_to(Table::Row::Header,:end_tags?)
|
68
|
+
assert_respond_to(Table::Row::Header,:end_tags=)
|
69
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = "foo" }
|
70
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = 1 }
|
71
|
+
assert_nothing_raised{ Table::Row::Header.end_tags = true }
|
72
|
+
end
|
73
|
+
|
74
|
+
def teardown
|
75
|
+
@th = nil
|
76
|
+
end
|
77
|
+
end
|
data/test/tc_html_handler.rb
CHANGED
@@ -1,47 +1,37 @@
|
|
1
|
-
############################################################################
|
2
|
-
# tc_html_handler.rb
|
3
|
-
#
|
4
|
-
# Test suite for the HtmlHandler 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
|
-
assert_nothing_raised{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert_nothing_raised{
|
39
|
-
@t.send(:modify_html,"align","top")
|
40
|
-
@t.send(:modify_html,"align","top")
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
def teardown
|
45
|
-
@t = nil
|
46
|
-
end
|
47
|
-
end
|
1
|
+
############################################################################
|
2
|
+
# tc_html_handler.rb
|
3
|
+
#
|
4
|
+
# Test suite for the HtmlHandler 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_HtmlHandler < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
@t = Table.new(["foo",1,"bar"])
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_html
|
17
|
+
assert_respond_to(@t, :html)
|
18
|
+
assert_nothing_raised{ @t.html }
|
19
|
+
assert_raises(NoMethodError){ @t.html = "foo" }
|
20
|
+
assert_kind_of(String,@t.html)
|
21
|
+
assert_equal(true,@t.html.length > 0)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_modify_html
|
25
|
+
assert_raises(ArgumentError){ @t.send(:modify_html) }
|
26
|
+
assert_nothing_raised{ @t.send(:modify_html,"nowrap") }
|
27
|
+
assert_nothing_raised{ @t.send(:modify_html,"align","top") }
|
28
|
+
assert_nothing_raised{
|
29
|
+
@t.send(:modify_html,"align","top")
|
30
|
+
@t.send(:modify_html,"align","top")
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
@t = nil
|
36
|
+
end
|
37
|
+
end
|
data/test/tc_row.rb
CHANGED
@@ -1,151 +1,141 @@
|
|
1
|
-
############################################
|
2
|
-
# tc_row.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Row 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
|
-
|
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
|
-
assert_nothing_raised{ @tr
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
def
|
60
|
-
assert_raises(ArgumentTypeError){ @tr
|
61
|
-
|
62
|
-
assert_nothing_raised{ @tr
|
63
|
-
assert_nothing_raised{ @tr.
|
64
|
-
assert_nothing_raised{ @tr
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
html
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
html
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
@tr.
|
112
|
-
@tr.
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
}
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
assert_respond_to(Table::Row,:end_tags=)
|
143
|
-
assert_raises(ArgumentTypeError){ Table::Row.end_tags = "foo" }
|
144
|
-
assert_raises(ArgumentTypeError){ Table::Row.end_tags = 1 }
|
145
|
-
assert_nothing_raised{ Table::Row.end_tags = true }
|
146
|
-
end
|
147
|
-
|
148
|
-
def teardown
|
149
|
-
@tr = nil
|
150
|
-
end
|
151
|
-
end
|
1
|
+
############################################
|
2
|
+
# tc_row.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Row class
|
5
|
+
############################################
|
6
|
+
require "test/unit"
|
7
|
+
require "html/table"
|
8
|
+
include HTML
|
9
|
+
|
10
|
+
class TC_HTML_Table_Row < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@tr = Table::Row.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_constructor
|
16
|
+
assert_nothing_raised{ Table::Row.new }
|
17
|
+
assert_nothing_raised{ Table::Row.new("foo") }
|
18
|
+
assert_nothing_raised{ Table::Row.new(1) }
|
19
|
+
assert_nothing_raised{ Table::Row.new([1,2,3]) }
|
20
|
+
assert_nothing_raised{ Table::Row.new([[1,2,3],["foo","bar"]]) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_basic
|
24
|
+
html = "<tr></tr>"
|
25
|
+
assert_equal(html,@tr.html.gsub(/\s+/,''))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_header
|
29
|
+
assert_respond_to(@tr, :header?)
|
30
|
+
assert_respond_to(@tr, :header=)
|
31
|
+
assert_nothing_raised{ @tr.header? }
|
32
|
+
assert_nothing_raised{ @tr.header = true }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_with_attributes
|
36
|
+
html = "<tr align='center'></tr>"
|
37
|
+
@tr.align = "center"
|
38
|
+
assert_equal(html,@tr.html.gsub(/\s{2,}|\n+/,''))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_index_assignment_constraints
|
42
|
+
assert_raises(ArgumentTypeError){ @tr[0] = "foo" }
|
43
|
+
assert_raises(ArgumentTypeError){ @tr[0] = 1 }
|
44
|
+
assert_raises(ArgumentTypeError){ @tr[0] = Table::Caption.new }
|
45
|
+
assert_nothing_raised{ @tr[0] = Table::Row::Data.new }
|
46
|
+
assert_nothing_raised{ @tr[0] = Table::Row::Header.new }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_push_constraints
|
50
|
+
assert_raises(ArgumentTypeError){ @tr.push(Table::Caption.new) }
|
51
|
+
assert_raises(ArgumentTypeError){ @tr.push(nil) }
|
52
|
+
assert_nothing_raised{ @tr.push("test") }
|
53
|
+
assert_nothing_raised{ @tr.push(7) }
|
54
|
+
assert_nothing_raised{ @tr.push(Table::Row::Data.new) }
|
55
|
+
assert_nothing_raised{ @tr.push(Table::Row::Header.new) }
|
56
|
+
end
|
57
|
+
|
58
|
+
# Test the '<<' method
|
59
|
+
def test_doubl_arrow_constraints
|
60
|
+
assert_raises(ArgumentTypeError){ @tr << Table::Caption.new }
|
61
|
+
assert_nothing_raised{ @tr << "test" }
|
62
|
+
assert_nothing_raised{ @tr << "test" << "foo" }
|
63
|
+
assert_nothing_raised{ @tr << Table::Row::Data.new }
|
64
|
+
assert_nothing_raised{ @tr << Table::Row::Header.new }
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_header_in_constructor
|
68
|
+
assert_nothing_raised{ @tr = Table::Row.new('test', true) }
|
69
|
+
html = "<tr><th>test</th></tr>"
|
70
|
+
assert_equal(html, @tr.html.gsub(/\s+/,''))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_push_single_data_element
|
74
|
+
html = "<tr><td>hello</td></tr>"
|
75
|
+
@tr.push Table::Row::Data.new{ |d| d.content = "hello" }
|
76
|
+
assert_equal(html,@tr.html.gsub(/\s{2,}|\n+/,''))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_push_multiple_data_element
|
80
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
81
|
+
d1 = Table::Row::Data.new{ |d| d.content = "hello" }
|
82
|
+
d2 = Table::Row::Data.new{ |d| d.content = "world" }
|
83
|
+
@tr.push d1, d2
|
84
|
+
assert_equal(html,@tr.html.gsub(/\s{2,}|\n+/,''))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_add_content_directly
|
88
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
89
|
+
@tr.content = "hello","world"
|
90
|
+
assert_equal(html,@tr.html.gsub(/\s{2,}|\n+/,''))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_add_content_in_constructor
|
94
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
95
|
+
tr = Table::Row.new(%w/hello world/)
|
96
|
+
assert_equal(html,tr.html.gsub(/\s{2,}|\n+/,''))
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_configure_column
|
100
|
+
html = "<tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr>"
|
101
|
+
@tr.content = "hello","world"
|
102
|
+
@tr.configure(1){ |d|
|
103
|
+
d.abbr = 'test'
|
104
|
+
d.width = 3
|
105
|
+
d.nowrap = true
|
106
|
+
}
|
107
|
+
assert_equal(html,@tr.html.gsub(/\s{2,}|\n+/,''))
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_unshift_constraints
|
111
|
+
assert_raises(ArgumentTypeError){ @tr.unshift(Table::Caption.new) }
|
112
|
+
assert_raises(ArgumentTypeError){ @tr.unshift(nil) }
|
113
|
+
assert_nothing_raised{ @tr.unshift("test") }
|
114
|
+
assert_nothing_raised{ @tr.unshift(7) }
|
115
|
+
assert_nothing_raised{ @tr.unshift(Table::Row::Data.new) }
|
116
|
+
assert_nothing_raised{ @tr.unshift(Table::Row::Header.new) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_configure_error
|
120
|
+
assert_raises(ArgumentError){ @tr.configure(0,0){ } }
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_indent_level
|
124
|
+
assert_respond_to(Table::Row,:indent_level)
|
125
|
+
assert_respond_to(Table::Row,:indent_level=)
|
126
|
+
assert_raises(ArgumentTypeError){ Table::Row.indent_level = "foo" }
|
127
|
+
assert_nothing_raised{ Table::Row.indent_level = 3 }
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_end_tags
|
131
|
+
assert_respond_to(Table::Row,:end_tags?)
|
132
|
+
assert_respond_to(Table::Row,:end_tags=)
|
133
|
+
assert_raises(ArgumentTypeError){ Table::Row.end_tags = "foo" }
|
134
|
+
assert_raises(ArgumentTypeError){ Table::Row.end_tags = 1 }
|
135
|
+
assert_nothing_raised{ Table::Row.end_tags = true }
|
136
|
+
end
|
137
|
+
|
138
|
+
def teardown
|
139
|
+
@tr = nil
|
140
|
+
end
|
141
|
+
end
|