html-table 1.3.6 → 1.4.0

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/test_foot.rb CHANGED
@@ -5,10 +5,7 @@
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 'rubygems'
9
- gem 'test-unit'
10
-
11
- require 'test/unit'
8
+ require 'test-unit'
12
9
  require 'html/table'
13
10
  include HTML
14
11
 
@@ -41,7 +38,7 @@ class TC_HTML_Table_Foot < Test::Unit::TestCase
41
38
  assert_nothing_raised{ Table::Foot.create([1,2,3]) }
42
39
  assert_nothing_raised{ Table::Foot.create([[1,2,3], ["foo","bar"]]) }
43
40
  end
44
-
41
+
45
42
  def test_basic
46
43
  html = "<tfoot></tfoot>"
47
44
  assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
@@ -66,7 +63,7 @@ class TC_HTML_Table_Foot < Test::Unit::TestCase
66
63
  @tfoot.char = 'x'
67
64
  assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
68
65
  end
69
-
66
+
70
67
  def test_push_single_row
71
68
  html = "<tfoot><tr><td>test</td></tr></tfoot>"
72
69
  @tfoot.push Table::Row.new{|r| r.content = "test"}
@@ -80,7 +77,7 @@ class TC_HTML_Table_Foot < Test::Unit::TestCase
80
77
  @tfoot.push r1, r2
81
78
  assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n/,''))
82
79
  end
83
-
80
+
84
81
  def test_add_content_directly
85
82
  html = "<tfoot><tr><td>hello</td><td>world</td></tr></tfoot>"
86
83
  @tfoot.content = "hello","world"
@@ -93,7 +90,7 @@ class TC_HTML_Table_Foot < Test::Unit::TestCase
93
90
  @tfoot = Table::Foot.create(["hello","world"])
94
91
  assert_equal(html, @tfoot.html.gsub(/\s{2,}|\n+/,''))
95
92
  end
96
-
93
+
97
94
  def test_configure_column
98
95
  html = "<tfoot><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
99
96
  html += "</td></tr></tfoot>"
data/test/test_head.rb CHANGED
@@ -5,10 +5,7 @@
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 'rubygems'
9
- gem 'test-unit'
10
-
11
- require 'test/unit'
8
+ require 'test-unit'
12
9
  require 'html/table'
13
10
  include HTML
14
11
 
@@ -37,7 +34,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
37
34
  assert_nothing_raised{ Table::Head.create([1,2,3]) }
38
35
  assert_nothing_raised{ Table::Head.create([[1,2,3],["foo","bar"]]) }
39
36
  end
40
-
37
+
41
38
  def test_basic
42
39
  html = "<thead></thead>"
43
40
  assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
@@ -59,7 +56,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
59
56
  @thead.char = 'x'
60
57
  assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
61
58
  end
62
-
59
+
63
60
  def test_push_single_row
64
61
  html = "<thead><tr><td>test</td></tr></thead>"
65
62
  @thead.push Table::Row.new{|r| r.content = "test"}
@@ -73,7 +70,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
73
70
  @thead.push(r1, r2)
74
71
  assert_equal(html,@thead.html.gsub(/\s{2,}|\n/,''))
75
72
  end
76
-
73
+
77
74
  def test_add_content_directly
78
75
  html = "<thead><tr><td>hello</td><td>world</td></tr></thead>"
79
76
  @thead.content = "hello","world"
@@ -86,7 +83,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
86
83
  @thead = Table::Head.create(["hello","world"])
87
84
  assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
88
85
  end
89
-
86
+
90
87
  def test_configure_column
91
88
  html = "<thead><tr><td>hello</td><td abbr='test' width=3 nowrap>world"
92
89
  html += "</td></tr></thead>"
@@ -98,7 +95,7 @@ class TC_HTML_Table_Head < Test::Unit::TestCase
98
95
  }
99
96
  assert_equal(html,@thead.html.gsub(/\s{2,}|\n+/,''))
100
97
  end
101
-
98
+
102
99
  def teardown
103
100
  @table = nil
104
101
  @thead.send(:refresh)
data/test/test_header.rb CHANGED
@@ -3,10 +3,7 @@
3
3
  #
4
4
  # Test suite for the Table::Row::Header class
