rubysl-csv 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +25 -0
  6. data/README.md +29 -0
  7. data/Rakefile +2 -0
  8. data/lib/csv.rb +1 -0
  9. data/lib/rubysl/csv.rb +2 -0
  10. data/lib/rubysl/csv/csv.rb +992 -0
  11. data/lib/rubysl/csv/version.rb +5 -0
  12. data/rubysl-csv.gemspec +27 -0
  13. data/spec/basicwriter/close_on_terminate_spec.rb +5 -0
  14. data/spec/basicwriter/initialize_spec.rb +5 -0
  15. data/spec/basicwriter/terminate_spec.rb +5 -0
  16. data/spec/cell/data_spec.rb +5 -0
  17. data/spec/cell/initialize_spec.rb +5 -0
  18. data/spec/fixtures/one_line.csv +1 -0
  19. data/spec/foreach_spec.rb +5 -0
  20. data/spec/generate_line_spec.rb +58 -0
  21. data/spec/generate_row_spec.rb +5 -0
  22. data/spec/generate_spec.rb +73 -0
  23. data/spec/iobuf/close_spec.rb +5 -0
  24. data/spec/iobuf/initialize_spec.rb +5 -0
  25. data/spec/iobuf/read_spec.rb +5 -0
  26. data/spec/iobuf/terminate_spec.rb +5 -0
  27. data/spec/ioreader/close_on_terminate_spec.rb +5 -0
  28. data/spec/ioreader/get_row_spec.rb +5 -0
  29. data/spec/ioreader/initialize_spec.rb +5 -0
  30. data/spec/ioreader/terminate_spec.rb +5 -0
  31. data/spec/open_spec.rb +5 -0
  32. data/spec/parse_row_spec.rb +29 -0
  33. data/spec/parse_spec.rb +126 -0
  34. data/spec/read_spec.rb +5 -0
  35. data/spec/reader/close_spec.rb +7 -0
  36. data/spec/reader/create_spec.rb +7 -0
  37. data/spec/reader/each_spec.rb +7 -0
  38. data/spec/reader/get_row_spec.rb +7 -0
  39. data/spec/reader/initialize_spec.rb +7 -0
  40. data/spec/reader/parse_spec.rb +24 -0
  41. data/spec/reader/shift_spec.rb +7 -0
  42. data/spec/reader/terminate_spec.rb +7 -0
  43. data/spec/readlines_spec.rb +24 -0
  44. data/spec/streambuf/add_buf_spec.rb +5 -0
  45. data/spec/streambuf/buf_size_spec.rb +5 -0
  46. data/spec/streambuf/drop_spec.rb +5 -0
  47. data/spec/streambuf/element_reference_spec.rb +5 -0
  48. data/spec/streambuf/get_spec.rb +5 -0
  49. data/spec/streambuf/idx_is_eos_spec.rb +5 -0
  50. data/spec/streambuf/initialize_spec.rb +5 -0
  51. data/spec/streambuf/is_eos_spec.rb +5 -0
  52. data/spec/streambuf/read_spec.rb +5 -0
  53. data/spec/streambuf/rel_buf_spec.rb +5 -0
  54. data/spec/streambuf/terminate_spec.rb +5 -0
  55. data/spec/stringreader/get_row_spec.rb +5 -0
  56. data/spec/stringreader/initialize_spec.rb +5 -0
  57. data/spec/writer/add_row_spec.rb +5 -0
  58. data/spec/writer/append_spec.rb +5 -0
  59. data/spec/writer/close_spec.rb +5 -0
  60. data/spec/writer/create_spec.rb +5 -0
  61. data/spec/writer/generate_spec.rb +5 -0
  62. data/spec/writer/initialize_spec.rb +5 -0
  63. data/spec/writer/terminate_spec.rb +5 -0
  64. metadata +227 -0
