rexcel 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,154 @@
1
+ #encoding: UTF-8
2
+ #~ gem 'test-unit', ">= 2.1.2" #tested with this version
3
+ require_relative 'rexcel_test_helper'
4
+
5
+ class Test_Worksheet < Test::Unit::TestCase
6
+ def test_init
7
+ ws = Excel::Worksheet.new()
8
+ assert_equal('Sheet', ws.name)
9
+ assert_equal([], ws.rows)
10
+ #~ assert_equal({}, ws.columns) #only internal.
11
+ end #def test_init
12
+ def test_add_title_row
13
+ ws = Excel::Worksheet.new()
14
+ assert_raise(ArgumentError){ ws.add_title_row(:xx) } #no #each
15
+ assert_raise(ArgumentError){ ws.add_title_row([]) } #wrong type
16
+ assert_raise(ArgumentError){ ws.add_title_row({}) } #empty
17
+
18
+ assert_raise(ArgumentError){ ws.add_title_row() }#no columns defined
19
+
20
+ title_row = ws.add_title_row({ 1 => Excel::Column.new(1), 2=> Excel::Column.new(2)})
21
+ assert_instance_of(Excel::Row, title_row)
22
+ assert_equal(2, title_row.columns.size)
23
+
24
+ end
25
+ end #class Test_Worksheet
26
+
27
+ class Test_Worksheet_insertions < Test::Unit::TestCase
28
+ def setup()
29
+ @mock = Mock_document.new
30
+ end
31
+ def test_insert_array
32
+ ws = Excel::Worksheet.new()
33
+ assert_equal(0, ws.rows.size)
34
+ assert_raise(Excel::EmptyError){
35
+ @mock.testcase{|builder, ns_proc|
36
+ ws.to_xml( builder,ns_proc)
37
+ }}
38
+ assert_nothing_raised{ ws << [:a,:b,:c,:d] }
39
+ assert_equal(1, ws.rows.size)
40
+ assert_equal(%{<ss:Worksheet ss:Name="Sheet">
41
+ <ss:Table>
42
+ <ss:Row>
43
+ <ss:Cell>
44
+ <ss:Data ss:Type="String">a</ss:Data>
45
+ </ss:Cell>
46
+ <ss:Cell>
47
+ <ss:Data ss:Type="String">b</ss:Data>
48
+ </ss:Cell>
49
+ <ss:Cell>
50
+ <ss:Data ss:Type="String">c</ss:Data>
51
+ </ss:Cell>
52
+ <ss:Cell>
53
+ <ss:Data ss:Type="String">d</ss:Data>
54
+ </ss:Cell>
55
+ </ss:Row>
56
+ </ss:Table>
57
+ </ss:Worksheet>},
58
+ @mock.testcase{|builder, ns_proc|
59
+ ws.to_xml( builder,ns_proc)
60
+ })
61
+ assert_nothing_raised{ ws << [:a,:b,:c,:d] }
62
+ end
63
+ def test_insert_row()
64
+ ws = Excel::Worksheet.new()
65
+ assert_equal(0, ws.rows.size)
66
+ assert_nothing_raised{ ws << ( Excel::Row.new() << 'a') }
67
+ assert_equal(1, ws.rows.size)
68
+ assert_equal(%{<ss:Worksheet ss:Name="Sheet">
69
+ <ss:Table>
70
+ <ss:Row>
71
+ <ss:Cell>
72
+ <ss:Data ss:Type="String">a</ss:Data>
73
+ </ss:Cell>
74
+ </ss:Row>
75
+ </ss:Table>
76
+ </ss:Worksheet>},
77
+ @mock.testcase{|builder, ns_proc|
78
+ ws.to_xml( builder,ns_proc)
79
+ })
80
+ end
81
+ def test_insert_hash()
82
+ ws = Excel::Worksheet.new()
83
+ assert_equal(0, ws.rows.size)
84
+ #Hash requires Heading data
85
+ assert_raise( ArgumentError ){ ws << { 1 => :a, 2 => :b, 3 => :c } }
86
+ assert_equal(0, ws.rows.size)
87
+
88
+ ws << Excel::Column.new(1)
89
+ ws << Excel::Column.new(2)
90
+
91
+ assert_nothing_raised{ ws << { 1 => :a, 2 => :b, 3 => :c } }
92
+ assert_equal(1, ws.rows.size)
93
+ assert_equal(%{<ss:Worksheet ss:Name="Sheet">
94
+ <ss:Table>
95
+ <ss:Column/>
96
+ <ss:Column/>
97
+ <ss:Row>
98
+ <ss:Cell>
99
+ <ss:Data ss:Type="String">a</ss:Data>
100
+ </ss:Cell>
101
+ <ss:Cell>
102
+ <ss:Data ss:Type="String">b</ss:Data>
103
+ </ss:Cell>
104
+ </ss:Row>
105
+ </ss:Table>
106
+ </ss:Worksheet>},
107
+ @mock.testcase{|builder, ns_proc|
108
+ ws.to_xml( builder,ns_proc)
109
+ })
110
+ end #def test_insert_hash()
111
+ end #class Test_Worksheet_insertion
112
+
113
+ class Test_Worksheet_to_csv < Test::Unit::TestCase
114
+ def setup()
115
+ @ws = Excel::Worksheet.new()
116
+ @ws << [:a,:b,:c,:d]
117
+ @ws << %w{a b c d}
118
+ @ws << [1,2,3,4]
119
+ @ws << [1.1,2.2,3.3,4.4]
120
+ #~ @ws << %w{1,1 2,2 3,3 4,4}
121
+ end
122
+ def teardown()
123
+ end
124
+ def test_to_csv
125
+ assert_equal(%{a;b;c;d\na;b;c;d\n1;2;3;4\n="1.1";="2.2";="3.3";="4.4"}, @ws.to_csv())
126
+ end
127
+ def test_to_csv_sep
128
+ assert_equal(%{a\tb\tc\td\na\tb\tc\td\n1\t2\t3\t4\n="1.1"\t="2.2"\t="3.3"\t="4.4"}, @ws.to_csv(:sep => "\t"))
129
+ assert_equal(%{a,b,c,d\na,b,c,d\n1,2,3,4\n="1.1",="2.2",="3.3",="4.4"}, @ws.to_csv(:sep => ','))
130
+
131
+ assert_raise(ArgumentError){@ws.to_csv(:sep => 'a')}
132
+ end
133
+
134
+ def test_filename()
135
+ filename = "#{self.class.name}-#{__method__}.csv"
136
+ File.delete(filename) if File.exist?(filename)
137
+ assert_false(File.exist?(filename))
138
+ @ws.to_csv(:filename => filename)
139
+ assert_true(File.exist?(filename))
140
+ assert_equal_filecontent(File.join('expected', filename), @ws.to_csv)
141
+ #~ assert_equal_filecontent(File.join('expected', filename), File.read(filename, :encoding => 'UTF-16LE'))
142
+ File.delete(filename)
143
+ end
144
+
145
+ def test_filename_encoding()
146
+ filename = "#{self.class.name}-#{__method__}.csv"
147
+ File.delete(filename) if File.exist?(filename)
148
+ assert_false(File.exist?(filename))
149
+ @ws.to_csv(:filename => filename, :encoding => 'utf-8')
150
+ assert_true(File.exist?(filename))
151
+ assert_equal_filecontent(File.join('expected', filename), File.read(filename, :encoding => 'UTF-8'))
152
+ File.delete(filename)
153
+ end
154
+ end #class Test_Worksheet_to_csv
metadata CHANGED
@@ -1,80 +1,58 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rexcel
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Knut Lickert
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-07 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-18 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: nokogiri
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &11026188 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: log4r
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *11026188
25
+ - !ruby/object:Gem::Dependency
26
+ name: log4r
27
+ requirement: &11025780 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 1
46
- - 1
47
- - 8
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
48
32
  version: 1.1.8
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: more_unit_test
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *11025780
36
+ - !ruby/object:Gem::Dependency
37
+ name: more_unit_test
38
+ requirement: &11025276 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 25
60
- segments:
61
- - 0
62
- - 1
63
- - 1
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
64
43
  version: 0.1.1
