html-table 1.3.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +13 -0
- data/MANIFEST +13 -13
- data/README +27 -26
- data/Rakefile +120 -2
- data/examples/advanced.rb +128 -0
- data/examples/intermediate1.rb +72 -0
- data/examples/intermediate2.rb +62 -0
- data/examples/intermediate3.rb +46 -0
- data/examples/simple1.rb +39 -0
- data/examples/simple2.rb +47 -0
- data/examples/simple3.rb +41 -0
- data/html-table.gemspec +5 -3
- data/lib/html/attribute_handler.rb +8 -16
- data/lib/html/table.rb +11 -4
- data/lib/html/tag_handler.rb +1 -3
- data/test/{tc_attribute_handler.rb → test_attribute_handler.rb} +110 -9
- data/test/{tc_body.rb → test_body.rb} +31 -28
- data/test/{tc_caption.rb → test_caption.rb} +26 -23
- data/test/{tc_col.rb → test_col.rb} +13 -10
- data/test/{tc_colgroup.rb → test_colgroup.rb} +29 -26
- data/test/{tc_data.rb → test_data.rb} +18 -15
- data/test/{tc_foot.rb → test_foot.rb} +34 -28
- data/test/{tc_head.rb → test_head.rb} +27 -24
- data/test/{tc_header.rb → test_header.rb} +20 -17
- data/test/test_html_handler.rb +40 -0
- data/test/test_row.rb +144 -0
- data/test/{tc_table.rb → test_table.rb} +47 -44
- data/test/{tc_tablesection.rb → test_tablesection.rb} +14 -11
- data/test/test_tag_handler.rb +93 -0
- metadata +61 -37
- data/html-table-1.3.2.gem +0 -0
- data/test/tc_html_handler.rb +0 -37
- data/test/tc_row.rb +0 -141
- data/test/tc_tag_handler.rb +0 -82
@@ -1,12 +1,15 @@
|
|
1
1
|
###############################################################################
|
2
|
-
#
|
2
|
+
# test_head.rb
|
3
3
|
#
|
4
4
|
# Test suite for the Table::Head class. The Table::Head class is a singleton
|
5
5
|
# class, so we have to take extra measures to ensure that a fresh instance
|
6
6
|
# is created between tests.
|
7
7
|
###############################################################################
|
8
|
-
require
|
9
|
-
|
8
|
+
require 'rubygems'
|
9
|
+
gem 'test-unit'
|
10
|
+
|
11
|
+
require 'test/unit'
|
12
|
+
require 'html/table'
|
10
13
|
include HTML
|
11
14
|
|
12
15
|
#####################################################################
|
@@ -22,8 +25,8 @@ end
|
|
22
25
|
|
23
26
|
class TC_HTML_Table_Head < Test::Unit::TestCase
|
24
27
|
def setup
|
25
|
-
@
|
26
|
-
@
|
28
|
+
@table = Table.new
|
29
|
+
@thead = Table::Head.create
|
27
30
|
end
|
28
31
|
|
29
32
|
def test_constructor
|
@@ -37,7 +40,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
|
|
37
40
|
|
38
41
|
def test_basic
|
39
42
|
html = "<thead></thead>"
|
40
|
-
assert_equal(html,@
|
43
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
41
44
|
end
|
42
45
|
|
43
46
|
def test_end_tags
|
@@ -52,53 +55,53 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
|
|
52
55
|
|
53
56
|
def test_with_attributes
|
54
57
|
html = "<thead align='left' char='x'></thead>"
|
55
|
-
@
|
56
|
-
@
|
57
|
-
assert_equal(html,@
|
58
|
+
@thead.align = "left"
|
59
|
+
@thead.char = 'x'
|
60
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
58
61
|
end
|
59
62
|
|
60
63
|
def test_push_single_row
|
61
64
|
html = "<thead><tr><td>test</td></tr></thead>"
|
62
|
-
@
|
63
|
-
assert_equal(html,@
|
65
|
+
@thead.push Table::Row.new{|r| r.content = "test"}
|
66
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
64
67
|
end
|
65
68
|
|
66
69
|
def test_push_multiple_rows
|
67
70
|
html = "<thead><tr><td>test</td></tr><tr><td>foo</td></tr></thead>"
|
68
71
|
r1 = Table::Row.new("test")
|
69
72
|
r2 = Table::Row.new("foo")
|
70
|
-
@
|
71
|
-
assert_equal(html,@
|
73
|
+
@thead.push(r1, r2)
|
74
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
|
72
75
|
end
|
73
76
|
|
74
77
|
def test_add_content_directly
|
75
78
|
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
76
|
-
@
|
77
|
-
assert_equal(html,@
|
79
|
+
@thead.content = "hello","world"
|
80
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
78
81
|
end
|
79
82
|
|
80
83
|
def test_add_content_in_constructor
|
81
84
|
html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
|
82
|
-
@
|
83
|
-
@
|
84
|
-
assert_equal(html,@
|
85
|
+
@thead.send(:refresh)
|
86
|
+
@thead = Table::Head.create(["hello","world"])
|
87
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
85
88
|
end
|
86
89
|
|
87
90
|
def test_configure_column
|
88
91
|
html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
|
89
92
|
html += "</td></tr></thead>"
|
90
|
-
@
|
91
|
-
@
|
93
|
+
@thead.content = "hello","world"
|
94
|
+
@thead.configure(0,1){ |d|
|
92
95
|
d.abbr = 'test'
|
93
96
|
d.width = 3
|
94
97
|
d.nowrap = true
|
95
98
|
}
|
96
|
-
assert_equal(html,@
|
99
|
+
assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
|
97
100
|
end
|
98
101
|
|
99
102
|
def teardown
|
100
|
-
@
|
101
|
-
@
|
102
|
-
@
|
103
|
+
@table = nil
|
104
|
+
@thead.send(:refresh)
|
105
|
+
@thead = nil
|
103
106
|
end
|
104
107
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
################################################
|
2
|
-
#
|
2
|
+
# test_header.rb
|
3
3
|
#
|
4
4
|
# Test suite for the Table::Row::Header class
|
5
5
|
################################################
|
6
|
-
require
|
7
|
-
|
6
|
+
require 'rubygems'
|
7
|
+
gem 'test-unit'
|
8
|
+
|
9
|
+
require 'test/unit'
|
10
|
+
require 'html/table'
|
8
11
|
include HTML
|
9
12
|
|
10
13
|
class TC_HTML_Table_Row_Header < Test::Unit::TestCase
|
11
14
|
def setup
|
12
|
-
@
|
15
|
+
@theader = Table::Row::Header.new
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_basic
|
16
19
|
html = "<th></th>"
|
17
|
-
assert_equal(html
|
20
|
+
assert_equal(html, @theader.html.gsub(/\s+/,''))
|
18
21
|
end
|
19
22
|
|
20
23
|
def test_constructor
|
@@ -28,32 +31,32 @@ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
|
|
28
31
|
|
29
32
|
def test_with_attributes
|
30
33
|
html = "<th align='left' colspan=3 nowrap></th>"
|
31
|
-
@
|
32
|
-
@
|
33
|
-
@
|
34
|
-
assert_equal(html
|
34
|
+
@theader.align = 'left'
|
35
|
+
@theader.colspan = 3
|
36
|
+
@theader.nowrap = true
|
37
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}|\n+/,''))
|
35
38
|
end
|
36
39
|
|
37
40
|
def test_configure_not_allowed
|
38
|
-
assert_raises(NoMethodError){ @
|
41
|
+
assert_raises(NoMethodError){ @theader.configure }
|
39
42
|
end
|
40
43
|
|
41
44
|
def test_add_content
|
42
45
|
html = "<th>hello world</th>"
|
43
|
-
@
|
44
|
-
assert_equal(html
|
46
|
+
@theader.content = "hello world"
|
47
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
45
48
|
end
|
46
49
|
|
47
50
|
def test_add_multiple_content_items
|
48
51
|
html = "<th>hello world</th>"
|
49
|
-
@
|
50
|
-
assert_equal(html
|
52
|
+
@theader.content = "hello"," world"
|
53
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
51
54
|
end
|
52
55
|
|
53
56
|
def test_add_content_in_constructor
|
54
57
|
html = "<th>hello world</th>"
|
55
|
-
|
56
|
-
assert_equal(html,
|
58
|
+
@theader = Table::Row::Header.new("hello world")
|
59
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
57
60
|
end
|
58
61
|
|
59
62
|
def test_indent_level
|
@@ -72,6 +75,6 @@ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
|
|
72
75
|
end
|
73
76
|
|
74
77
|
def teardown
|
75
|
-
@
|
78
|
+
@theader = nil
|
76
79
|
end
|
77
80
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
############################################################################
|
2
|
+
# test_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 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'html/table'
|
12
|
+
include HTML
|
13
|
+
|
14
|
+
class TC_HtmlHandler < Test::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@table = Table.new(["foo",1,"bar"])
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_html
|
20
|
+
assert_respond_to(@table, :html)
|
21
|
+
assert_nothing_raised{ @table.html }
|
22
|
+
assert_raises(NoMethodError){ @table.html = "foo" }
|
23
|
+
assert_kind_of(String, @table.html)
|
24
|
+
assert_equal(true, @table.html.length > 0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_modify_html
|
28
|
+
assert_raises(ArgumentError){ @table.send(:modify_html) }
|
29
|
+
assert_nothing_raised{ @table.send(:modify_html,"nowrap") }
|
30
|
+
assert_nothing_raised{ @table.send(:modify_html,"align","top") }
|
31
|
+
assert_nothing_raised{
|
32
|
+
@table.send(:modify_html,"align","top")
|
33
|
+
@table.send(:modify_html,"align","top")
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
@table = nil
|
39
|
+
end
|
40
|
+
end
|
data/test/test_row.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
############################################
|
2
|
+
# test_row.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Row 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 < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@trow = Table::Row.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_constructor
|
19
|
+
assert_nothing_raised{ Table::Row.new }
|
20
|
+
assert_nothing_raised{ Table::Row.new("foo") }
|
21
|
+
assert_nothing_raised{ Table::Row.new(1) }
|
22
|
+
assert_nothing_raised{ Table::Row.new([1,2,3]) }
|
23
|
+
assert_nothing_raised{ Table::Row.new([[1,2,3],["foo","bar"]]) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_basic
|
27
|
+
html = "<tr></tr>"
|
28
|
+
assert_equal(html,@trow.html.gsub(/\s+/,''))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_header
|
32
|
+
assert_respond_to(@trow, :header?)
|
33
|
+
assert_respond_to(@trow, :header=)
|
34
|
+
assert_nothing_raised{ @trow.header? }
|
35
|
+
assert_nothing_raised{ @trow.header = true }
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_with_attributes
|
39
|
+
html = "<tr align='center'></tr>"
|
40
|
+
@trow.align = "center"
|
41
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_index_assignment_constraints
|
45
|
+
assert_raises(ArgumentTypeError){ @trow[0] = "foo" }
|
46
|
+
assert_raises(ArgumentTypeError){ @trow[0] = 1 }
|
47
|
+
assert_raises(ArgumentTypeError){ @trow[0] = Table::Caption.new }
|
48
|
+
assert_nothing_raised{ @trow[0] = Table::Row::Data.new }
|
49
|
+
assert_nothing_raised{ @trow[0] = Table::Row::Header.new }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_push_constraints
|
53
|
+
assert_raises(ArgumentTypeError){ @trow.push(Table::Caption.new) }
|
54
|
+
assert_raises(ArgumentTypeError){ @trow.push(nil) }
|
55
|
+
assert_nothing_raised{ @trow.push("test") }
|
56
|
+
assert_nothing_raised{ @trow.push(7) }
|
57
|
+
assert_nothing_raised{ @trow.push(Table::Row::Data.new) }
|
58
|
+
assert_nothing_raised{ @trow.push(Table::Row::Header.new) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# Test the '<<' method
|
62
|
+
def test_doubl_arrow_constraints
|
63
|
+
assert_raises(ArgumentTypeError){ @trow << Table::Caption.new }
|
64
|
+
assert_nothing_raised{ @trow << "test" }
|
65
|
+
assert_nothing_raised{ @trow << "test" << "foo" }
|
66
|
+
assert_nothing_raised{ @trow << Table::Row::Data.new }
|
67
|
+
assert_nothing_raised{ @trow << Table::Row::Header.new }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_header_in_constructor
|
71
|
+
assert_nothing_raised{ @trow = Table::Row.new('test', true) }
|
72
|
+
html = "<tr><th>test</th></tr>"
|
73
|
+
assert_equal(html, @trow.html.gsub(/\s+/,''))
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_push_single_data_element
|
77
|
+
html = "<tr><td>hello</td></tr>"
|
78
|
+
@trow.push Table::Row::Data.new{ |d| d.content = "hello" }
|
79
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_push_multiple_data_element
|
83
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
84
|
+
d1 = Table::Row::Data.new{ |d| d.content = "hello" }
|
85
|
+
d2 = Table::Row::Data.new{ |d| d.content = "world" }
|
86
|
+
@trow.push d1, d2
|
87
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_add_content_directly
|
91
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
92
|
+
@trow.content = "hello","world"
|
93
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_add_content_in_constructor
|
97
|
+
html = "<tr><td>hello</td><td>world</td></tr>"
|
98
|
+
@trow = Table::Row.new(%w/hello world/)
|
99
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_configure_column
|
103
|
+
html = "<tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr>"
|
104
|
+
@trow.content = "hello","world"
|
105
|
+
@trow.configure(1){ |d|
|
106
|
+
d.abbr = 'test'
|
107
|
+
d.width = 3
|
108
|
+
d.nowrap = true
|
109
|
+
}
|
110
|
+
assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_unshift_constraints
|
114
|
+
assert_raises(ArgumentTypeError){ @trow.unshift(Table::Caption.new) }
|
115
|
+
assert_raises(ArgumentTypeError){ @trow.unshift(nil) }
|
116
|
+
assert_nothing_raised{ @trow.unshift("test") }
|
117
|
+
assert_nothing_raised{ @trow.unshift(7) }
|
118
|
+
assert_nothing_raised{ @trow.unshift(Table::Row::Data.new) }
|
119
|
+
assert_nothing_raised{ @trow.unshift(Table::Row::Header.new) }
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_configure_error
|
123
|
+
assert_raises(ArgumentError){ @trow.configure(0,0){ } }
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_indent_level
|
127
|
+
assert_respond_to(Table::Row,:indent_level)
|
128
|
+
assert_respond_to(Table::Row,:indent_level=)
|
129
|
+
assert_raises(ArgumentTypeError){ Table::Row.indent_level = "foo" }
|
130
|
+
assert_nothing_raised{ Table::Row.indent_level = 3 }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_end_tags
|
134
|
+
assert_respond_to(Table::Row,:end_tags?)
|
135
|
+
assert_respond_to(Table::Row,:end_tags=)
|
136
|
+
assert_raises(ArgumentTypeError){ Table::Row.end_tags = "foo" }
|
137
|
+
assert_raises(ArgumentTypeError){ Table::Row.end_tags = 1 }
|
138
|
+
assert_nothing_raised{ Table::Row.end_tags = true }
|
139
|
+
end
|
140
|
+
|
141
|
+
def teardown
|
142
|
+
@trow = nil
|
143
|
+
end
|
144
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
1
|
#######################################################################
|
2
|
-
#
|
2
|
+
# test_table.rb
|
3
3
|
#
|
4
4
|
# Test suite for the HTML::Table class. This test case should be run
|
5
5
|
# via the 'rake test' task.
|
6
6
|
#######################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
7
10
|
require 'test/unit'
|
8
11
|
require 'html/table'
|
9
12
|
require 'strongtyping'
|
@@ -12,11 +15,11 @@ include HTML
|
|
12
15
|
|
13
16
|
class TC_HTML_Table < Test::Unit::TestCase
|
14
17
|
def setup
|
15
|
-
@
|
18
|
+
@table = Table.new
|
16
19
|
end
|
17
20
|
|
18
21
|
def test_version
|
19
|
-
assert_equal('1.3.
|
22
|
+
assert_equal('1.3.3', Table::VERSION)
|
20
23
|
end
|
21
24
|
|
22
25
|
def test_constructor
|
@@ -45,99 +48,99 @@ class TC_HTML_Table < Test::Unit::TestCase
|
|
45
48
|
end
|
46
49
|
|
47
50
|
def test_index
|
48
|
-
assert_raises(ArgumentTypeError){ @
|
51
|
+
assert_raises(ArgumentTypeError){ @table[0] = 'foo' }
|
49
52
|
end
|
50
53
|
|
51
54
|
def test_caption_index_constraints
|
52
|
-
assert_nothing_raised{ @
|
53
|
-
assert_raises(ArgumentError){ @
|
55
|
+
assert_nothing_raised{ @table[0] = Table::Caption.new }
|
56
|
+
assert_raises(ArgumentError){ @table[1] = Table::Caption.new }
|
54
57
|
end
|
55
58
|
|
56
59
|
def test_head_index_constraints
|
57
|
-
assert_nothing_raised{ @
|
58
|
-
assert_raises(ArgumentError){ @
|
59
|
-
assert_raises(ArgumentError){ @
|
60
|
+
assert_nothing_raised{ @table[0] = Table::Head.create }
|
61
|
+
assert_raises(ArgumentError){ @table[1] = Table::Head.create }
|
62
|
+
assert_raises(ArgumentError){ @table[2] = Table::Head.create }
|
60
63
|
end
|
61
64
|
|
62
65
|
def test_foot_index_constraints
|
63
66
|
assert_nothing_raised{
|
64
|
-
@
|
65
|
-
@
|
67
|
+
@table[0] = Table::Caption.new
|
68
|
+
@table[-1] = Table::Foot.create
|
66
69
|
}
|
67
|
-
assert_raises(ArgumentError){ @
|
70
|
+
assert_raises(ArgumentError){ @table[0] = Table::Foot.create }
|
68
71
|
end
|
69
72
|
|
70
73
|
def test_unshift_constraints
|
71
|
-
assert_nothing_raised{ @
|
72
|
-
assert_raises(ArgumentTypeError){ @
|
73
|
-
assert_raises(ArgumentTypeError){ @
|
74
|
+
assert_nothing_raised{ @table.unshift Table::Row.new }
|
75
|
+
assert_raises(ArgumentTypeError){ @table.unshift Table::Row::Data.new }
|
76
|
+
assert_raises(ArgumentTypeError){ @table.unshift 'foo' }
|
74
77
|
end
|
75
78
|
|
76
79
|
def test_push_constraints
|
77
|
-
assert_nothing_raised{ @
|
78
|
-
assert_raises(ArgumentTypeError){ @
|
79
|
-
assert_raises(ArgumentTypeError){ @
|
80
|
-
assert_raises(ArgumentTypeError){ @
|
80
|
+
assert_nothing_raised{ @table.push Table::Row.new }
|
81
|
+
assert_raises(ArgumentTypeError){ @table.push('foo') }
|
82
|
+
assert_raises(ArgumentTypeError){ @table.push(7) }
|
83
|
+
assert_raises(ArgumentTypeError){ @table.push(nil) }
|
81
84
|
end
|
82
85
|
|
83
86
|
def test_double_arrow_constraints
|
84
|
-
assert_nothing_raised{ @
|
85
|
-
assert_nothing_raised{ @
|
86
|
-
assert_raises(ArgumentTypeError){ @
|
87
|
-
assert_raises(ArgumentTypeError){ @
|
88
|
-
assert_raises(ArgumentTypeError){ @
|
87
|
+
assert_nothing_raised{ @table << Table::Row.new }
|
88
|
+
assert_nothing_raised{ @table << Table::Row.new << Table::Row.new }
|
89
|
+
assert_raises(ArgumentTypeError){ @table << 'foo' }
|
90
|
+
assert_raises(ArgumentTypeError){ @table << 7 }
|
91
|
+
assert_raises(ArgumentTypeError){ @table << nil }
|
89
92
|
end
|
90
93
|
|
91
94
|
def test_basic
|
92
95
|
html = "<table>\n</table>"
|
93
|
-
assert_equal(html, @
|
96
|
+
assert_equal(html, @table.html)
|
94
97
|
end
|
95
98
|
|
96
99
|
def test_with_attributes
|
97
100
|
html = "<table border=1 align='left' nowrap>\n</table>"
|
98
|
-
@
|
99
|
-
@
|
100
|
-
@
|
101
|
-
assert_equal(html, @
|
101
|
+
@table.border = 1
|
102
|
+
@table.align = 'left'
|
103
|
+
@table.nowrap = true
|
104
|
+
assert_equal(html, @table.html)
|
102
105
|
end
|
103
106
|
|
104
107
|
def test_add_row_push
|
105
108
|
html = '<table><tr></tr></table>'
|
106
|
-
@
|
107
|
-
assert_equal(html, @
|
109
|
+
@table.push(Table::Row.new)
|
110
|
+
assert_equal(html, @table.html.gsub(/\s+/,''))
|
108
111
|
end
|
109
112
|
|
110
113
|
def test_add_row_by_index
|
111
114
|
html = '<table><tr></tr></table>'
|
112
|
-
@
|
113
|
-
assert_equal(html, @
|
115
|
+
@table[0] = Table::Row.new
|
116
|
+
assert_equal(html, @table.html.gsub(/\s+/,''))
|
114
117
|
end
|
115
118
|
|
116
119
|
def test_add_multiple_rows
|
117
120
|
html = '<table><tr></tr><tr></tr></table>'
|
118
|
-
@
|
119
|
-
assert_equal(html, @
|
121
|
+
@table.push Table::Row.new, Table::Row.new
|
122
|
+
assert_equal(html, @table.html.gsub(/\s+/,''))
|
120
123
|
end
|
121
124
|
|
122
125
|
def test_add_single_data_element
|
123
126
|
html = '<table><tr><td>hello</td></tr></table>'
|
124
|
-
@
|
125
|
-
assert_equal(html, @
|
127
|
+
@table.content = 'hello'
|
128
|
+
assert_equal(html, @table.html.gsub(/\s+/,''))
|
126
129
|
end
|
127
130
|
|
128
131
|
def test_add_multiple_data_elements
|
129
132
|
html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
|
130
|
-
@
|
131
|
-
assert_equal(html, @
|
133
|
+
@table.content = 'hello','world'
|
134
|
+
assert_equal(html, @table.html.gsub(/\s+/,''))
|
132
135
|
end
|
133
136
|
|
134
137
|
def test_configure_row
|
135
138
|
html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
|
136
139
|
html << '</table>'
|
137
|
-
@
|
138
|
-
@
|
139
|
-
@
|
140
|
-
assert_equal(html, @
|
140
|
+
@table.push Table::Row::Data.new{ |d| d.content = 'hello' }
|
141
|
+
@table.configure(0){ |t| t.align = 'center' }
|
142
|
+
@table.configure(0,0){ |d| d.bgcolor = 'red' }
|
143
|
+
assert_equal(html, @table.html.gsub(/\s{2,}|\n+/,''))
|
141
144
|
end
|
142
145
|
|
143
146
|
def test_global_end_tags
|
@@ -149,6 +152,6 @@ class TC_HTML_Table < Test::Unit::TestCase
|
|
149
152
|
end
|
150
153
|
|
151
154
|
def teardown
|
152
|
-
@
|
155
|
+
@table = nil
|
153
156
|
end
|
154
157
|
end
|