html-table 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ ############################################
2
+ # tc_colgroup.rb
3
+ #
4
+ # Test suite for the Table::ColGroup class
5
+ ############################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /html-table/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd)
11
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/html")
13
+ Dir.chdir("test") rescue nil
14
+ end
15
+
16
+ require "test/unit"
17
+ require "html/table"
18
+ include HTML
19
+
20
+ class TC_HTML_Table_ColGroup < Test::Unit::TestCase
21
+ def setup
22
+ @cg = Table::ColGroup.new
23
+ @col = Table::ColGroup::Col.new
24
+ end
25
+
26
+ def test_constructor
27
+ assert_nothing_raised{ Table::ColGroup.new }
28
+ assert_nothing_raised{ Table::ColGroup.new(@col) }
29
+ assert_raises(TypeError){ Table::ColGroup.new("foo") }
30
+ end
31
+
32
+ def test_basic
33
+ html = "<colgroup></colgroup>"
34
+ assert_equal(html,@cg.html.gsub(/\s+/,''))
35
+ end
36
+
37
+ def test_with_attributes
38
+ html = "<colgroup align='center' width='20%'></colgroup>"
39
+ @cg.align = "center"
40
+ @cg.width = "20%"
41
+ assert_equal(html,@cg.html.gsub(/\s{2,}|\n+/,''))
42
+ end
43
+
44
+ def test_push_single_col_element
45
+ html = "<colgroup><col></colgroup>"
46
+ @cg.push(@col)
47
+ assert_equal(html,@cg.html.gsub(/\s{2,}|\n+/,''))
48
+ end
49
+
50
+ def test_index_assignment_constraints
51
+ assert_raises(ArgumentTypeError){ @cg[0] = "foo" }
52
+ assert_raises(ArgumentTypeError){ @cg[0] = 1 }
53
+ assert_raises(ArgumentTypeError){ @cg[1] = Table::Row.new }
54
+ assert_nothing_raised{ @cg[0] = Table::ColGroup::Col.new }
55
+ end
56
+
57
+ def test_push_constraints
58
+ assert_raises(TypeError){ @cg.push(7) }
59
+ assert_raises(TypeError){ @cg.push("hello") }
60
+ assert_raises(TypeError){ @cg.push(Table::Row.new) }
61
+ assert_nothing_raised{ @cg.push(Table::ColGroup::Col.new) }
62
+ end
63
+
64
+ # Test '<<'
65
+ def test_double_arrow_constraints
66
+ assert_raises(TypeError){ @cg << 7 }
67
+ assert_raises(TypeError){ @cg << "hello" }
68
+ assert_raises(TypeError){ @cg << Table::Row.new }
69
+ assert_nothing_raised{ @cg << Table::ColGroup::Col.new }
70
+ end
71
+
72
+ def test_configure_error
73
+ assert_raises(ArgumentError){ @cg.configure(0,0){ } }
74
+ end
75
+
76
+ def test_content_error
77
+ assert_raises(NoMethodError){ @cg.content }
78
+ assert_raises(NoMethodError){ @cg.content = 'blah' }
79
+ end
80
+
81
+ def test_indent_level
82
+ assert_respond_to(Table::ColGroup,:indent_level)
83
+ assert_respond_to(Table::ColGroup,:indent_level=)
84
+ assert_raises(ArgumentTypeError){ Table::ColGroup.indent_level = "foo" }
85
+ assert_nothing_raised{ Table::ColGroup.indent_level = 6 }
86
+ end
87
+
88
+ def test_end_tags
89
+ assert_respond_to(Table::ColGroup,:end_tags?)
90
+ assert_respond_to(Table::ColGroup,:end_tags=)
91
+ assert_raises(ArgumentTypeError){ Table::ColGroup.end_tags = "foo" }
92
+ assert_raises(ArgumentTypeError){ Table::ColGroup.end_tags = 1 }
93
+ assert_nothing_raised{ Table::ColGroup.end_tags = true }
94
+ end
95
+
96
+ def teardown
97
+ @cg = nil
98
+ end
99
+ end
@@ -0,0 +1,87 @@
1
+ ##############################################
2
+ # tc_data.rb
3
+ #
4
+ # Test suite for the Table::Row::Data class
5
+ ##############################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /html-table/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd)
11
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/html")
13
+ Dir.chdir("test") rescue nil
14
+ end
15
+
16
+ require "test/unit"
17
+ require "html/table"
18
+ include HTML
19
+
20
+ class TC_HTML_Table_Row_Data < Test::Unit::TestCase
21
+ def setup
22
+ @td = Table::Row::Data.new
23
+ end
24
+
25
+ def test_constructor
26
+ assert_nothing_raised{ Table::Row::Data.new }
27
+ assert_nothing_raised{ Table::Row::Data.new("foo") }
28
+ assert_nothing_raised{ Table::Row::Data.new(1) }
29
+ assert_nothing_raised{ Table::Row::Data.new(%w/foo bar baz/) }
30
+ assert_nothing_raised{ Table::Row::Data.new([1,2,3]) }
31
+ assert_nothing_raised{ Table::Row::Data.new([[1,2,3],["foo","bar"]]) }
32
+ end
33
+
34
+ def test_basic
35
+ html = "<td></td>"
36
+ assert_equal(html,@td.html.gsub(/\s+/,''))
37
+ end
38
+
39
+ def test_with_attributes
40
+ html = "<td align='left' width=3 nowrap></td>"
41
+ @td.align = 'left'
42
+ @td.width = 3
43
+ @td.nowrap = true
44
+ assert_equal(html,@td.html.gsub(/\s{2,}|\n+/,''))
45
+ end
46
+
47
+ def test_configure_not_allowed
48
+ assert_raises(NoMethodError){ @td.configure }
49
+ end
50
+
51
+ def test_add_content
52
+ html = "<td>hello world</td>"
53
+ @td.content = "hello world"
54
+ assert_equal(html,@td.html.gsub(/\s{2,}/,''))
55
+ end
56
+
57
+ def test_add_content_in_constructor
58
+ html = "<td>hello world</td>"
59
+ td = Table::Row::Data.new("hello world")
60
+ assert_equal(html,td.html.gsub(/\s{2,}/,''))
61
+ end
62
+
63
+ def test_add_multiple_content_items
64
+ html = "<td>hello world</td>"
65
+ @td.content = "hello"," world"
66
+ assert_equal(html,@td.html.gsub(/\s{2,}/,''))
67
+ end
68
+
69
+ def test_indent_level
70
+ assert_respond_to(Table::Row::Data,:indent_level)
71
+ assert_respond_to(Table::Row::Data,:indent_level=)
72
+ assert_raises(ArgumentTypeError){ Table::Row::Data.indent_level = "foo" }
73
+ assert_nothing_raised{ Table::Row::Data.indent_level = 6 }
74
+ end
75
+
76
+ def test_end_tags
77
+ assert_respond_to(Table::Row::Data,:end_tags?)
78
+ assert_respond_to(Table::Row::Data,:end_tags=)
79
+ assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = "foo" }
80
+ assert_raises(ArgumentTypeError){ Table::Row::Data.end_tags = 1 }
81
+ assert_nothing_raised{ Table::Row::Data.end_tags = true }
82
+ end
83
+
84
+ def teardown
85
+ @td = nil
86
+ end
87
+ end
@@ -0,0 +1,118 @@
1
+ ###############################################################################
2
+ # tc_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
+ base = File.basename(Dir.pwd)
9
+
10
+ if base == "test" || base =~ /html-table/
11
+ Dir.chdir("..") if base == "test"
12
+ $LOAD_PATH.unshift(Dir.pwd)
13
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
14
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/html")
15
+ Dir.chdir("test") rescue nil
16
+ end
17
+
18
+ require "test/unit"
19
+ require "html/table"
20
+ include HTML
21
+
22
+ #####################################################################
23
+ # Ensure that a fresh instance of Table::Foot is used between tests
24
+ # by calling 'refresh' in the 'teardown' method.
25
+ #####################################################################
26
+ class Table::Foot
27
+ private
28
+ def refresh
29
+ @@foot = nil
30
+ end
31
+ end
32
+
33
+ class TC_HTML_Table_Foot < Test::Unit::TestCase
34
+ def setup
35
+ @t = Table.new
36
+ @tf = Table::Foot.create
37
+ end
38
+
39
+ def test_new_not_allowed
40
+ assert_raises(NoMethodError){ Table::Foot.new }
41
+ end
42
+
43
+ def test_constructor
44
+ assert_nothing_raised{ Table::Foot.create }
45
+ assert_nothing_raised{ Table::Foot.create("foo") }
46
+ assert_nothing_raised{ Table::Foot.create(1) }
47
+ assert_nothing_raised{ Table::Foot.create(%w/foo bar baz/) }
48
+ assert_nothing_raised{ Table::Foot.create([1,2,3]) }
49
+ assert_nothing_raised{ Table::Foot.create([[1,2,3],["foo","bar"]]) }
50
+ end
51
+
52
+ def test_basic
53
+ html = "<tfoot></tfoot>"
54
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n/,''))
55
+ end
56
+
57
+ def test_end_tags
58
+ assert_respond_to(Table::Foot, :end_tags?)
59
+ assert_respond_to(Table::Foot, :end_tags=)
60
+ assert_nothing_raised{ Table::Foot.end_tags? }
61
+ assert_nothing_raised{ Table::Foot.end_tags = true }
62
+ assert_raises(StrongTyping::ArgumentTypeError){
63
+ Table::Foot.end_tags = "foo"
64
+ }
65
+ end
66
+
67
+ def test_with_attributes
68
+ html = "<tfoot align='left' char='x'></tfoot>"
69
+ @tf.align = "left"
70
+ @tf.char = 'x'
71
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n/,''))
72
+ end
73
+
74
+ def test_push_single_row
75
+ html = "<tfoot><tr><td>test</td></tr></tfoot>"
76
+ @tf.push Table::Row.new{|r| r.content = "test"}
77
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n/,''))
78
+ end
79
+
80
+ def test_push_multiple_rows
81
+ html = "<tfoot><tr><td>test</td></tr><tr><td>foo</td></tr></tfoot>"
82
+ r1 = Table::Row.new{|r| r.content = "test"}
83
+ r2 = Table::Row.new{|r| r.content = "foo"}
84
+ @tf.push r1, r2
85
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n/,''))
86
+ end
87
+
88
+ def test_add_content_directly
89
+ html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
90
+ @tf.content = "hello","world"
91
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n+/,''))
92
+ end
93
+
94
+ def test_add_content_in_constructor
95
+ html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
96
+ @tf.send(:refresh)
97
+ @tf = Table::Foot.create(["hello","world"])
98
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n+/,''))
99
+ end
100
+
101
+ def test_configure_column
102
+ html = "<tfoot><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
103
+ html += "</td></tr></tfoot>"
104
+ @tf.content = "hello","world"
105
+ @tf.configure(0,1){ |d|
106
+ d.abbr = 'test'
107
+ d.width = 3
108
+ d.nowrap = true
109
+ }
110
+ assert_equal(html,@tf.html.gsub(/\s{2,}|\n+/,''))
111
+ end
112
+
113
+ def teardown
114
+ @t = nil
115
+ @tf.send(:refresh)
116
+ @tf = nil
117
+ end
118
+ end
@@ -0,0 +1,114 @@
1
+ ###############################################################################
2
+ # tc_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
+ base = File.basename(Dir.pwd)
9
+
10
+ if base == "test" || base =~ /html-table/
11
+ Dir.chdir("..") if base == "test"
12
+ $LOAD_PATH.unshift(Dir.pwd)
13
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
14
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/html")
15
+ Dir.chdir("test") rescue nil
16
+ end
17
+
18
+ require "test/unit"
19
+ require "html/table"
20
+ include HTML
21
+
22
+ #####################################################################
23
+ # Ensure that a fresh instance of Table::Head is used between tests
24
+ # by calling 'refresh' in the 'teardown' method.
25
+ #####################################################################
26
+ class Table::Head
27
+ private
28
+ def refresh
29
+ @@head = nil
30
+ end
31
+ end
32
+
33
+ class TC_HTML_Table_Head < Test::Unit::TestCase
34
+ def setup
35
+ @t = Table.new
36
+ @th = Table::Head.create
37
+ end
38
+
39
+ def test_constructor
40
+ assert_nothing_raised{ Table::Head.create }
41
+ assert_nothing_raised{ Table::Head.create("foo") }
42
+ assert_nothing_raised{ Table::Head.create(1) }
43
+ assert_nothing_raised{ Table::Head.create(%w/foo bar baz/) }
44
+ assert_nothing_raised{ Table::Head.create([1,2,3]) }
45
+ assert_nothing_raised{ Table::Head.create([[1,2,3],["foo","bar"]]) }
46
+ end
47
+
48
+ def test_basic
49
+ html = "<thead></thead>"
50
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
51
+ end
52
+
53
+ def test_end_tags
54
+ assert_respond_to(Table::Head, :end_tags?)
55
+ assert_respond_to(Table::Head, :end_tags=)
56
+ assert_nothing_raised{ Table::Head.end_tags? }
57
+ assert_nothing_raised{ Table::Head.end_tags = true }
58
+ assert_raises(StrongTyping::ArgumentTypeError){
59
+ Table::Head.end_tags = "foo"
60
+ }
61
+ end
62
+
63
+ def test_with_attributes
64
+ html = "<thead align='left' char='x'></thead>"
65
+ @th.align = "left"
66
+ @th.char = 'x'
67
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
68
+ end
69
+
70
+ def test_push_single_row
71
+ html = "<thead><tr><td>test</td></tr></thead>"
72
+ @th.push Table::Row.new{|r| r.content = "test"}
73
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
74
+ end
75
+
76
+ def test_push_multiple_rows
77
+ html = "<thead><tr><td>test</td></tr><tr><td>foo</td></tr></thead>"
78
+ r1 = Table::Row.new("test")
79
+ r2 = Table::Row.new("foo")
80
+ @th.push(r1, r2)
81
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
82
+ end
83
+
84
+ def test_add_content_directly
85
+ html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
86
+ @th.content = "hello","world"
87
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
88
+ end
89
+
90
+ def test_add_content_in_constructor
91
+ html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
92
+ @th.send(:refresh)
93
+ @th = Table::Head.create(["hello","world"])
94
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
95
+ end
96
+
97
+ def test_configure_column
98
+ html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
99
+ html += "</td></tr></thead>"
100
+ @th.content = "hello","world"
101
+ @th.configure(0,1){ |d|
102
+ d.abbr = 'test'
103
+ d.width = 3
104
+ d.nowrap = true
105
+ }
106
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
107
+ end
108
+
109
+ def teardown
110
+ @t = nil
111
+ @th.send(:refresh)
112
+ @th = nil
113
+ end
114
+ end
@@ -0,0 +1,87 @@
1
+ ################################################
2
+ # tc_header.rb
3
+ #
4
+ # Test suite for the Table::Row::Header class
5
+ ################################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /html-table/
9
+ Dir.chdir("..") if base == "test"
10
+ $LOAD_PATH.unshift(Dir.pwd)
11
+ $LOAD_PATH.unshift(Dir.pwd + "/lib")
12
+ $LOAD_PATH.unshift(Dir.pwd + "/lib/html")
13
+ Dir.chdir("test") rescue nil
14
+ end
15
+
16
+ require "test/unit"
17
+ require "html/table"
18
+ include HTML
19
+
20
+ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
21
+ def setup
22
+ @th = Table::Row::Header.new
23
+ end
24
+
25
+ def test_basic
26
+ html = "<th></th>"
27
+ assert_equal(html,@th.html.gsub(/\s+/,''))
28
+ end
29
+
30
+ def test_constructor
31
+ assert_nothing_raised{ Table::Row::Header.new }
32
+ assert_nothing_raised{ Table::Row::Header.new("foo") }
33
+ assert_nothing_raised{ Table::Row::Header.new(1) }
34
+ assert_nothing_raised{ Table::Row::Header.new(%w/foo bar baz/) }
35
+ assert_nothing_raised{ Table::Row::Header.new([1,2,3]) }
36
+ assert_nothing_raised{ Table::Row::Header.new([[1,2,3],["foo","bar"]]) }
37
+ end
38
+
39
+ def test_with_attributes
40
+ html = "<th align='left' colspan=3 nowrap></th>"
41
+ @th.align = 'left'
42
+ @th.colspan = 3
43
+ @th.nowrap = true
44
+ assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
45
+ end
46
+
47
+ def test_configure_not_allowed
48
+ assert_raises(NoMethodError){ @th.configure }
49
+ end
50
+
51
+ def test_add_content
52
+ html = "<th>hello world</th>"
53
+ @th.content = "hello world"
54
+ assert_equal(html,@th.html.gsub(/\s{2,}/,''))
55
+ end
56
+
57
+ def test_add_multiple_content_items
58
+ html = "<th>hello world</th>"
59
+ @th.content = "hello"," world"
60
+ assert_equal(html,@th.html.gsub(/\s{2,}/,''))
61
+ end
62
+
63
+ def test_add_content_in_constructor
64
+ html = "<th>hello world</th>"
65
+ th = Table::Row::Header.new("hello world")
66
+ assert_equal(html,th.html.gsub(/\s{2,}/,''))
67
+ end
68
+
69
+ def test_indent_level
70
+ assert_respond_to(Table::Row::Header,:indent_level)
71
+ assert_respond_to(Table::Row::Header,:indent_level=)
72
+ assert_raises(ArgumentTypeError){ Table::Row::Header.indent_level = "foo" }
73
+ assert_nothing_raised{ Table::Row::Header.indent_level = 6 }
74
+ end
75
+
76
+ def test_end_tags
77
+ assert_respond_to(Table::Row::Header,:end_tags?)
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