html-table 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +3 -1
- data.tar.gz.sig +0 -0
- data/CHANGES +159 -155
- data/MANIFEST +59 -59
- data/README +132 -132
- data/certs/djberg96_pub.pem +22 -17
- data/doc/attributes.rdoc +143 -143
- data/doc/table.rdoc +158 -158
- data/doc/table_body.rdoc +9 -9
- data/doc/table_caption.rdoc +9 -9
- data/doc/table_colgroup.rdoc +8 -8
- data/doc/table_colgroup_col.rdoc +9 -9
- data/doc/table_content.rdoc +15 -15
- data/doc/table_foot.rdoc +8 -8
- data/doc/table_head.rdoc +11 -11
- data/doc/table_row.rdoc +105 -105
- data/doc/table_row_data.rdoc +92 -92
- data/doc/table_row_header.rdoc +7 -7
- data/examples/advanced.rb +128 -128
- data/examples/intermediate1.rb +72 -72
- data/examples/intermediate2.rb +62 -62
- data/examples/intermediate3.rb +46 -46
- data/examples/simple1.rb +39 -39
- data/examples/simple2.rb +47 -47
- data/examples/simple3.rb +41 -41
- data/html-table.gemspec +28 -28
- data/lib/html-table.rb +1 -1
- data/lib/html/attribute_handler.rb +403 -403
- data/lib/html/body.rb +37 -37
- data/lib/html/caption.rb +49 -49
- data/lib/html/col.rb +41 -41
- data/lib/html/colgroup.rb +113 -113
- data/lib/html/content.rb +18 -18
- data/lib/html/data.rb +69 -69
- 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 -188
- data/lib/html/table.rb +323 -323
- data/lib/html/tablesection.rb +48 -48
- data/lib/html/tag_handler.rb +121 -121
- data/test/test_attribute_handler.rb +361 -361
- data/test/test_body.rb +87 -87
- data/test/test_caption.rb +80 -80
- data/test/test_col.rb +40 -40
- data/test/test_colgroup.rb +89 -89
- data/test/test_data.rb +77 -77
- data/test/test_foot.rb +111 -111
- data/test/test_head.rb +104 -104
- data/test/test_header.rb +77 -77
- data/test/test_html_handler.rb +37 -37
- data/test/test_row.rb +141 -141
- data/test/test_table.rb +159 -158
- data/test/test_tablesection.rb +42 -42
- data/test/test_tag_handler.rb +90 -90
- metadata +25 -20
- metadata.gz.sig +0 -0
data/test/test_data.rb
CHANGED
@@ -1,77 +1,77 @@
|
|
1
|
-
##############################################
|
2
|
-
# test_data.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Row::Data class
|
5
|
-
##############################################
|
6
|
-
require 'test-unit'
|
7
|
-
require 'html/table'
|
8
|
-
include HTML
|
9
|
-
|
10
|
-
class TC_HTML_Table_Row_Data < Test::Unit::TestCase
|
11
|
-
def setup
|
12
|
-
@tdata = Table::Row::Data.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_constructor
|
16
|
-
assert_nothing_raised{ Table::Row::Data.new }
|
17
|
-
assert_nothing_raised{ Table::Row::Data.new("foo") }
|
18
|
-
assert_nothing_raised{ Table::Row::Data.new(1) }
|
19
|
-
assert_nothing_raised{ Table::Row::Data.new(%w/foo bar baz/) }
|
20
|
-
assert_nothing_raised{ Table::Row::Data.new([1,2,3]) }
|
21
|
-
assert_nothing_raised{ Table::Row::Data.new([[1,2,3],["foo","bar"]]) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_basic
|
25
|
-
html = "<td></td>"
|
26
|
-
assert_equal(html,@tdata.html.gsub(/\s+/,''))
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_with_attributes
|
30
|
-
html = "<td align='left' width=3 nowrap></td>"
|
31
|
-
@tdata.align = 'left'
|
32
|
-
@tdata.width = 3
|
33
|
-
@tdata.nowrap = true
|
34
|
-
assert_equal(html,@tdata.html.gsub(/\s{2,}|\n+/,''))
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_configure_not_allowed
|
38
|
-
assert_raises(NoMethodError){ @tdata.configure }
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_add_content
|
42
|
-
html = "<td>hello world</td>"
|
43
|
-
@tdata.content = "hello world"
|
44
|
-
assert_equal(html,@tdata.html.gsub(/\s{2,}/,''))
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_add_content_in_constructor
|
48
|
-
html = "<td>hello world</td>"
|
49
|
-
td = Table::Row::Data.new("hello world")
|
50
|
-
assert_equal(html,td.html.gsub(/\s{2,}/,''))
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_add_multiple_content_items
|
54
|
-
html = "<td>hello world</td>"
|
55
|
-
@tdata.content = "hello"," world"
|
56
|
-
assert_equal(html,@tdata.html.gsub(/\s{2,}/,''))
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_indent_level
|
60
|
-
assert_respond_to(Table::Row::Data,:indent_level)
|
61
|
-
assert_respond_to(Table::Row::Data,:indent_level=)
|
62
|
-
assert_raises(ArgumentTypeError){ Table::Row::Data.indent_level = "foo" }
|
63
|
-
assert_nothing_raised{ Table::Row::Data.indent_level = 6 }
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_end_tags
|
67
|
-
assert_respond_to(Table::Row::Data,:end_tags?)
|
68
|
-
assert_respond_to(Table::Row::Data,:end_tags=)
|
69
|
-
assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = "foo" }
|
70
|
-
assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = 1 }
|
71
|
-
assert_nothing_raised{ Table::Row::Data.end_tags = true }
|
72
|
-
end
|
73
|
-
|
74
|
-
def teardown
|
75
|
-
@tdata = nil
|
76
|
-
end
|
77
|
-
end
|
1
|
+
##############################################
|
2
|
+
# test_data.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Row::Data class
|
5
|
+
##############################################
|
6
|
+
require 'test-unit'
|
7
|
+
require 'html/table'
|
8
|
+
include HTML
|
9
|
+
|
10
|
+
class TC_HTML_Table_Row_Data < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
@tdata = Table::Row::Data.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_constructor
|
16
|
+
assert_nothing_raised{ Table::Row::Data.new }
|
17
|
+
assert_nothing_raised{ Table::Row::Data.new("foo") }
|
18
|
+
assert_nothing_raised{ Table::Row::Data.new(1) }
|
19
|
+
assert_nothing_raised{ Table::Row::Data.new(%w/foo bar baz/) }
|
20
|
+
assert_nothing_raised{ Table::Row::Data.new([1,2,3]) }
|
21
|
+
assert_nothing_raised{ Table::Row::Data.new([[1,2,3],["foo","bar"]]) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_basic
|
25
|
+
html = "<td></td>"
|
26
|
+
assert_equal(html,@tdata.html.gsub(/\s+/,''))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_with_attributes
|
30
|
+
html = "<td align='left' width=3 nowrap></td>"
|
31
|
+
@tdata.align = 'left'
|
32
|
+
@tdata.width = 3
|
33
|
+
@tdata.nowrap = true
|
34
|
+
assert_equal(html,@tdata.html.gsub(/\s{2,}|\n+/,''))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_configure_not_allowed
|
38
|
+
assert_raises(NoMethodError){ @tdata.configure }
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_add_content
|
42
|
+
html = "<td>hello world</td>"
|
43
|
+
@tdata.content = "hello world"
|
44
|
+
assert_equal(html,@tdata.html.gsub(/\s{2,}/,''))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_add_content_in_constructor
|
48
|
+
html = "<td>hello world</td>"
|
49
|
+
td = Table::Row::Data.new("hello world")
|
50
|
+
assert_equal(html,td.html.gsub(/\s{2,}/,''))
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_add_multiple_content_items
|
54
|
+
html = "<td>hello world</td>"
|
55
|
+
@tdata.content = "hello"," world"
|
56
|
+
assert_equal(html,@tdata.html.gsub(/\s{2,}/,''))
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_indent_level
|
60
|
+
assert_respond_to(Table::Row::Data,:indent_level)
|
61
|
+
assert_respond_to(Table::Row::Data,:indent_level=)
|
62
|
+
assert_raises(ArgumentTypeError){ Table::Row::Data.indent_level = "foo" }
|
63
|
+
assert_nothing_raised{ Table::Row::Data.indent_level = 6 }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_end_tags
|
67
|
+
assert_respond_to(Table::Row::Data,:end_tags?)
|
68
|
+
assert_respond_to(Table::Row::Data,:end_tags=)
|
69
|
+
assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = "foo" }
|
70
|
+
assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = 1 }
|
71
|
+
assert_nothing_raised{ Table::Row::Data.end_tags = true }
|
72
|
+
end
|
73
|
+
|
74
|
+
def teardown
|
75
|
+
@tdata = nil
|
76
|
+
end
|
77
|
+
end
|
data/test/test_foot.rb
CHANGED
@@ -1,111 +1,111 @@
|
|
1
|
-
###############################################################################
|
2
|
-
# test_foot.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Foot class. The Table::Foot class is a singleton
|
5
|
-
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
-
# is created between tests.
|
7
|
-
###############################################################################
|
8
|
-
require 'test-unit'
|
9
|
-
require 'html/table'
|
10
|
-
include HTML
|
11
|
-
|
12
|
-
#####################################################################
|
13
|
-
# Ensure that a fresh instance of Table::Foot is used between tests
|
14
|
-
# by calling 'refresh' in the 'teardown' method.
|
15
|
-
#####################################################################
|
16
|
-
class Table::Foot
|
17
|
-
private
|
18
|
-
def refresh
|
19
|
-
@@foot = nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class TC_HTML_Table_Foot < Test::Unit::TestCase
|
24
|
-
def setup
|
25
|
-
@table = Table.new
|
26
|
-
@tfoot = Table::Foot.create
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_new_not_allowed
|
30
|
-
assert_raises(NoMethodError){ Table::Foot.new }
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_constructor
|
34
|
-
assert_nothing_raised{ Table::Foot.create }
|
35
|
-
assert_nothing_raised{ Table::Foot.create("foo") }
|
36
|
-
assert_nothing_raised{ Table::Foot.create(1) }
|
37
|
-
assert_nothing_raised{ Table::Foot.create(%w/foo bar baz/) }
|
38
|
-
assert_nothing_raised{ Table::Foot.create([1,2,3]) }
|
39
|
-
assert_nothing_raised{ Table::Foot.create([[1,2,3], ["foo","bar"]]) }
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_basic
|
43
|
-
html = "<tfoot></tfoot>"
|
44
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_end_tags
|
48
|
-
assert_respond_to(Table::Foot, :end_tags?)
|
49
|
-
assert_respond_to(Table::Foot, :end_tags=)
|
50
|
-
assert_nothing_raised{ Table::Foot.end_tags? }
|
51
|
-
assert_nothing_raised{ Table::Foot.end_tags = true }
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_end_tags_expected_errors
|
55
|
-
assert_raises(StrongTyping::ArgumentTypeError){
|
56
|
-
Table::Foot.end_tags = "foo"
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_with_attributes
|
61
|
-
html = "<tfoot align='left' char='x'></tfoot>"
|
62
|
-
@tfoot.align = "left"
|
63
|
-
@tfoot.char = 'x'
|
64
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_push_single_row
|
68
|
-
html = "<tfoot><tr><td>test</td></tr></tfoot>"
|
69
|
-
@tfoot.push Table::Row.new{|r| r.content = "test"}
|
70
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_push_multiple_rows
|
74
|
-
html = "<tfoot><tr><td>test</td></tr><tr><td>foo</td></tr></tfoot>"
|
75
|
-
r1 = Table::Row.new{|r| r.content = "test"}
|
76
|
-
r2 = Table::Row.new{|r| r.content = "foo"}
|
77
|
-
@tfoot.push r1, r2
|
78
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_add_content_directly
|
82
|
-
html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
|
83
|
-
@tfoot.content = "hello","world"
|
84
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_add_content_in_constructor
|
88
|
-
html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
|
89
|
-
@tfoot.send(:refresh)
|
90
|
-
@tfoot = Table::Foot.create(["hello","world"])
|
91
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_configure_column
|
95
|
-
html = "<tfoot><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
96
|
-
html += "</td></tr></tfoot>"
|
97
|
-
@tfoot.content = "hello","world"
|
98
|
-
@tfoot.configure(0,1){ |data|
|
99
|
-
data.abbr = 'test'
|
100
|
-
data.width = 3
|
101
|
-
data.nowrap = true
|
102
|
-
}
|
103
|
-
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
104
|
-
end
|
105
|
-
|
106
|
-
def teardown
|
107
|
-
@table = nil
|
108
|
-
@tfoot.send(:refresh)
|
109
|
-
@tfoot = nil
|
110
|
-
end
|
111
|
-
end
|
1
|
+
###############################################################################
|
2
|
+
# test_foot.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Foot class. The Table::Foot class is a singleton
|
5
|
+
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
+
# is created between tests.
|
7
|
+
###############################################################################
|
8
|
+
require 'test-unit'
|
9
|
+
require 'html/table'
|
10
|
+
include HTML
|
11
|
+
|
12
|
+
#####################################################################
|
13
|
+
# Ensure that a fresh instance of Table::Foot is used between tests
|
14
|
+
# by calling 'refresh' in the 'teardown' method.
|
15
|
+
#####################################################################
|
16
|
+
class Table::Foot
|
17
|
+
private
|
18
|
+
def refresh
|
19
|
+
@@foot = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TC_HTML_Table_Foot < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
@table = Table.new
|
26
|
+
@tfoot = Table::Foot.create
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_new_not_allowed
|
30
|
+
assert_raises(NoMethodError){ Table::Foot.new }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_constructor
|
34
|
+
assert_nothing_raised{ Table::Foot.create }
|
35
|
+
assert_nothing_raised{ Table::Foot.create("foo") }
|
36
|
+
assert_nothing_raised{ Table::Foot.create(1) }
|
37
|
+
assert_nothing_raised{ Table::Foot.create(%w/foo bar baz/) }
|
38
|
+
assert_nothing_raised{ Table::Foot.create([1,2,3]) }
|
39
|
+
assert_nothing_raised{ Table::Foot.create([[1,2,3], ["foo","bar"]]) }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_basic
|
43
|
+
html = "<tfoot></tfoot>"
|
44
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_end_tags
|
48
|
+
assert_respond_to(Table::Foot, :end_tags?)
|
49
|
+
assert_respond_to(Table::Foot, :end_tags=)
|
50
|
+
assert_nothing_raised{ Table::Foot.end_tags? }
|
51
|
+
assert_nothing_raised{ Table::Foot.end_tags = true }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_end_tags_expected_errors
|
55
|
+
assert_raises(StrongTyping::ArgumentTypeError){
|
56
|
+
Table::Foot.end_tags = "foo"
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_with_attributes
|
61
|
+
html = "<tfoot align='left' char='x'></tfoot>"
|
62
|
+
@tfoot.align = "left"
|
63
|
+
@tfoot.char = 'x'
|
64
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_push_single_row
|
68
|
+
html = "<tfoot><tr><td>test</td></tr></tfoot>"
|
69
|
+
@tfoot.push Table::Row.new{|r| r.content = "test"}
|
70
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_push_multiple_rows
|
74
|
+
html = "<tfoot><tr><td>test</td></tr><tr><td>foo</td></tr></tfoot>"
|
75
|
+
r1 = Table::Row.new{|r| r.content = "test"}
|
76
|
+
r2 = Table::Row.new{|r| r.content = "foo"}
|
77
|
+
@tfoot.push r1, r2
|
78
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_add_content_directly
|
82
|
+
html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
|
83
|
+
@tfoot.content = "hello","world"
|
84
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_add_content_in_constructor
|
88
|
+
html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
|
89
|
+
@tfoot.send(:refresh)
|
90
|
+
@tfoot = Table::Foot.create(["hello","world"])
|
91
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_configure_column
|
95
|
+
html = "<tfoot><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
96
|
+
html += "</td></tr></tfoot>"
|
97
|
+
@tfoot.content = "hello","world"
|
98
|
+
@tfoot.configure(0,1){ |data|
|
99
|
+
data.abbr = 'test'
|
100
|
+
data.width = 3
|
101
|
+
data.nowrap = true
|
102
|
+
}
|
103
|
+
assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
|
104
|
+
end
|
105
|
+
|
106
|
+
def teardown
|
107
|
+
@table = nil
|
108
|
+
@tfoot.send(:refresh)
|
109
|
+
@tfoot = nil
|
110
|
+
end
|
111
|
+
end
|
data/test/test_head.rb
CHANGED
@@ -1,104 +1,104 @@
|
|
1
|
-
###############################################################################
|
2
|
-
# test_head.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Head class. The Table::Head class is a singleton
|
5
|
-
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
-
# is created between tests.
|
7
|
-
###############################################################################
|
8
|
-
require 'test-unit'
|
9
|
-
require 'html/table'
|
10
|
-
include HTML
|
11
|
-
|
12
|
-
#####################################################################
|
13
|
-
# Ensure that a fresh instance of Table::Head is used between tests
|
14
|
-
# by calling 'refresh' in the 'teardown' method.
|
15
|
-
#####################################################################
|
16
|
-
class Table::Head
|
17
|
-
private
|
18
|
-
def refresh
|
19
|
-
@@head = nil
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class TC_HTML_Table_Head < Test::Unit::TestCase
|
24
|
-
def setup
|
25
|
-
@table = Table.new
|
26
|
-
@thead = Table::Head.create
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_constructor
|
30
|
-
assert_nothing_raised{ Table::Head.create }
|
31
|
-
assert_nothing_raised{ Table::Head.create("foo") }
|
32
|
-
assert_nothing_raised{ Table::Head.create(1) }
|
33
|
-
assert_nothing_raised{ Table::Head.create(%w/foo bar baz/) }
|
34
|
-
assert_nothing_raised{ Table::Head.create([1,2,3]) }
|
35
|
-
assert_nothing_raised{ Table::Head.create([[1,2,3],["foo","bar"]]) }
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_basic
|
39
|
-
html = "<thead></thead>"
|
40
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_end_tags
|
44
|
-
assert_respond_to(Table::Head, :end_tags?)
|
45
|
-
assert_respond_to(Table::Head, :end_tags=)
|
46
|
-
assert_nothing_raised{ Table::Head.end_tags? }
|
47
|
-
assert_nothing_raised{ Table::Head.end_tags = true }
|
48
|
-
assert_raises(StrongTyping::ArgumentTypeError){
|
49
|
-
Table::Head.end_tags = "foo"
|
50
|
-
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def test_with_attributes
|
54
|
-
html = "<thead align='left' char='x'></thead>"
|
55
|
-
@thead.align = "left"
|
56
|
-
@thead.char = 'x'
|
57
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_push_single_row
|
61
|
-
html = "<thead><tr><td>test</td></tr></thead>"
|
62
|
-
@thead.push Table::Row.new{|r| r.content = "test"}
|
63
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_push_multiple_rows
|
67
|
-
html = "<thead><tr><td>test</td></tr><tr><td>foo</td></tr></thead>"
|
68
|
-
r1 = Table::Row.new("test")
|
69
|
-
r2 = Table::Row.new("foo")
|
70
|
-
@thead.push(r1, r2)
|
71
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_add_content_directly
|
75
|
-
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
76
|
-
@thead.content = "hello","world"
|
77
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_add_content_in_constructor
|
81
|
-
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
82
|
-
@thead.send(:refresh)
|
83
|
-
@thead = Table::Head.create(["hello","world"])
|
84
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_configure_column
|
88
|
-
html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
89
|
-
html += "</td></tr></thead>"
|
90
|
-
@thead.content = "hello","world"
|
91
|
-
@thead.configure(0,1){ |d|
|
92
|
-
d.abbr = 'test'
|
93
|
-
d.width = 3
|
94
|
-
d.nowrap = true
|
95
|
-
}
|
96
|
-
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
97
|
-
end
|
98
|
-
|
99
|
-
def teardown
|
100
|
-
@table = nil
|
101
|
-
@thead.send(:refresh)
|
102
|
-
@thead = nil
|
103
|
-
end
|
104
|
-
end
|
1
|
+
###############################################################################
|
2
|
+
# test_head.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Head class. The Table::Head class is a singleton
|
5
|
+
# class, so we have to take extra measures to ensure that a fresh instance
|
6
|
+
# is created between tests.
|
7
|
+
###############################################################################
|
8
|
+
require 'test-unit'
|
9
|
+
require 'html/table'
|
10
|
+
include HTML
|
11
|
+
|
12
|
+
#####################################################################
|
13
|
+
# Ensure that a fresh instance of Table::Head is used between tests
|
14
|
+
# by calling 'refresh' in the 'teardown' method.
|
15
|
+
#####################################################################
|
16
|
+
class Table::Head
|
17
|
+
private
|
18
|
+
def refresh
|
19
|
+
@@head = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class TC_HTML_Table_Head < Test::Unit::TestCase
|
24
|
+
def setup
|
25
|
+
@table = Table.new
|
26
|
+
@thead = Table::Head.create
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_constructor
|
30
|
+
assert_nothing_raised{ Table::Head.create }
|
31
|
+
assert_nothing_raised{ Table::Head.create("foo") }
|
32
|
+
assert_nothing_raised{ Table::Head.create(1) }
|
33
|
+
assert_nothing_raised{ Table::Head.create(%w/foo bar baz/) }
|
34
|
+
assert_nothing_raised{ Table::Head.create([1,2,3]) }
|
35
|
+
assert_nothing_raised{ Table::Head.create([[1,2,3],["foo","bar"]]) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_basic
|
39
|
+
html = "<thead></thead>"
|
40
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_end_tags
|
44
|
+
assert_respond_to(Table::Head, :end_tags?)
|
45
|
+
assert_respond_to(Table::Head, :end_tags=)
|
46
|
+
assert_nothing_raised{ Table::Head.end_tags? }
|
47
|
+
assert_nothing_raised{ Table::Head.end_tags = true }
|
48
|
+
assert_raises(StrongTyping::ArgumentTypeError){
|
49
|
+
Table::Head.end_tags = "foo"
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_with_attributes
|
54
|
+
html = "<thead align='left' char='x'></thead>"
|
55
|
+
@thead.align = "left"
|
56
|
+
@thead.char = 'x'
|
57
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_push_single_row
|
61
|
+
html = "<thead><tr><td>test</td></tr></thead>"
|
62
|
+
@thead.push Table::Row.new{|r| r.content = "test"}
|
63
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_push_multiple_rows
|
67
|
+
html = "<thead><tr><td>test</td></tr><tr><td>foo</td></tr></thead>"
|
68
|
+
r1 = Table::Row.new("test")
|
69
|
+
r2 = Table::Row.new("foo")
|
70
|
+
@thead.push(r1, r2)
|
71
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_add_content_directly
|
75
|
+
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
76
|
+
@thead.content = "hello","world"
|
77
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_add_content_in_constructor
|
81
|
+
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
82
|
+
@thead.send(:refresh)
|
83
|
+
@thead = Table::Head.create(["hello","world"])
|
84
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_configure_column
|
88
|
+
html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
89
|
+
html += "</td></tr></thead>"
|
90
|
+
@thead.content = "hello","world"
|
91
|
+
@thead.configure(0,1){ |d|
|
92
|
+
d.abbr = 'test'
|
93
|
+
d.width = 3
|
94
|
+
d.nowrap = true
|
95
|
+
}
|
96
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
97
|
+
end
|
98
|
+
|
99
|
+
def teardown
|
100
|
+
@table = nil
|
101
|
+
@thead.send(:refresh)
|
102
|
+
@thead = nil
|
103
|
+
end
|
104
|
+
end
|