fastercsv 1.4.0 → 1.5.5

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/lib/fastercsv.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # fastercsv.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2006-04-01.
6
- # Copyright 2006 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
  #
8
8
  # This file is just another name for faster_csv.rb.
9
9
 
Binary file
@@ -3,7 +3,7 @@
3
3
  # tc_csv_parsing.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-10-31.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
@@ -108,6 +108,33 @@ class TestCSVParsing < Test::Unit::TestCase
108
108
  #
109
109
  assert_equal(Array.new, FasterCSV.parse_line("\n1,2,3\n"))
110
110
  end
111
+
112
+ def test_rob_edge_cases
113
+ [ [%Q{"a\nb"}, ["a\nb"]],
114
+ [%Q{"\n\n\n"}, ["\n\n\n"]],
115
+ [%Q{a,"b\n\nc"}, ['a', "b\n\nc"]],
116
+ [%Q{,"\r\n"}, [nil,"\r\n"]],
117
+ [%Q{,"\r\n."}, [nil,"\r\n."]],
118
+ [%Q{"a\na","one newline"}, ["a\na", 'one newline']],
119
+ [%Q{"a\n\na","two newlines"}, ["a\n\na", 'two newlines']],
120
+ [%Q{"a\r\na","one CRLF"}, ["a\r\na", 'one CRLF']],
121
+ [%Q{"a\r\n\r\na","two CRLFs"}, ["a\r\n\r\na", 'two CRLFs']],
122
+ [%Q{with blank,"start\n\nfinish"\n}, ['with blank', "start\n\nfinish"]],
123
+ ].each do |edge_case|
124
+ assert_equal(edge_case.last, FasterCSV.parse_line(edge_case.first))
125
+ end
126
+ end
127
+
128
+ def test_non_regex_edge_cases
129
+ # An early version of the non-regex parser fails this test
130
+ [["foo,\"foo,bar,baz,foo\",\"foo\"", ["foo", "foo,bar,baz,foo", "foo"]]].each do |edge_case|
131
+ assert_equal(edge_case.last, FasterCSV.parse_line(edge_case.first))
132
+ end
133
+
134
+ assert_raise(FasterCSV::MalformedCSVError) do
135
+ FasterCSV.parse_line("1,\"23\"4\"5\", 6")
136
+ end
137
+ end
111
138
 
112
139
  def test_malformed_csv
113
140
  assert_raise(FasterCSV::MalformedCSVError) do
@@ -158,7 +185,7 @@ class TestCSVParsing < Test::Unit::TestCase
158
185
  assert_send([csv.lineno, :<, 4])
159
186
  end
160
187
  rescue FasterCSV::MalformedCSVError
161
- assert_equal("Illegal quoting on line 4.", $!.message)
188
+ assert_equal("Illegal quoting in line 4.", $!.message)
162
189
  end
163
190
  end
164
191
  end
@@ -3,7 +3,7 @@
3
3
  # tc_csv_writing.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-11-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
@@ -3,7 +3,7 @@
3
3
  # tc_data_converters.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-12-30.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
data/test/tc_encodings.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_encodings.rb
4
4
  #
5
5
  # Created by Michael Reinsch.
6
- # Copyright (c) 2008 Ubiquitous Business Technology, Inc.
6
+ # Copyright (c) 2012 Ubiquitous Business Technology, Inc.
7
7
 
8
8
  require "test/unit"
9
9
 
data/test/tc_features.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_features.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-11-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
  require "zlib"
data/test/tc_headers.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_headers.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2006-02-25.
6
- # Copyright 2006 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
data/test/tc_interface.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_interface.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-11-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
@@ -72,6 +72,11 @@ class TestFasterCSVInterface < Test::Unit::TestCase
72
72
  assert_equal(%w{1 2 3}, row)
73
73
  end
74
74
 
75
+ def test_parse_line_with_empty_lines
76
+ assert_equal(nil, FasterCSV.parse_line("")) # to signal eof
77
+ assert_equal(Array.new, FasterCSV.parse_line("\n1,2,3"))
78
+ end
79
+
75
80
  def test_read_and_readlines
76
81
  assert_equal( @expected,
77
82
  FasterCSV.read(@path, :col_sep => "\t", :row_sep => "\r\n") )
@@ -103,6 +108,17 @@ class TestFasterCSVInterface < Test::Unit::TestCase
103
108
  assert_equal(nil, csv.shift)
104
109
  end
105
110
  end
111
+
112
+ def test_long_line # ruby's regex parser may have problems with long rows
113
+ File.unlink(@path)
114
+
115
+ long_field_length = 2800
116
+ File.open(@path, "w") do |file|
117
+ file << "1\t2\t#{'3' * long_field_length}\r\n"
118
+ end
119
+ @expected = [%w{1 2} + ['3' * long_field_length]]
120
+ test_shift
121
+ end
106
122
 
107
123
  ### Test Write Interface ###
108
124
 
