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_header.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
|
-
################################################
|
2
|
-
# test_header.rb
|
3
|
-
#
|
4
|
-
# Test suite for the Table::Row::Header 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_Header < Test::Unit::TestCase
|
14
|
-
def setup
|
15
|
-
@theader = Table::Row::Header.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_basic
|
19
|
-
html = "<th></th>"
|
20
|
-
assert_equal(html, @theader.html.gsub(/\s+/,''))
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_constructor
|
24
|
-
assert_nothing_raised{ Table::Row::Header.new }
|
25
|
-
assert_nothing_raised{ Table::Row::Header.new("foo") }
|
26
|
-
assert_nothing_raised{ Table::Row::Header.new(1) }
|
27
|
-
assert_nothing_raised{ Table::Row::Header.new(%w/foo bar baz/) }
|
28
|
-
assert_nothing_raised{ Table::Row::Header.new([1,2,3]) }
|
29
|
-
assert_nothing_raised{ Table::Row::Header.new([[1,2,3],["foo","bar"]]) }
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_with_attributes
|
33
|
-
html = "<th align='left' colspan=3 nowrap></th>"
|
34
|
-
@theader.align = 'left'
|
35
|
-
@theader.colspan = 3
|
36
|
-
@theader.nowrap = true
|
37
|
-
assert_equal(html, @theader.html.gsub(/\s{2,}|\n+/,''))
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_configure_not_allowed
|
41
|
-
assert_raises(NoMethodError){ @theader.configure }
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_add_content
|
45
|
-
html = "<th>hello world</th>"
|
46
|
-
@theader.content = "hello world"
|
47
|
-
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_add_multiple_content_items
|
51
|
-
html = "<th>hello world</th>"
|
52
|
-
@theader.content = "hello"," world"
|
53
|
-
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_add_content_in_constructor
|
57
|
-
html = "<th>hello world</th>"
|
58
|
-
@theader = Table::Row::Header.new("hello world")
|
59
|
-
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_indent_level
|
63
|
-
assert_respond_to(Table::Row::Header,:indent_level)
|
64
|
-
assert_respond_to(Table::Row::Header,:indent_level=)
|
65
|
-
assert_raises(ArgumentTypeError){ Table::Row::Header.indent_level = "foo" }
|
66
|
-
assert_nothing_raised{ Table::Row::Header.indent_level = 6 }
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_end_tags
|
70
|
-
assert_respond_to(Table::Row::Header,:end_tags?)
|
71
|
-
assert_respond_to(Table::Row::Header,:end_tags=)
|
72
|
-
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = "foo" }
|
73
|
-
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = 1 }
|
74
|
-
assert_nothing_raised{ Table::Row::Header.end_tags = true }
|
75
|
-
end
|
76
|
-
|
77
|
-
def teardown
|
78
|
-
@theader = nil
|
79
|
-
end
|
80
|
-
end
|
1
|
+
################################################
|
2
|
+
# test_header.rb
|
3
|
+
#
|
4
|
+
# Test suite for the Table::Row::Header 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_Header < Test::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
@theader = Table::Row::Header.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_basic
|
19
|
+
html = "<th></th>"
|
20
|
+
assert_equal(html, @theader.html.gsub(/\s+/,''))
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_constructor
|
24
|
+
assert_nothing_raised{ Table::Row::Header.new }
|
25
|
+
assert_nothing_raised{ Table::Row::Header.new("foo") }
|
26
|
+
assert_nothing_raised{ Table::Row::Header.new(1) }
|
27
|
+
assert_nothing_raised{ Table::Row::Header.new(%w/foo bar baz/) }
|
28
|
+
assert_nothing_raised{ Table::Row::Header.new([1,2,3]) }
|
29
|
+
assert_nothing_raised{ Table::Row::Header.new([[1,2,3],["foo","bar"]]) }
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_with_attributes
|
33
|
+
html = "<th align='left' colspan=3 nowrap></th>"
|
34
|
+
@theader.align = 'left'
|
35
|
+
@theader.colspan = 3
|
36
|
+
@theader.nowrap = true
|
37
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}|\n+/,''))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_configure_not_allowed
|
41
|
+
assert_raises(NoMethodError){ @theader.configure }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_add_content
|
45
|
+
html = "<th>hello world</th>"
|
46
|
+
@theader.content = "hello world"
|
47
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_add_multiple_content_items
|
51
|
+
html = "<th>hello world</th>"
|
52
|
+
@theader.content = "hello"," world"
|
53
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_content_in_constructor
|
57
|
+
html = "<th>hello world</th>"
|
58
|
+
@theader = Table::Row::Header.new("hello world")
|
59
|
+
assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_indent_level
|
63
|
+
assert_respond_to(Table::Row::Header,:indent_level)
|
64
|
+
assert_respond_to(Table::Row::Header,:indent_level=)
|
65
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.indent_level = "foo" }
|
66
|
+
assert_nothing_raised{ Table::Row::Header.indent_level = 6 }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_end_tags
|
70
|
+
assert_respond_to(Table::Row::Header,:end_tags?)
|
71
|
+
assert_respond_to(Table::Row::Header,:end_tags=)
|
72
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = "foo" }
|
73
|
+
assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = 1 }
|
74
|
+
assert_nothing_raised{ Table::Row::Header.end_tags = true }
|
75
|
+
end
|
76
|
+
|
77
|
+
def teardown
|
78
|
+
@theader = nil
|
79
|
+
end
|
80
|
+
end
|
data/test/test_html_handler.rb
CHANGED
@@ -1,40 +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
|
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
CHANGED
@@ -1,144 +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
|
+
############################################
|
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
|