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