5
5
  ################################################
6
- require 'rubygems'
7
- gem 'test-unit'
8
-
9
- require 'test/unit'
6
+ require 'test-unit'
10
7
  require 'html/table'
11
8
  include HTML
12
9
 
@@ -14,7 +11,7 @@ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
14
11
  def setup
15
12
  @theader = Table::Row::Header.new
16
13
  end
17
-
14
+
18
15
  def test_basic
19
16
  html = "<th></th>"
20
17
  assert_equal(html, @theader.html.gsub(/\s+/,''))
@@ -36,17 +33,17 @@ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
36
33
  @theader.nowrap = true
37
34
  assert_equal(html, @theader.html.gsub(/\s{2,}|\n+/,''))
38
35
  end
39
-
36
+
40
37
  def test_configure_not_allowed
41
38
  assert_raises(NoMethodError){ @theader.configure }
42
39
  end
43
-
40
+
44
41
  def test_add_content
45
42
  html = "<th>hello world</th>"
46
43
  @theader.content = "hello world"
47
44
  assert_equal(html, @theader.html.gsub(/\s{2,}/,''))
48
45
  end
49
-
46
+
50
47
  def test_add_multiple_content_items
51
48
  html = "<th>hello world</th>"
52
49
  @theader.content = "hello"," world"
@@ -73,7 +70,7 @@ class TC_HTML_Table_Row_Header < Test::Unit::TestCase
73
70
  assert_raises(ArgumentTypeError){ Table::Row::Header.end_tags = 1 }
74
71
  assert_nothing_raised{ Table::Row::Header.end_tags = true }
75
72
  end
76
-
73
+
77
74
  def teardown
78
75
  @theader = nil
79
76
  end
@@ -4,10 +4,7 @@
4
4
  # Test suite for the HtmlHandler module. For these tests, we'll use an
5
5
  # instance of the Table class where the module has been mixed in.
6
6
  ############################################################################
7
- require 'rubygems'
8
- gem 'test-unit'
9
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'html/table'
12
9
  include HTML
13
10
 
@@ -15,7 +12,7 @@ class TC_HtmlHandler < Test::Unit::TestCase
15
12
  def setup
16
13
  @table = Table.new(["foo",1,"bar"])
17
14
  end
18
-
15
+
19
16
  def test_html
20
17
  assert_respond_to(@table, :html)
21
18
  assert_nothing_raised{ @table.html }
@@ -23,7 +20,7 @@ class TC_HtmlHandler < Test::Unit::TestCase
23
20
  assert_kind_of(String, @table.html)
24
21
  assert_equal(true, @table.html.length > 0)
25
22
  end
26
-
23
+
27
24
  def test_modify_html
28
25
  assert_raises(ArgumentError){ @table.send(:modify_html) }
29
26
  assert_nothing_raised{ @table.send(:modify_html,"nowrap") }
@@ -32,8 +29,8 @@ class TC_HtmlHandler < Test::Unit::TestCase
32
29
  @table.send(:modify_html,"align","top")
33
30
  @table.send(:modify_html,"align","top")
34
31
  }
35
- end
36
-
32
+ end
33
+
37
34
  def teardown
38
35
  @table = nil
39
36
  end
data/test/test_row.rb CHANGED
@@ -3,10 +3,7 @@
3
3
  #
4
4
  # Test suite for the Table::Row class
5
5
  ############################################
6
- require 'rubygems'
7
- gem 'test-unit'
8
-
9
- require 'test/unit'
6
+ require 'test-unit'
10
7
  require 'html/table'
11
8
  include HTML
12
9
 
@@ -22,7 +19,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
22
19
  assert_nothing_raised{ Table::Row.new([1,2,3]) }
23
20
  assert_nothing_raised{ Table::Row.new([[1,2,3],["foo","bar"]]) }
24
21
  end
25
-
22
+
26
23
  def test_basic
27
24
  html = "<tr></tr>"
28
25
  assert_equal(html,@trow.html.gsub(/\s+/,''))
@@ -34,7 +31,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
34
31
  assert_nothing_raised{ @trow.header? }
35
32
  assert_nothing_raised{ @trow.header = true }
36
33
  end