65
44
  type: :development
66
- version_requirements: *id003
67
- description: |
68
- Build excel documents with Ruby/Winole
45
+ prerelease: false
46
+ version_requirements: *11025276
47
+ description: ! 'Build excel documents with Ruby/Winole
69
48
 
49
+ '
70
50
  email: knut@lickert.net
71
51
  executables: []
72
-
73
52
  extensions: []
74
-
75
53
  extra_rdoc_files: []
76
-
77
- files:
54
+ files:
55
+ - readme.rdoc
78
56
  - lib/rexcel.rb
79
57
  - lib/rexcel/workbook.rb
80
58
  - lib/rexcel/worksheet.rb
@@ -85,56 +63,65 @@ files:
85
63
  - examples/example.rb
86
64
  - examples/example_format.rb
87
65
  - examples/example_color.rb
66
+ - examples/example_sequel.rb
88
67
  - benchmark/rexcel_benchmark.rb
68
+ - unittest/rexcel_test_helper.rb
89
69
  - unittest/test_rexcel.rb
70
+ - unittest/test_rexcel_cell.rb
71
+ - unittest/test_rexcel_row.rb
72
+ - unittest/test_rexcel_worksheet.rb
73
+ - unittest/test_rexcel_workbook.rb
90
74
  - unittest/expected/Test_Style_xlm-test_backgroundcolor-gray.xml
