html-table 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/tc_table.rb CHANGED
@@ -1,163 +1,154 @@
1
- ############################################
2
- # tc_table.rb
3
- #
4
- # Test suite for the Table 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
- require "strongtyping"
19
- include StrongTyping
20
- include HTML
21
-
22
- class TC_HTML_Table < Test::Unit::TestCase
23
- def setup
24
- @t = Table.new
25
- end
26
-
27
- def test_version
28
- assert_equal('1.3.1', Table::VERSION)
29
- end
30
-
31
- def test_constructor
32
- assert_nothing_raised{ Table.new }
33
- assert_nothing_raised{ Table.new("foo") }
34
- assert_nothing_raised{ Table.new(1) }
35
- assert_nothing_raised{ Table.new(%w/foo bar baz/) }
36
- assert_nothing_raised{ Table.new([1,2,3]) }
37
- assert_nothing_raised{ Table.new([[1,2,3],["foo","bar"]]) }
38
- end
39
-
40
- def test_html_case
41
- assert_respond_to(Table, :html_case)
42
- assert_respond_to(Table, :html_case=)
43
- assert_nothing_raised{ Table.html_case = "upper" }
44
- assert_nothing_raised{ Table.html_case = "lower" }
45
- assert_raises(ArgumentError){ Table.html_case = "foo" }
46
- assert_raises(ArgumentTypeError){ Table.html_case = 7 }
47
- end
48
-
49
- def test_indent_level
50
- assert_respond_to(Table, :indent_level)
51
- assert_respond_to(Table, :indent_level=)
52
- assert_nothing_raised{ Table.indent_level = 0 }
53
- assert_raises(ArgumentTypeError){ Table.indent_level = "foo" }
54
- end
55
-
56
- def test_index
57
- assert_raises(ArgumentTypeError){ @t[0] = "foo" }
58
- end
59
-
60
- def test_caption_index_constraints
61
- assert_nothing_raised{ @t[0] = Table::Caption.new }
62
- assert_raises(ArgumentError){ @t[1] = Table::Caption.new }
63
- end
64
-
65
- def test_head_index_constraints
66
- assert_nothing_raised{ @t[0] = Table::Head.create }
67
- assert_raises(ArgumentError){ @t[1] = Table::Head.create }
68
- assert_raises(ArgumentError){ @t[2] = Table::Head.create }
69
- end
70
-
71
- def test_foot_index_constraints
72
- assert_nothing_raised{
73
- @t[0] = Table::Caption.new
74
- @t[-1] = Table::Foot.create
75
- }
76
- assert_raises(ArgumentError){ @t[0] = Table::Foot.create }
77
- end
78
-
79
- def test_unshift_constraints
80
- assert_nothing_raised{ @t.unshift Table::Row.new }
81
- assert_raises(ArgumentTypeError){ @t.unshift Table::Row::Data.new }
82
- assert_raises(ArgumentTypeError){ @t.unshift "foo" }
83
- end
84
-
85
- def test_push_constraints
86
- assert_nothing_raised{ @t.push Table::Row.new }
87
- assert_raises(ArgumentTypeError){ @t.push("foo") }
88
- assert_raises(ArgumentTypeError){ @t.push(7) }
89
- assert_raises(ArgumentTypeError){ @t.push(nil) }
90
- end
91
-
92
- def test_double_arrow_constraints
93
- assert_nothing_raised{ @t << Table::Row.new }
94
- assert_nothing_raised{ @t << Table::Row.new << Table::Row.new }
95
- assert_raises(ArgumentTypeError){ @t << "foo" }
96
- assert_raises(ArgumentTypeError){ @t << 7 }
97
- assert_raises(ArgumentTypeError){ @t << nil }
98
- end
99
-
100
- def test_basic
101
- html = "<table>\n</table>"
102
- assert_equal(html,@t.html)
103
- end
104
-
105
- def test_with_attributes
106
- html = "<table border=1 align='left' nowrap>\n</table>"
107
- @t.border = 1
108
- @t.align = "left"
109
- @t.nowrap = true
110
- assert_equal(html,@t.html)
111
- end
112
-
113
- def test_add_row_push
114
- html = "<table><tr></tr></table>"
115
- @t.push(Table::Row.new)
116
- assert_equal(html,@t.html.gsub(/\s+/,''))
117
- end
118
-
119
- def test_add_row_by_index
120
- html = "<table><tr></tr></table>"
121
- @t[0] = Table::Row.new
122
- assert_equal(html,@t.html.gsub(/\s+/,''))
123
- end
124
-
125
- def test_add_multiple_rows
126
- html = "<table><tr></tr><tr></tr></table>"
127
- @t.push Table::Row.new, Table::Row.new
128
- assert_equal(html,@t.html.gsub(/\s+/,''))
129
- end
130
-
131
- def test_add_single_data_element
132
- html = "<table><tr><td>hello</td></tr></table>"
133
- @t.content = "hello"
134
- assert_equal(html,@t.html.gsub(/\s+/,''))
135
- end
136
-
137
- def test_add_multiple_data_elements
138
- html = "<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>"
139
- @t.content = "hello","world"
140
- assert_equal(html,@t.html.gsub(/\s+/,''))
141
- end
142
-
143
- def test_configure_row
144
- html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
145
- html << "</table>"
146
- @t.push Table::Row::Data.new{ |d| d.content = "hello" }
147
- @t.configure(0){ |t| t.align = "center" }
148
- @t.configure(0,0){ |d| d.bgcolor = "red" }
149
- assert_equal(html,@t.html.gsub(/\s{2,}|\n+/,''))
150
- end
151
-
152
- def test_global_end_tags
153
- assert_respond_to(Table,:global_end_tags?)
154
- assert_respond_to(Table,:global_end_tags=)
155
- assert_nothing_raised{ Table.global_end_tags = false }
156
- assert_nothing_raised{ Table.global_end_tags = true }
157
- assert_raises(ArgumentTypeError){ Table.global_end_tags = "foo" }
158
- end
159
-
160
- def teardown
161
- @t = nil
162
- end
163
- end
1
+ #######################################################################
2
+ # tc_table.rb
3
+ #
4
+ # Test suite for the HTML::Table class. This test case should be run
5
+ # via the 'rake test' task.
6
+ #######################################################################
7
+ require 'test/unit'
8
+ require 'html/table'
9
+ require 'strongtyping'
10
+ include StrongTyping
11
+ include HTML
12
+
13
+ class TC_HTML_Table < Test::Unit::TestCase
14
+ def setup
15
+ @t = Table.new
16
+ end
17
+
18
+ def test_version
19
+ assert_equal('1.3.2', Table::VERSION)
20
+ end
21
+
22
+ def test_constructor
23
+ assert_nothing_raised{ Table.new }
24
+ assert_nothing_raised{ Table.new('foo') }
25
+ assert_nothing_raised{ Table.new(1) }
26
+ assert_nothing_raised{ Table.new(%w/foo bar baz/) }
27
+ assert_nothing_raised{ Table.new([1,2,3]) }
28
+ assert_nothing_raised{ Table.new([[1,2,3],['foo','bar']]) }
29
+ end
30
+
31
+ def test_html_case
32
+ assert_respond_to(Table, :html_case)
33
+ assert_respond_to(Table, :html_case=)
34
+ assert_nothing_raised{ Table.html_case = 'upper' }
35
+ assert_nothing_raised{ Table.html_case = 'lower' }
36
+ assert_raises(ArgumentError){ Table.html_case = 'foo' }
37
+ assert_raises(ArgumentTypeError){ Table.html_case = 7 }
38
+ end
39
+
40
+ def test_indent_level
41
+ assert_respond_to(Table, :indent_level)
42
+ assert_respond_to(Table, :indent_level=)
43
+ assert_nothing_raised{ Table.indent_level = 0 }
44
+ assert_raises(ArgumentTypeError){ Table.indent_level = 'foo' }
45
+ end
46
+
47
+ def test_index
48
+ assert_raises(ArgumentTypeError){ @t[0] = 'foo' }
49
+ end
50
+
51
+ def test_caption_index_constraints
52
+ assert_nothing_raised{ @t[0] = Table::Caption.new }
53
+ assert_raises(ArgumentError){ @t[1] = Table::Caption.new }
54
+ end
55
+
56
+ def test_head_index_constraints
57
+ assert_nothing_raised{ @t[0] = Table::Head.create }
58
+ assert_raises(ArgumentError){ @t[1] = Table::Head.create }
59
+ assert_raises(ArgumentError){ @t[2] = Table::Head.create }
60
+ end
61
+
62
+ def test_foot_index_constraints
63
+ assert_nothing_raised{
64
+ @t[0] = Table::Caption.new
65
+ @t[-1] = Table::Foot.create
66
+ }
67
+ assert_raises(ArgumentError){ @t[0] = Table::Foot.create }
68
+ end
69
+
70
+ def test_unshift_constraints
71
+ assert_nothing_raised{ @t.unshift Table::Row.new }
72
+ assert_raises(ArgumentTypeError){ @t.unshift Table::Row::Data.new }
73
+ assert_raises(ArgumentTypeError){ @t.unshift 'foo' }
74
+ end
75
+
76
+ def test_push_constraints
77
+ assert_nothing_raised{ @t.push Table::Row.new }
78
+ assert_raises(ArgumentTypeError){ @t.push('foo') }
79
+ assert_raises(ArgumentTypeError){ @t.push(7) }
80
+ assert_raises(ArgumentTypeError){ @t.push(nil) }
81
+ end
82
+
83
+ def test_double_arrow_constraints
84
+ assert_nothing_raised{ @t << Table::Row.new }
85
+ assert_nothing_raised{ @t << Table::Row.new << Table::Row.new }
86
+ assert_raises(ArgumentTypeError){ @t << 'foo' }
87
+ assert_raises(ArgumentTypeError){ @t << 7 }
88
+ assert_raises(ArgumentTypeError){ @t << nil }
89
+ end
90
+
91
+ def test_basic
92
+ html = "<table>\n</table>"
93
+ assert_equal(html, @t.html)
94
+ end
95
+
96
+ def test_with_attributes
97
+ html = "<table border=1 align='left' nowrap>\n</table>"
98
+ @t.border = 1
99
+ @t.align = 'left'
100
+ @t.nowrap = true
101
+ assert_equal(html, @t.html)
102
+ end
103
+
104
+ def test_add_row_push
105
+ html = '<table><tr></tr></table>'
106
+ @t.push(Table::Row.new)
107
+ assert_equal(html, @t.html.gsub(/\s+/,''))
108
+ end
109
+
110
+ def test_add_row_by_index
111
+ html = '<table><tr></tr></table>'
112
+ @t[0] = Table::Row.new
113
+ assert_equal(html, @t.html.gsub(/\s+/,''))
114
+ end
115
+
116
+ def test_add_multiple_rows
117
+ html = '<table><tr></tr><tr></tr></table>'
118
+ @t.push Table::Row.new, Table::Row.new
119
+ assert_equal(html, @t.html.gsub(/\s+/,''))
120
+ end
121
+
122
+ def test_add_single_data_element
123
+ html = '<table><tr><td>hello</td></tr></table>'
124
+ @t.content = 'hello'
125
+ assert_equal(html, @t.html.gsub(/\s+/,''))
126
+ end
127
+
128
+ def test_add_multiple_data_elements
129
+ html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
130
+ @t.content = 'hello','world'
131
+ assert_equal(html, @t.html.gsub(/\s+/,''))
132
+ end
133
+
134
+ def test_configure_row
135
+ html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
136
+ html << '</table>'
137
+ @t.push Table::Row::Data.new{ |d| d.content = 'hello' }
138
+ @t.configure(0){ |t| t.align = 'center' }
139
+ @t.configure(0,0){ |d| d.bgcolor = 'red' }
140
+ assert_equal(html, @t.html.gsub(/\s{2,}|\n+/,''))
141
+ end
142
+
143
+ def test_global_end_tags
144
+ assert_respond_to(Table,:global_end_tags?)
145
+ assert_respond_to(Table,:global_end_tags=)
146
+ assert_nothing_raised{ Table.global_end_tags = false }
147
+ assert_nothing_raised{ Table.global_end_tags = true }
148
+ assert_raises(ArgumentTypeError){ Table.global_end_tags = 'foo' }
149
+ end
150
+
151
+ def teardown
152
+ @t = nil
153
+ end
154
+ end
@@ -1,52 +1,42 @@
1
- ################################################
2
- # tc_tablesection.rb
3
- #
4
- # Test suite for the Table::TableSection 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_TableSection < Test::Unit::TestCase
21
- def setup
22
- @t = Table.new
23
- @ts = Table::TableSection.new
24
- end
25
-
26
- def test_indent_level
27
- assert_respond_to(Table::Caption,:indent_level)
28
- assert_respond_to(Table::Caption,:indent_level=)
29
- assert_raises(ArgumentTypeError){ Table::Caption.indent_level = "foo" }
30
- assert_nothing_raised{ Table::Caption.indent_level = 3 }
31
- end
32
-
33
- def test_indices
34
- assert_raises(ArgumentTypeError){ @ts[0] = "foo" }
35
- assert_nothing_raised{ @ts[0] = Table::Row.new }
36
- end
37
-
38
- def test_push
39
- assert_raises(ArgumentTypeError){ @ts.push("foo") }
40
- assert_nothing_raised{ @ts.push(Table::Row.new) }
41
- end
42
-
43
- def test_unshift
44
- assert_raises(ArgumentTypeError){ @ts.unshift("foo") }
45
- assert_nothing_raised{ @ts.unshift(Table::Row.new) }
46
- end
47
-
48
- def teardown
49
- @t = nil
50
- @ts = nil
51
- end
52
- end
1
+ ################################################
2
+ # tc_tablesection.rb
3
+ #
4
+ # Test suite for the Table::TableSection class
5
+ ################################################
6
+ require "test/unit"
7
+ require "html/table"
8
+ include HTML
9
+
10
+ class TC_HTML_Table_TableSection < Test::Unit::TestCase
11
+ def setup
12
+ @t = Table.new
13
+ @ts = Table::TableSection.new
14
+ end
15
+
16
+ def test_indent_level
17
+ assert_respond_to(Table::Caption,:indent_level)
18
+ assert_respond_to(Table::Caption,:indent_level=)
19
+ assert_raises(ArgumentTypeError){ Table::Caption.indent_level = "foo" }
20
+ assert_nothing_raised{ Table::Caption.indent_level = 3 }
21
+ end
22
+
23
+ def test_indices
24
+ assert_raises(ArgumentTypeError){ @ts[0] = "foo" }
25
+ assert_nothing_raised{ @ts[0] = Table::Row.new }
26
+ end
27
+
28
+ def test_push
29
+ assert_raises(ArgumentTypeError){ @ts.push("foo") }
30
+ assert_nothing_raised{ @ts.push(Table::Row.new) }
31
+ end
32
+
33
+ def test_unshift
34
+ assert_raises(ArgumentTypeError){ @ts.unshift("foo") }
35
+ assert_nothing_raised{ @ts.unshift(Table::Row.new) }
36
+ end
37
+
38
+ def teardown
39
+ @t = nil
40
+ @ts = nil
41
+ end
42
+ end
@@ -1,92 +1,82 @@
1
- ############################################################################
2
- # tc_tag_handler.rb
3
- #
4
- # Test suite for the TagHandler module. For these tests, we'll use an
5
- # instance of the Table class where the module has been mixed in.
6
- ############################################################################
7
- base = File.basename(Dir.pwd)
8
-
9
- if base == 'test' || base =~ /html-table/
10
- Dir.chdir('..') if base == 'test'
11
- $LOAD_PATH.unshift(Dir.pwd)
12
- $LOAD_PATH.unshift(Dir.pwd + '/lib')
13
- $LOAD_PATH.unshift(Dir.pwd + '/lib/html')
14
- Dir.chdir('test') rescue nil
15
- end
16
-
17
- require 'test/unit'
18
- require 'html/table'
19
- include HTML
20
-
21
- class TC_TagHandler < Test::Unit::TestCase
22
- def setup
23
- @content = Table::Content.new('test')
24
- end
25
-
26
- def test_bold
27
- assert_respond_to(@content, :bold)
28
- assert_respond_to(@content, :bold=)
29
- assert_nothing_raised{ @content.bold }
30
- assert_nothing_raised{ @content.bold = true }
31
- end
32
-
33
- def test_big
34
- assert_respond_to(@content, :big)
35
- assert_respond_to(@content, :big=)
36
- assert_nothing_raised{ @content.big }
37
- assert_nothing_raised{ @content.big = true }
38
- end
39
-
40
- def test_blink
41
- assert_respond_to(@content, :blink)
42
- assert_respond_to(@content, :blink=)
43
- assert_nothing_raised{ @content.blink }
44
- assert_nothing_raised{ @content.blink = true }
45
- end
46
-
47
- def test_italic
48
- assert_respond_to(@content, :italic)
49
- assert_respond_to(@content, :italic=)
50
- assert_nothing_raised{ @content.italic }
51
- assert_nothing_raised{ @content.italic = true }
52
- end
53
-
54
- def test_strike
55
- assert_respond_to(@content, :strike)
56
- assert_respond_to(@content, :strike=)
57
- assert_nothing_raised{ @content.strike }
58
- assert_nothing_raised{ @content.strike = true }
59
- end
60
-
61
- def test_sub
62
- assert_respond_to(@content, :sub)
63
- assert_respond_to(@content, :sub)
64
- assert_nothing_raised{ @content.sub }
65
- assert_nothing_raised{ @content.sub = true }
66
- end
67
-
68
- def test_sup
69
- assert_respond_to(@content, :sup)
70
- assert_respond_to(@content, :sup)
71
- assert_nothing_raised{ @content.sup }
72
- assert_nothing_raised{ @content.sup = true }
73
- end
74
-
75
- def test_tt
76
- assert_respond_to(@content, :tt)
77
- assert_respond_to(@content, :tt)
78
- assert_nothing_raised{ @content.tt }
79
- assert_nothing_raised{ @content.tt = true }
80
- end
81
-
82
- def test_underline
83
- assert_respond_to(@content, :underline)
84
- assert_respond_to(@content, :underline)
85
- assert_nothing_raised{ @content.underline }
86
- assert_nothing_raised{ @content.underline = true }
87
- end
88
-
89
- def teardown
90
- @content = nil
91
- end
92
- end
1
+ ############################################################################
2
+ # tc_tag_handler.rb
3
+ #
4
+ # Test suite for the TagHandler module. For these tests, we'll use an
5
+ # instance of the Table class where the module has been mixed in.
6
+ ############################################################################
7
+ require 'test/unit'
8
+ require 'html/table'
9
+ include HTML
10
+
11
+ class TC_TagHandler < Test::Unit::TestCase
12
+ def setup
13
+ @content = Table::Content.new('test')
14
+ end
15
+
16
+ def test_bold
17
+ assert_respond_to(@content, :bold)
18
+ assert_respond_to(@content, :bold=)
19
+ assert_nothing_raised{ @content.bold }
20
+ assert_nothing_raised{ @content.bold = true }
21
+ end
22
+
23
+ def test_big
24
+ assert_respond_to(@content, :big)
25
+ assert_respond_to(@content, :big=)
26
+ assert_nothing_raised{ @content.big }
27
+ assert_nothing_raised{ @content.big = true }
28
+ end
29
+
30
+ def test_blink
31
+ assert_respond_to(@content, :blink)
32
+ assert_respond_to(@content, :blink=)
33
+ assert_nothing_raised{ @content.blink }
34
+ assert_nothing_raised{ @content.blink = true }
35
+ end
36
+
37
+ def test_italic
38
+ assert_respond_to(@content, :italic)
39
+ assert_respond_to(@content, :italic=)
40
+ assert_nothing_raised{ @content.italic }
41
+ assert_nothing_raised{ @content.italic = true }
42
+ end
43
+
44
+ def test_strike
45
+ assert_respond_to(@content, :strike)
46
+ assert_respond_to(@content, :strike=)
47
+ assert_nothing_raised{ @content.strike }
48
+ assert_nothing_raised{ @content.strike = true }
49
+ end
50
+
51
+ def test_sub
52
+ assert_respond_to(@content, :sub)
53
+ assert_respond_to(@content, :sub)
54
+ assert_nothing_raised{ @content.sub }
55
+ assert_nothing_raised{ @content.sub = true }
56
+ end
57
+
58
+ def test_sup
59
+ assert_respond_to(@content, :sup)
60
+ assert_respond_to(@content, :sup)
61
+ assert_nothing_raised{ @content.sup }
62
+ assert_nothing_raised{ @content.sup = true }
63
+ end
64
+
65
+ def test_tt
66
+ assert_respond_to(@content, :tt)
67
+ assert_respond_to(@content, :tt)
68
+ assert_nothing_raised{ @content.tt }
69
+ assert_nothing_raised{ @content.tt = true }
70
+ end
71
+
72
+ def test_underline
73
+ assert_respond_to(@content, :underline)
74
+ assert_respond_to(@content, :underline)
75
+ assert_nothing_raised{ @content.underline }
76
+ assert_nothing_raised{ @content.underline = true }
77
+ end
78
+
79
+ def teardown
80
+ @content = nil
81
+ end
82
+ end