simplecsv 0.0.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/CHANGELOG.txt +28 -0
- data/History.txt +9 -0
- data/INSTALL.txt +10 -0
- data/Manifest.txt +16 -0
- data/README.txt +17 -0
- data/Rakefile +59 -0
- data/TODO +0 -0
- data/TUTORIAL.txt +19 -0
- data/ext/simplecsv/MANIFEST +4 -0
- data/ext/simplecsv/extconf.rb +9 -0
- data/ext/simplecsv/rb_simplecsv.c +216 -0
- data/ext/simplecsv/rb_simplecsv.h +3 -0
- data/lib/simplecsv.rb +3 -0
- data/lib/simplecsv/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/simplecsv/simplecsv_test.rb +171 -0
- metadata +61 -0
@@ -0,0 +1,171 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', 'ext', 'simplecsv'))
|
2
|
+
|
3
|
+
require 'simplecsv'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TC_SimpleCSV < Test::Unit::TestCase
|
7
|
+
def test_constants
|
8
|
+
need_build =<<-_EOL_
|
9
|
+
__NOTICE__
|
10
|
+
You need to build ext library before run the test.
|
11
|
+
Try to type below.
|
12
|
+
$ ruby setup.rb config
|
13
|
+
$ ruby setup.rb setup
|
14
|
+
_EOL_
|
15
|
+
assert_equal('constant', defined? SimpleCSV)
|
16
|
+
assert_equal('constant', defined? SimpleCSV::STRICT, need_build)
|
17
|
+
assert_equal('constant', defined? SimpleCSV::REPALL_NL)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_module
|
21
|
+
assert_instance_of Module, SimpleCSV
|
22
|
+
assert_raise(NoMethodError) do
|
23
|
+
SimpleCSV.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_parse
|
28
|
+
assert_raise(ArgumentError) do
|
29
|
+
SimpleCSV.parse()
|
30
|
+
end
|
31
|
+
|
32
|
+
assert_raise(TypeError) do
|
33
|
+
SimpleCSV.parse(1)
|
34
|
+
end
|
35
|
+
|
36
|
+
assert_raise(TypeError) do
|
37
|
+
SimpleCSV.parse('', '')
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_raise(LocalJumpError) do
|
41
|
+
SimpleCSV.parse('no block given')
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_nothing_raised do
|
45
|
+
SimpleCSV.parse(''){}
|
46
|
+
end
|
47
|
+
|
48
|
+
assert_nil SimpleCSV.parse('')
|
49
|
+
|
50
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
51
|
+
test
|
52
|
+
_CSV_
|
53
|
+
assert_instance_of Array, row
|
54
|
+
assert_instance_of String, row.first
|
55
|
+
assert_equal 1, row.size
|
56
|
+
assert_equal ['test'], row
|
57
|
+
end
|
58
|
+
|
59
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
60
|
+
1,2,3
|
61
|
+
_CSV_
|
62
|
+
assert_instance_of Array, row
|
63
|
+
assert_instance_of String, row.first
|
64
|
+
assert_equal 3, row.size
|
65
|
+
assert_equal ['1', '2', '3'], row
|
66
|
+
end
|
67
|
+
|
68
|
+
rows = 0
|
69
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
70
|
+
1,2,3
|
71
|
+
2,3,4
|
72
|
+
_CSV_
|
73
|
+
assert_instance_of Array, row
|
74
|
+
assert_instance_of String, row.first
|
75
|
+
assert_equal 3, row.size
|
76
|
+
rows += 1
|
77
|
+
end
|
78
|
+
assert_equal 2, rows
|
79
|
+
|
80
|
+
rows = 0
|
81
|
+
SimpleCSV.parse("1,2,3\r\n2,3,4\n") do |row|
|
82
|
+
rows += 1
|
83
|
+
end
|
84
|
+
assert_equal 2, rows
|
85
|
+
|
86
|
+
rows = 0
|
87
|
+
SimpleCSV.parse("1,2,3\r2,3,4\n") do |row|
|
88
|
+
rows += 1
|
89
|
+
end
|
90
|
+
assert_equal 2, rows
|
91
|
+
|
92
|
+
rows = 0
|
93
|
+
SimpleCSV.parse("1,2,3\n2,3,4\n \t\n") do |row|
|
94
|
+
rows += 1
|
95
|
+
end
|
96
|
+
assert_equal 2, rows
|
97
|
+
|
98
|
+
SimpleCSV.parse(" 1,2 , 3 ,\t4,5\t,\t6\t, 7\t,\t8 ") do |row|
|
99
|
+
assert_equal ['1', '2', '3', '4', '5', '6', '7', '8'], row
|
100
|
+
end
|
101
|
+
|
102
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
103
|
+
" 1 "
|
104
|
+
_CSV_
|
105
|
+
assert_equal [' 1 '], row
|
106
|
+
end
|
107
|
+
|
108
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
109
|
+
"1", "2", "3"
|
110
|
+
_CSV_
|
111
|
+
assert_equal ['1', '2', '3'], row
|
112
|
+
end
|
113
|
+
|
114
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
115
|
+
"1, 2, 3"
|
116
|
+
_CSV_
|
117
|
+
assert_equal ['1, 2, 3'], row
|
118
|
+
end
|
119
|
+
|
120
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
121
|
+
"""1"
|
122
|
+
_CSV_
|
123
|
+
assert_equal ['"1'], row
|
124
|
+
end
|
125
|
+
|
126
|
+
SimpleCSV.parse(<<_CSV_) do |row|
|
127
|
+
"ab"c"
|
128
|
+
_CSV_
|
129
|
+
assert_equal ['ab"c'], row
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_raise(SimpleCSV::ParseError) do
|
133
|
+
SimpleCSV.parse(<<_CSV_, SimpleCSV::STRICT){}
|
134
|
+
"ab"c"
|
135
|
+
_CSV_
|
136
|
+
end
|
137
|
+
|
138
|
+
rows = 0
|
139
|
+
SimpleCSV.parse(<<_CSV_, SimpleCSV::REPALL_NL) do |row|
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
_CSV_
|
144
|
+
rows += 1
|
145
|
+
end
|
146
|
+
assert_equal 3, rows
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_write
|
150
|
+
assert_equal '', SimpleCSV.write([])
|
151
|
+
|
152
|
+
assert_equal '"1","2","3"', SimpleCSV.write(["1", "2", "3"])
|
153
|
+
|
154
|
+
assert_equal '""""', SimpleCSV.write(['"'])
|
155
|
+
|
156
|
+
assert_equal 256, SimpleCSV.write(['"'*127]).size
|
157
|
+
assert_equal '"' * 256, SimpleCSV.write(['"'*127])
|
158
|
+
|
159
|
+
assert_raise(ArgumentError) do
|
160
|
+
SimpleCSV.write()
|
161
|
+
end
|
162
|
+
|
163
|
+
assert_raise(TypeError) do
|
164
|
+
SimpleCSV.write(1)
|
165
|
+
end
|
166
|
+
|
167
|
+
assert_raise(TypeError) do
|
168
|
+
SimpleCSV.write([1, 2, 3])
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: simplecsv
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2007-03-02 00:00:00 +09:00
|
8
|
+
summary: SimpleCSV privides simple csv reading/writing api.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- ext
|
12
|
+
email: itacchi@gmail.com
|
13
|
+
homepage: http://simplecsv.rubyforge.org
|
14
|
+
rubyforge_project: simplecsv
|
15
|
+
description: SimpleCSV privides simple csv reading/writing api.
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
authors:
|
30
|
+
- date
|
31
|
+
files:
|
32
|
+
- CHANGELOG.txt
|
33
|
+
- History.txt
|
34
|
+
- INSTALL.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- README.txt
|
37
|
+
- Rakefile
|
38
|
+
- TODO
|
39
|
+
- TUTORIAL.txt
|
40
|
+
- ext/simplecsv/MANIFEST
|
41
|
+
- ext/simplecsv/extconf.rb
|
42
|
+
- ext/simplecsv/rb_simplecsv.c
|
43
|
+
- ext/simplecsv/rb_simplecsv.h
|
44
|
+
- lib/simplecsv.rb
|
45
|
+
- lib/simplecsv/version.rb
|
46
|
+
- setup.rb
|
47
|
+
- test/simplecsv/simplecsv_test.rb
|
48
|
+
test_files:
|
49
|
+
- test/simplecsv/simplecsv_test.rb
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
extra_rdoc_files: []
|
53
|
+
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions:
|
57
|
+
- ext/simplecsv/extconf.rb
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
dependencies: []
|
61
|
+
|