37
-
34
+
38
35
  def test_with_attributes
39
36
  html = "<tr align='center'></tr>"
40
37
  @trow.align = "center"
@@ -72,7 +69,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
72
69
  html = "<tr><th>test</th></tr>"
73
70
  assert_equal(html, @trow.html.gsub(/\s+/,''))
74
71
  end
75
-
72
+
76
73
  def test_push_single_data_element
77
74
  html = "<tr><td>hello</td></tr>"
78
75
  @trow.push Table::Row::Data.new{ |d| d.content = "hello" }
@@ -86,7 +83,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
86
83
  @trow.push d1, d2
87
84
  assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
88
85
  end
89
-
86
+
90
87
  def test_add_content_directly
91
88
  html = "<tr><td>hello</td><td>world</td></tr>"
92
89
  @trow.content = "hello","world"
@@ -98,7 +95,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
98
95
  @trow = Table::Row.new(%w/hello world/)
99
96
  assert_equal(html, @trow.html.gsub(/\s{2,}|\n+/,''))
100
97
  end
101
-
98
+
102
99
  def test_configure_column
103
100
  html = "<tr><td>hello</td><td abbr='test' width=3 nowrap>world</td></tr>"
104
101
  @trow.content = "hello","world"
@@ -118,7 +115,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
118
115
  assert_nothing_raised{ @trow.unshift(Table::Row::Data.new) }
119
116
  assert_nothing_raised{ @trow.unshift(Table::Row::Header.new) }
120
117
  end
121
-
118
+
122
119
  def test_configure_error
123
120
  assert_raises(ArgumentError){ @trow.configure(0,0){ } }
124
121
  end
@@ -137,7 +134,7 @@ class TC_HTML_Table_Row < Test::Unit::TestCase
137
134
  assert_raises(ArgumentTypeError){ Table::Row.end_tags = 1 }
138
135
  assert_nothing_raised{ Table::Row.end_tags = true }
139
136
  end
140
-
137
+
141
138
  def teardown
142
139
  @trow = nil
143
140
  end
data/test/test_table.rb CHANGED
@@ -4,154 +4,155 @@
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
-
10
- require 'test/unit'
7
+ require 'test-unit'
11
8
  require 'html/table'
12
9
  require 'strongtyping'
13
10
  include StrongTyping
14
11
  include HTML
15
12
 
16
13
  class TC_HTML_Table < Test::Unit::TestCase