@@ -165,7 +181,7 @@ class TestFasterCSVInterface < Test::Unit::TestCase
165
181
  csv << lines.first.keys
166
182
  lines.each { |line| csv << line }
167
183
  end
168
- FasterCSV.open( @path, "w", :headers => true,
184
+ FasterCSV.open( @path, "r", :headers => true,
169
185
  :converters => :all,
170
186
  :header_converters => :symbol ) do |csv|
171
187
  csv.each { |line| assert_equal(lines.shift, line.to_hash) }
data/test/tc_row.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_row.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2006-02-24.
6
- # Copyright 2006 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
@@ -3,7 +3,7 @@
3
3
  # tc_serialization.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2006-03-28.
6
- # Copyright 2006 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
data/test/tc_speed.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_speed.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-11-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
  require "timeout"
data/test/tc_table.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # tc_table.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2006-02-24.
6
- # Copyright 2006 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
@@ -251,6 +251,8 @@ class TestFasterCSVTable < Test::Unit::TestCase
251
251
  # with options
252
252
  assert_equal( csv.gsub(",", "|").gsub("\n", "\r\n"),
253
253
  @table.to_csv(:col_sep => "|", :row_sep => "\r\n") )
254
+ assert_equal( csv.to_a[1..-1].join,
255
+ @table.to_csv(:write_headers => false) )
254
256
 
255
257
  # with headers
256
258
  assert_equal(csv, @header_table.to_csv)
@@ -319,6 +321,12 @@ class TestFasterCSVTable < Test::Unit::TestCase
319
321
  END_RESULT
320
322
  end
321
323
 
324
+ def test_delete_with_blank_rows
325
+ data = "col1,col2\nra1,ra2\n\nrb1,rb2"
326
+ table = FasterCSV.parse(data, :headers => true)
327
+ assert_equal(["ra2", nil, "rb2"], table.delete("col2"))
328
+ end
329
+
322
330
  def test_delete_if
323
331
  ######################
324
332
  ### Mixed/Row Mode ###
data/test/ts_all.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # ts_all.rb
4
4
  #
5
5
  # Created by James Edward Gray II on 2005-11-14.
6
- # Copyright 2005 Gray Productions. All rights reserved.
6
+ # Copyright 2012 Gray Productions. All rights reserved.
7
7
 
8
8
  require "test/unit"
9
9
 
metadata CHANGED
@@ -1,25 +1,28 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fastercsv
3
- version: !ruby/object:Gem::Version
4
- version: 1.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.5
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - James Edward Gray II
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2008-09-10 00:00:00 -05:00
13
- default_executable:
12
+ date: 2012-05-15 00:00:00.000000000 Z
14
13
  dependencies: []
14
+ description: ! 'FasterCSV is intended as a complete replacement to the CSV standard
15
+ library. It
16
+
17
+ is significantly faster and smaller while still being pure Ruby code. It also
18
+
19
+ strives for a better interface.
15
20
 
16
- description: FasterCSV is intended as a complete replacement to the CSV standard library. It is significantly faster and smaller while still being pure Ruby code. It also strives for a better interface.
21
+ '
17
22
  email: james@grayproductions.net
18
23
  executables: []
19
-
20
24
  extensions: []
21
-
22
- extra_rdoc_files:
25
+ extra_rdoc_files:
23
26
  - AUTHORS
24
27
  - COPYING
25
28
  - README
@@ -27,7 +30,7 @@ extra_rdoc_files:
27
30
  - TODO
28
31
  - CHANGELOG
29
32
  - LICENSE
30
- files:
33
+ files:
31
34
  - lib/faster_csv.rb
32
35
  - lib/fastercsv.rb
33
36
  - test/tc_csv_parsing.rb
@@ -51,7 +54,7 @@ files:
51
54
  - test/test_data.csv
52
55
  - examples/purchase.csv
53
56
  - Rakefile
54
- - setup.rb
57
+ - test/line_endings.gz
55
58
  - AUTHORS
56
59
  - COPYING
57
60
  - README
@@ -59,34 +62,33 @@ files:
59
62
  - TODO
60
63
  - CHANGELOG
61
64
  - LICENSE
62
- has_rdoc: true
63
65
  homepage: http://fastercsv.rubyforge.org
66
+ licenses: []
64
67
  post_install_message:
65
- rdoc_options:
68
+ rdoc_options:
66
69
  - --title
67
70
  - FasterCSV Documentation
68
71
  - --main
69
72
  - README
70
- require_paths:
73
+ require_paths:
71
74
  - lib
72
- required_ruby_version: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
- version:
78
- required_rubygems_version: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
83
- version:
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
84
87
  requirements: []
85
-
86
88
  rubyforge_project: fastercsv
87
- rubygems_version: 1.2.0
89
+ rubygems_version: 1.8.24
88
90
  signing_key:
89
- specification_version: 2
91
+ specification_version: 3
90
92
  summary: FasterCSV is CSV, but faster, smaller, and cleaner.
91
- test_files:
93
+ test_files:
92
94
  - test/ts_all.rb