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.
@@ -1,12 +1,15 @@
1
1
  ###############################################################################
2
- # tc_head.rb
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 "test/unit"
9
- require "html/table"
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
- @t = Table.new
26
- @th = Table::Head.create
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,@th.html.gsub(/\s{2,}|\n/,''))
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
- @th.align = "left"
56
- @th.char = 'x'
57
- assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
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
- @th.push Table::Row.new{|r| r.content = "test"}
63
- assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
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
- @th.push(r1, r2)
71
- assert_equal(html,@th.html.gsub(/\s{2,}|\n/,''))
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
- @th.content = "hello","world"
77
- assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
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
- @th.send(:refresh)
83
- @th = Table::Head.create(["hello","world"])
84
- assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
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
- @th.content = "hello","world"
91
- @th.configure(0,1){ |d|
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,@th.html.gsub(/\s{2,}|\n+/,''))
99
+ assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
97
100
  end
98
101
 
99
102
  def teardown
100
- @t = nil
101
- @th.send(:refresh)
102
- @th = nil
103
+ @table = nil
104
+ @thead.send(:refresh)
105
+ @thead = nil
103
106
  end
104
107
  end
@@ -1,20 +1,23 @@
1
1
  ################################################
2
- # tc_header.rb
2
+ # test_header.rb
3
3
  #
4
4
  # Test suite for the Table::Row::Header class
5
5
  ################################################
6
- require "test/unit"
7
- require "html/table"
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
- @th = Table::Row::Header.new
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,@th.html.gsub(/\s+/,''))
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
- @th.align = 'left'
32
- @th.colspan = 3
33
- @th.nowrap = true
34
- assert_equal(html,@th.html.gsub(/\s{2,}|\n+/,''))
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){ @th.configure }
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
- @th.content = "hello world"
44
- assert_equal(html,@th.html.gsub(/\s{2,}/,''))
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
- @th.content = "hello"," world"
50
- assert_equal(html,@th.html.gsub(/\s{2,}/,''))
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
- th = Table::Row::Header.new("hello world")
56
- assert_equal(html,th.html.gsub(/\s{2,}/,''))
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
- @th = nil
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
- # tc_table.rb
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
- @t = Table.new
18
+ @table = Table.new
16
19
  end
17
20
 
18
21
  def test_version
19
- assert_equal('1.3.2', Table::VERSION)
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){ @t[0] = 'foo' }
51
+ assert_raises(ArgumentTypeError){ @table[0] = 'foo' }
49
52
  end
50
53
 
51
54
  def test_caption_index_constraints
52
- assert_nothing_raised{ @t[0] = Table::Caption.new }
53
- assert_raises(ArgumentError){ @t[1] = Table::Caption.new }
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{ @t[0] = Table::Head.create }
58
- assert_raises(ArgumentError){ @t[1] = Table::Head.create }
59
- assert_raises(ArgumentError){ @t[2] = Table::Head.create }
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
- @t[0] = Table::Caption.new
65
- @t[-1] = Table::Foot.create
67
+ @table[0] = Table::Caption.new
68
+ @table[-1] = Table::Foot.create
66
69
  }
67
- assert_raises(ArgumentError){ @t[0] = Table::Foot.create }
70
+ assert_raises(ArgumentError){ @table[0] = Table::Foot.create }
68
71
  end
69
72
 
70
73
  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
+ 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{ @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) }
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{ @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 }
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, @t.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
- @t.border = 1
99
- @t.align = 'left'
100
- @t.nowrap = true
101
- assert_equal(html, @t.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
- @t.push(Table::Row.new)
107
- assert_equal(html, @t.html.gsub(/\s+/,''))
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
- @t[0] = Table::Row.new
113
- assert_equal(html, @t.html.gsub(/\s+/,''))
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
- @t.push Table::Row.new, Table::Row.new
119
- assert_equal(html, @t.html.gsub(/\s+/,''))
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
- @t.content = 'hello'
125
- assert_equal(html, @t.html.gsub(/\s+/,''))
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
- @t.content = 'hello','world'
131
- assert_equal(html, @t.html.gsub(/\s+/,''))
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
- @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+/,''))
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
- @t = nil
155
+ @table = nil
153
156
  end
154
157
  end