91
75
  - unittest/expected/Test_Style_xlm-test_bold-bold.xml
92
76
  - unittest/expected/Test_Style_xlm-test_color-gray.xml
93
77
  - unittest/expected/Test_Style_xlm-test_italic-italic.xml
94
78
  - unittest/expected/Test_workbook-test_save_xml.xml
95
- has_rdoc: true
79
+ - unittest/expected/Test_Workbook_to_csv-test_filename.csv
80
+ - unittest/expected/Test_Workbook_to_csv-test_filename_encoding.csv
81
+ - unittest/expected/Test_Worksheet_to_csv-test_filename.csv
82
+ - unittest/expected/Test_Worksheet_to_csv-test_filename_encoding.csv
96
83
  homepage: http://forum.ruby-portal.de/viewtopic.php?f=22&t=11746
97
84
  licenses: []
98
-
99
85
  post_install_message:
100
- rdoc_options:
86
+ rdoc_options:
101
87
  - --main
102
88
  - lib/rexcel.rb
103
- require_paths:
89
+ require_paths:
104
90
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
106
92
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 49
111
- segments:
112
- - 1
113
- - 9
114
- - 1
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
115
96
  version: 1.9.1
116
- required_rubygems_version: !ruby/object:Gem::Requirement
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
98
  none: false
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- hash: 3
122
- segments:
123
- - 0
124
- version: "0"
125
- requirements:
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements:
126
104
  - MS Excel
127
105
  - Beyond Compare (for unit test)
128
106
  rubyforge_project:
129
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.8.11
130
108
  signing_key:
131
109
  specification_version: 3
132
110
  summary: Build excel documents with Ruby/Winole
133
- test_files:
111
+ test_files:
134
112
  - benchmark/rexcel_benchmark.rb
113
+ - unittest/rexcel_test_helper.rb
135
114
  - unittest/test_rexcel.rb
115
+ - unittest/test_rexcel_cell.rb
116
+ - unittest/test_rexcel_row.rb
117
+ - unittest/test_rexcel_worksheet.rb
118
+ - unittest/test_rexcel_workbook.rb
136
119
  - unittest/expected/Test_Style_xlm-test_backgroundcolor-gray.xml
137
120
  - unittest/expected/Test_Style_xlm-test_bold-bold.xml
138
121
  - unittest/expected/Test_Style_xlm-test_color-gray.xml
139
122
  - unittest/expected/Test_Style_xlm-test_italic-italic.xml
140
123
  - unittest/expected/Test_workbook-test_save_xml.xml
124
+ - unittest/expected/Test_Workbook_to_csv-test_filename.csv
125
+ - unittest/expected/Test_Workbook_to_csv-test_filename_encoding.csv
126
+ - unittest/expected/Test_Worksheet_to_csv-test_filename.csv
127
+ - unittest/expected/Test_Worksheet_to_csv-test_filename_encoding.csv