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