@@ -0,0 +1,5 @@
1
+ module RubySL
2
+ module CSV
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require './lib/rubysl/csv/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "rubysl-csv"
6
+ spec.version = RubySL::CSV::VERSION
7
+ spec.authors = ["Brian Shirai"]
8
+ spec.email = ["brixen@gmail.com"]
9
+ spec.description = %q{Ruby standard library csv.}
10
+ spec.summary = %q{Ruby standard library csv.}
11
+ spec.homepage = "https://github.com/rubysl/rubysl-csv"
12
+ spec.license = "BSD"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.required_ruby_version = "~> 1.8.7"
20
+
21
+ spec.add_runtime_dependency "rubysl-english", "~> 2.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "mspec", "~> 1.5"
26
+ spec.add_development_dependency "rubysl-prettyprint", "~> 1.0"
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::BasicWriter#close_on_terminate" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::BasicWriter#initialize" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::BasicWriter#terminate" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::Cell#data" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::Cell#initialize" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1 @@
1
+ 1,2
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.foreach" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.generate_line" do
4
+
5
+ ruby_version_is "" ... "1.9" do
6
+ it "generates an empty string" do
7
+ result = CSV::generate_line([])
8
+ result.should == ""
9
+ end
10
+
11
+ it "generates the string 'foo,bar'" do
12
+ result = CSV::generate_line(["foo", "bar"])
13
+ result.should == "foo,bar"
14
+ end
15
+
16
+ it "generates the string 'foo;bar'" do
17
+ result = CSV::generate_line(["foo", "bar"], ?;)
18
+ result.should == "foo;bar"
19
+ end
20
+
21
+ it "generates the string 'foo,,bar'" do
22
+ result = CSV::generate_line(["foo", nil, "bar"])
23
+ result.should == "foo,,bar"
24
+ end
25
+
26
+ it "generates the string 'foo;;bar'" do
27
+ result = CSV::generate_line(["foo", nil, "bar"], ?;)
28
+ result.should == "foo;;bar"
29
+ end
30
+ end
31
+
32
+ ruby_version_is "1.9" do
33
+ it "generates an empty string" do
34
+ result = CSV::generate_line([])
35
+ result.should == "\n"
36
+ end
37
+
38
+ it "generates the string 'foo,bar'" do
39
+ result = CSV::generate_line(["foo", "bar"])
40
+ result.should == "foo,bar\n"
41
+ end
42
+
43
+ it "generates the string 'foo;bar'" do
44
+ result = CSV::generate_line(["foo", "bar"], :col_sep => ?;)
45
+ result.should == "foo;bar\n"
46
+ end
47
+
48
+ it "generates the string 'foo,,bar'" do
49
+ result = CSV::generate_line(["foo", nil, "bar"])
50
+ result.should == "foo,,bar\n"
51
+ end
52
+
53
+ it "generates the string 'foo;;bar'" do
54
+ result = CSV::generate_line(["foo", nil, "bar"], :col_sep => ?;)
55
+ result.should == "foo;;bar\n"
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.generate_row" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,73 @@
1
+ require 'csv'
2
+ require 'tempfile'
3
+
4
+ describe "CSV.generate" do
5
+
6
+ ruby_version_is "" ... "1.9" do
7
+ before :each do
8
+ @outfile_name = tmp("generate_test_#{$$}.csv")
9
+ end
10
+
11
+ it "creates a BasicWriter" do
12
+ writer = CSV::generate(@outfile_name)
13
+ writer.should be_kind_of(CSV::BasicWriter)
14
+ writer.close
15
+ end
16
+
17
+ it "accepts a field separator" do
18
+ writer = CSV::generate(@outfile_name, ",")
19
+ writer.should be_kind_of(CSV::BasicWriter)
20
+ writer.close
21
+ end
22
+
23
+ it "accepts a row separator" do
24
+ writer = CSV::generate(@outfile_name, ".")
25
+ writer.should be_kind_of(CSV::BasicWriter)
26
+ writer.close
27
+ end
28
+
29
+ it "creates a BasicWriter to use in a block" do
30
+ CSV::generate(@outfile_name) do |writer|
31
+ writer.should be_kind_of(CSV::BasicWriter)
32
+ end
33
+ end
34
+
35
+ it "creates a BasicWriter with ; as the separator inside the block" do
36
+ CSV::generate(@outfile_name, ?;) do |writer|
37
+ writer.should be_kind_of(CSV::BasicWriter)
38
+ end
39
+ end
40
+
41
+ after :each do
42
+ rm_r @outfile_name
43
+ end
44
+ end
45
+
46
+ ruby_version_is "1.9" do
47
+ it "returns CSV string" do
48
+ csv_str = CSV.generate do |csv|
49
+ csv.add_row [1, 2, 3]
50
+ csv << [4, 5, 6]
51
+ end
52
+ csv_str.should == "1,2,3\n4,5,6\n"
53
+ end
54
+
55
+ it "accepts a col separator" do
56
+ csv_str = CSV.generate(:col_sep => ";") do |csv|
57
+ csv.add_row [1, 2, 3]
58
+ csv << [4, 5, 6]
59
+ end
60
+ csv_str.should == "1;2;3\n4;5;6\n"
61
+ end
62
+
63
+ it "appends and returns the argument itself" do
64
+ str = ""
65
+ csv_str = CSV.generate(str) do |csv|
66
+ csv.add_row [1, 2, 3]
67
+ csv << [4, 5, 6]
68
+ end
69
+ csv_str.object_id.should == str.object_id
70
+ str.should == "1,2,3\n4,5,6\n"
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOBuf#close" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOBuf#initialize" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOBuf#read" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOBuf#terminate" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOReader#close_on_terminate" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOReader#get_row" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOReader#initialize" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV::IOReader#terminate" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.open" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'csv'
2
+
3
+ ruby_version_is "" ... "1.9" do
4
+ describe "CSV.parse_row" do
5
+
6
+ it "parses 'foo\nbar' one row at a time" do
7
+ parse_me = "foo\nbar"
8
+
9
+ parsed_row = []
10
+ parsed_count, next_row_index = CSV::parse_row parse_me, 0, parsed_row
11
+ parsed_count.should == 1
12
+ next_row_index.should == 4
13
+ parsed_row.should == ['foo']
14
+
15
+ parsed_row = []
16
+ parsed_count, next_row_index = CSV::parse_row parse_me, next_row_index, parsed_row
17
+ parsed_count.should == 1
18
+ next_row_index.should == 7
19
+ parsed_row.should == ['bar']
20
+
21
+ parsed_row = []
22
+ parsed_count, next_row_index = CSV::parse_row parse_me, next_row_index, parsed_row
23
+ parsed_count.should == 0
24
+ next_row_index.should == 0
25
+ parsed_row.should == []
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,126 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.parse" do
4
+
5
+ it "parses '' into []" do
6
+ result = CSV::parse ''
7
+ result.should be_kind_of(Array)
8
+ result.should == []
9
+ end
10
+
11
+ ruby_version_is "" ... "1.9" do
12
+ it "parses '\n' into [[nil]]" do
13
+ result = CSV::parse "\n"
14
+ result.should == [[nil]]
15
+ end
16
+ end
17
+
18
+ ruby_version_is "1.9" do
19
+ it "parses '\n' into [[]]" do
20
+ result = CSV::parse "\n"
21
+ result.should == [[]]
22
+ end
23
+ end
24
+
25
+ it "parses 'foo' into [['foo']]" do
26
+ result = CSV::parse 'foo'
27
+ result.should == [['foo']]
28
+ end
29
+
30
+ it "parses 'foo,bar,baz' into [['foo','bar','baz']]" do
31
+ result = CSV::parse 'foo,bar,baz'
32
+ result.should == [['foo','bar','baz']]
33
+ end
34
+
35
+ it "parses 'foo,baz' into [[foo,nil,baz]]" do
36
+ result = CSV::parse 'foo,,baz'
37
+ result.should == [['foo',nil,'baz']]
38
+ end
39
+
40
+ ruby_version_is "" ... "1.9" do
41
+ it "parses '\nfoo' into [[nil],['foo']]" do
42
+ result = CSV::parse "\nfoo"
43
+ result.should == [[nil],['foo']]
44
+ end
45
+ end
46
+
47
+ ruby_version_is "1.9" do
48
+ it "parses '\nfoo' into [[],['foo']]" do
49
+ result = CSV::parse "\nfoo"
50
+ result.should == [[],['foo']]
51
+ end
52
+ end
53
+
54
+ it "parses 'foo\n' into [['foo']]" do
55
+ result = CSV::parse "foo\n"
56
+ result.should == [['foo']]
57
+ end
58
+
59
+ it "parses 'foo\nbar' into [['foo'],['bar']]" do
60
+ result = CSV::parse "foo\nbar"
61
+ result.should == [['foo'],['bar']]
62
+ end
63
+
64
+ it "parses 'foo,bar\nbaz,quz' into [['foo','bar'],['baz','quz']]" do
65
+ result = CSV::parse "foo,bar\nbaz,quz"
66
+ result.should == [['foo','bar'],['baz','quz']]
67
+ end
68
+
69
+ it "parses 'foo,bar'\nbaz' into [['foo','bar'],['baz']]" do
70
+ result = CSV::parse "foo,bar\nbaz"
71
+ result.should == [['foo','bar'],['baz']]
72
+ end
73
+
74
+ it "parses 'foo\nbar,baz' into [['foo'],['bar','baz']]" do
75
+ result = CSV::parse "foo\nbar,baz"
76
+ result.should == [['foo'],['bar','baz']]
77
+ end
78
+
79
+ ruby_version_is "" ... "1.9" do
80
+ it "parses '\n\nbar' into [[nil],[nil],'bar']]" do
81
+ result = CSV::parse "\n\nbar"
82
+ result.should == [[nil],[nil],['bar']]
83
+ end
84
+ end
85
+
86
+ ruby_version_is "1.9" do
87
+ it "parses '\n\nbar' into [[],[],'bar']]" do
88
+ result = CSV::parse "\n\nbar"
89
+ result.should == [[],[],['bar']]
90
+ end
91
+ end
92
+
93
+ ruby_version_is "" ... "1.9" do
94
+ it "parses 'foo' into [['foo']] with a separator of ;" do
95
+ result = CSV::parse "foo", ?;
96
+ result.should == [['foo']]
97
+ end
98
+
99
+ it "parses 'foo;bar' into [['foo','bar']] with a separator of ;" do
100
+ result = CSV::parse "foo;bar", ?;
101
+ result.should == [['foo','bar']]
102
+ end
103
+
104
+ it "parses 'foo;bar\nbaz;quz' into [['foo','bar'],['baz','quz']] with a separator of ;" do
105
+ result = CSV::parse "foo;bar\nbaz;quz", ?;
106
+ result.should == [['foo','bar'],['baz','quz']]
107
+ end
108
+ end
109
+
110
+ ruby_version_is "1.9" do
111
+ it "parses 'foo' into [['foo']] with a separator of ;" do
112
+ result = CSV::parse "foo", :col_sep => ?;
113
+ result.should == [['foo']]
114
+ end
115
+
116
+ it "parses 'foo;bar' into [['foo','bar']] with a separator of ;" do
117
+ result = CSV::parse "foo;bar", :col_sep => ?;
118
+ result.should == [['foo','bar']]
119
+ end
120
+
121
+ it "parses 'foo;bar\nbaz;quz' into [['foo','bar'],['baz','quz']] with a separator of ;" do
122
+ result = CSV::parse "foo;bar\nbaz;quz", :col_sep => ?;
123
+ result.should == [['foo','bar'],['baz','quz']]
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ describe "CSV.read" do
4
+ it "needs to be reviewed for spec completeness"
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'csv'
2
+
3
+ ruby_version_is "" ... "1.9" do
4
+ describe "CSV::Reader#close" do
5
+ it "needs to be reviewed for spec completeness"
6
+ end
7
+ end