17
- def setup
18
- @table = Table.new
19
- end
20
-
21
- def test_version
22
- assert_equal('1.3.6', Table::VERSION)
23
- end
24
-
25
- def test_constructor
26
- assert_nothing_raised{ Table.new }
27
- assert_nothing_raised{ Table.new('foo') }
28
- assert_nothing_raised{ Table.new(1) }
29
- assert_nothing_raised{ Table.new(%w/foo bar baz/) }
30
- assert_nothing_raised{ Table.new([1,2,3]) }
31
- assert_nothing_raised{ Table.new([[1,2,3],['foo','bar']]) }
32
- end
33
-
34
- def test_html_case
35
- assert_respond_to(Table, :html_case)
36
- assert_respond_to(Table, :html_case=)
37
- assert_nothing_raised{ Table.html_case = 'upper' }
38
- assert_nothing_raised{ Table.html_case = 'lower' }
39
- assert_raises(ArgumentError){ Table.html_case = 'foo' }
40
- assert_raises(ArgumentTypeError){ Table.html_case = 7 }
41
- end
42
-
43
- def test_indent_level
44
- assert_respond_to(Table, :indent_level)
45
- assert_respond_to(Table, :indent_level=)
46
- assert_nothing_raised{ Table.indent_level = 0 }
47
- assert_raises(ArgumentTypeError){ Table.indent_level = 'foo' }
48
- end
49
-
50
- def test_index
51
- assert_raises(ArgumentTypeError){ @table[0] = 'foo' }
52
- end
53
-
54
- def test_caption_index_constraints
55
- assert_nothing_raised{ @table[0] = Table::Caption.new }
56
- assert_raises(ArgumentError){ @table[1] = Table::Caption.new }
57
- end
58
-
59
- def test_head_index_constraints
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 }
63
- end
64
-
65
- def test_foot_index_constraints
66
- assert_nothing_raised{
67
- @table[0] = Table::Caption.new
68
- @table[-1] = Table::Foot.create
69
- }
70
- assert_raises(ArgumentError){ @table[0] = Table::Foot.create }
71
- end
72
-
73
- def test_unshift_constraints
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' }
77
- end
78
-
79
- def test_push_constraints
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) }
84
- end
85
-
86
- def test_double_arrow_constraints
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 }
92
- end
93
-
94
- def test_basic
95
- html = "<table>\n</table>"
96
- assert_equal(html, @table.html)
97
- end
98
-
99
- def test_with_attributes
100
- html = "<table border=1 align='left' nowrap>\n</table>"
101
- @table.border = 1
102
- @table.align = 'left'
103
- @table.nowrap = true
104
- assert_equal(html, @table.html)
105
- end
106
-
107
- def test_add_row_push
108
- html = '<table><tr></tr></table>'
109
- @table.push(Table::Row.new)
110
- assert_equal(html, @table.html.gsub(/\s+/,''))
111
- end
112
-
113
- def test_add_row_by_index
114
- html = '<table><tr></tr></table>'
115
- @table[0] = Table::Row.new
116
- assert_equal(html, @table.html.gsub(/\s+/,''))
117
- end
118
-
119
- def test_add_multiple_rows
120
- html = '<table><tr></tr><tr></tr></table>'
121
- @table.push Table::Row.new, Table::Row.new
122
- assert_equal(html, @table.html.gsub(/\s+/,''))
123
- end
124
-
125
- def test_add_single_data_element
126
- html = '<table><tr><td>hello</td></tr></table>'
127
- @table.content = 'hello'
128
- assert_equal(html, @table.html.gsub(/\s+/,''))
129
- end
130
-
131
- def test_add_multiple_data_elements
132
- html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
133
- @table.content = 'hello','world'
134
- assert_equal(html, @table.html.gsub(/\s+/,''))
135
- end
136
-
137
- def test_configure_row
138
- html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
139
- html << '</table>'
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+/,''))
144
- end
145
-
146
- def test_global_end_tags
147
- assert_respond_to(Table,:global_end_tags?)
148
- assert_respond_to(Table,:global_end_tags=)
149
- assert_nothing_raised{ Table.global_end_tags = false }
150
- assert_nothing_raised{ Table.global_end_tags = true }
151
- assert_raises(ArgumentTypeError){ Table.global_end_tags = 'foo' }
152
- end
153
-
154
- def teardown
155
- @table = nil
156
- end
14
+ def setup
15
+ @table = Table.new
16
+ end
17
+
18
+ def test_version
19
+ assert_equal('1.4.0', 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_constructor_with_attributes
32
+ assert_nothing_raised{ Table.new(%w[foo bar baz], :border => 1) }
33
+ end
34
+
35
+ def test_html_case
36
+ assert_respond_to(Table, :html_case)
37
+ assert_respond_to(Table, :html_case=)
38
+ assert_nothing_raised{ Table.html_case = 'upper' }
39
+ assert_nothing_raised{ Table.html_case = 'lower' }
40
+ assert_raises(ArgumentError){ Table.html_case = 'foo' }
41
+ assert_raises(ArgumentTypeError){ Table.html_case = 7 }
42
+ end
43
+
44
+ def test_indent_level
45
+ assert_respond_to(Table, :indent_level)
46
+ assert_respond_to(Table, :indent_level=)
47
+ assert_nothing_raised{ Table.indent_level = 0 }
48
+ assert_raises(ArgumentTypeError){ Table.indent_level = 'foo' }
49
+ end
50
+
51
+ def test_index
52
+ assert_raises(ArgumentTypeError){ @table[0] = 'foo' }
53
+ end
54
+
55
+ def test_caption_index_constraints
56
+ assert_nothing_raised{ @table[0] = Table::Caption.new }
57
+ assert_raises(ArgumentError){ @table[1] = Table::Caption.new }
58
+ end
59
+
60
+ def test_head_index_constraints
61
+ assert_nothing_raised{ @table[0] = Table::Head.create }
62
+ assert_raises(ArgumentError){ @table[1] = Table::Head.create }
63
+ assert_raises(ArgumentError){ @table[2] = Table::Head.create }
64
+ end
65
+
66
+ def test_foot_index_constraints
67
+ assert_nothing_raised{
68
+ @table[0] = Table::Caption.new
69
+ @table[-1] = Table::Foot.create
70
+ }
71
+ assert_raises(ArgumentError){ @table[0] = Table::Foot.create }
72
+ end
73
+
74
+ def test_unshift_constraints
75
+ assert_nothing_raised{ @table.unshift Table::Row.new }
76
+ assert_raises(ArgumentTypeError){ @table.unshift Table::Row::Data.new }
77
+ assert_raises(ArgumentTypeError){ @table.unshift 'foo' }
78
+ end
79
+
80
+ def test_push_constraints
81
+ assert_nothing_raised{ @table.push Table::Row.new }
82
+ assert_raises(ArgumentTypeError){ @table.push('foo') }
83
+ assert_raises(ArgumentTypeError){ @table.push(7) }
84
+ assert_raises(ArgumentTypeError){ @table.push(nil) }
85
+ end
86
+
87
+ def test_double_arrow_constraints
88
+ assert_nothing_raised{ @table << Table::Row.new }
89
+ assert_nothing_raised{ @table << Table::Row.new << Table::Row.new }
90
+ assert_raises(ArgumentTypeError){ @table << 'foo' }
91
+ assert_raises(ArgumentTypeError){ @table << 7 }
92
+ assert_raises(ArgumentTypeError){ @table << nil }
93
+ end
94
+
95
+ def test_basic
96
+ html = "<table>\n</table>"
97
+ assert_equal(html, @table.html)
98
+ end
99
+
100
+ def test_with_attributes
101
+ html = "<table border=1 align='left' nowrap>\n</table>"
102
+ @table.border = 1
103
+ @table.align = 'left'
104
+ @table.nowrap = true
105
+ assert_equal(html, @table.html)
106
+ end
107
+
108
+ def test_add_row_push
109
+ html = '<table><tr></tr></table>'
110
+ @table.push(Table::Row.new)
111
+ assert_equal(html, @table.html.gsub(/\s+/,''))
112
+ end
113
+
114
+ def test_add_row_by_index
115
+ html = '<table><tr></tr></table>'
116
+ @table[0] = Table::Row.new
117
+ assert_equal(html, @table.html.gsub(/\s+/,''))
118
+ end
119
+
120
+ def test_add_multiple_rows
121
+ html = '<table><tr></tr><tr></tr></table>'
122
+ @table.push Table::Row.new, Table::Row.new
123
+ assert_equal(html, @table.html.gsub(/\s+/,''))
124
+ end
125
+
126
+ def test_add_single_data_element
127
+ html = '<table><tr><td>hello</td></tr></table>'
128
+ @table.content = 'hello'
129
+ assert_equal(html, @table.html.gsub(/\s+/,''))
130
+ end
131
+
132
+ def test_add_multiple_data_elements
133
+ html = '<table><tr><td>hello</td></tr><tr><td>world</td></tr></table>'
134
+ @table.content = 'hello','world'
135
+ assert_equal(html, @table.html.gsub(/\s+/,''))
136
+ end
137
+
138
+ def test_configure_row
139
+ html = "<table><tr align='center'><td bgcolor='red'>hello</td></tr>"
140
+ html << '</table>'
141
+ @table.push Table::Row::Data.new{ |d| d.content = 'hello' }
142
+ @table.configure(0){ |t| t.align = 'center' }
143
+ @table.configure(0,0){ |d| d.bgcolor = 'red' }
144
+ assert_equal(html, @table.html.gsub(/\s{2,}|\n+/,''))
145
+ end
146
+
147
+ def test_global_end_tags
148
+ assert_respond_to(Table,:global_end_tags?)
149
+ assert_respond_to(Table,:global_end_tags=)
150
+ assert_nothing_raised{ Table.global_end_tags = false }
151
+ assert_nothing_raised{ Table.global_end_tags = true }
152
+ assert_raises(ArgumentTypeError){ Table.global_end_tags = 'foo' }
153
+ end
154
+
155
+ def teardown
156
+ @table = nil
157
+ end
157
158
  end