csvreader 1.2.4 → 1.2.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.
@@ -1,208 +1,208 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_parser_java.rb
6
-
7
-
8
- require 'helper'
9
-
10
- ##########################
11
- # try some tests from apache java (commons) csv reader
12
- # see https://github.com/apache/commons-csv/blob/master/src/test/java/org/apache/commons/csv/LexerTest.java
13
-
14
-
15
- class TestParserJava < MiniTest::Test
16
-
17
-
18
- LF = "\n" ## \n == ASCII 0x0A (hex) 10 (dec) = LF (Newline/line feed)
19
- CR = "\r" ## \r == ASCII 0x0D (hex) 13 (dec) = CR (Carriage return)
20
-
21
-
22
-
23
- def parser
24
- CsvReader::Parser
25
- end
26
-
27
- def test_surrounding_spaces_are_deleted
28
- assert_equal [["noSpaces",
29
- "leadingSpaces",
30
- "trailingSpaces",
31
- "surroundingSpaces",
32
- "",
33
- "",
34
- ""]], parser.default.parse( "noSpaces, leadingSpaces,trailingSpaces , surroundingSpaces , ,," )
35
- end
36
-
37
-
38
- def test_surrounding_tabs_are_deleted
39
- assert_equal [["noTabs",
40
- "leadingTab",
41
- "trailingTab",
42
- "surroundingTabs",
43
- "",
44
- "",
45
- ""]], parser.default.parse( "noTabs,\tleadingTab,trailingTab\t,\tsurroundingTabs\t,\t\t,," )
46
- end
47
-
48
- def test_ignore_empty_lines
49
- assert_equal [[ "first", "line", "" ],
50
- [ "second", "line" ],
51
- [ "third line" ],
52
- [ "last", "line" ]],
53
- parser.default.parse( "first,line,\n" + "\n" + "\n" +
54
- "second,line\n" + "\n" + "\n" +
55
- "third line \n" + "\n" + "\n" +
56
- "last, line \n" + "\n" + "\n" + "\n" )
57
- end
58
-
59
-
60
- def test_comments
61
- assert_equal [["first", "line", "" ],
62
- ["second", "line", "tokenWith#no-comment" ],
63
- ["third", "line" ]],
64
- parser.default.parse( "first,line,\n" +
65
- "second,line,tokenWith#no-comment\n" +
66
- "# comment line \n" +
67
- "third,line #inline-end-of-line-comment\n" +
68
- "# penultimate comment\n" +
69
- "# Final comment\n" )
70
- end
71
-
72
-
73
-
74
-
75
-
76
- def test_comments_and_empty_lines
77
- parser.strict.comment = '#'
78
-
79
- assert_equal [[ "1", "2", "3", "" ], ## 1
80
- [ "" ], ## 1b
81
- [ "" ], ## 1c
82
- [ "a", "b x", "c#no-comment" ], ## 2
83
- [ "" ], ## 4
84
- [ "" ], ## 4b
85
- [ "d", "e", "#no-comment" ], ## 5
86
- [ "" ], ## 5b
87
- [ "" ], ## 5c
88
- [ "" ], ## 6b
89
- [ "" ] ## 6c
90
- ],
91
- parser.strict.parse(
92
- "1,2,3,\n" + ## 1
93
- "\n" + ## 1b
94
- "\n" + ## 1c
95
- "a,b x,c#no-comment\n" + ## 2
96
- "#foo\n" + ## 3
97
- "\n" + ## 4
98
- "\n" + ## 4b
99
- "d,e,#no-comment\n" + ## 5
100
- "\n" + ## 5b
101
- "\n" + ## 5c
102
- "# penultimate comment\n" + ## 6
103
- "\n" + ## 6b
104
- "\n" + ## 6c
105
- "# Final comment\n" ## 7
106
- )
107
-
108
- parser.strict.comment = false ## reset to defaults
109
- end
110
-
111
-
112
- def test_backslash_with_escaping
113
- ## simple token with escaping enabled
114
- assert_equal [[ "a", ",", "b\\" ],
115
- [ ",", "\nc", "d\r" ],
116
- [ "e" ]], parser.default.parse( "a,\\,,b\\\\\n" +
117
- "\\,,\\\nc,d\\\r\n" +
118
- "e" )
119
-
120
-
121
- parser.strict.escape = "\\"
122
- assert_equal [[ "a", ",", "b\\" ],
123
- [ ",", "\nc", "d\r" ],
124
- [ "e" ]], parser.strict.parse( "a,\\,,b\\\\\n" +
125
- "\\,,\\\nc,d\\\r\n" +
126
- "e" )
127
- parser.strict.escape = false
128
- end
129
-
130
-
131
- def test_backslash_without_escaping
132
- ## simple token with escaping not enabled
133
- assert_equal [[ "a",
134
- "\\", ## an unquoted single backslash is not an escape char
135
- "",
136
- "b\\" ## an unquoted single backslash is not an escape char
137
- ],
138
- [ "\\", "", "" ]], parser.strict.parse( "a,\\,,b\\\n" +
139
- "\\,," )
140
-
141
- end
142
-
143
-
144
-
145
- def test_next_token4
146
- ## encapsulator tokenizer (single line)
147
- assert_equal [[ "a", "foo", "b" ],
148
- [ "a", " foo", "b" ],
149
- [ "a", "foo ", "b" ],
150
- [ "a", " foo ", "b" ]],
151
- parser.default.parse( "a,\"foo\",b\n" +
152
- "a, \" foo\",b\n" +
153
- "a,\"foo \" ,b\n" +
154
- "a, \" foo \" ,b" )
155
- end
156
-
157
-
158
- def test_next_token5
159
- ## encapsulator tokenizer (multi line, delimiter in string)
160
- assert_equal [[ "a", "foo\n", "b" ],
161
- [ "foo\n baar ,,," ],
162
- [ "\n\t \n" ]],
163
- parser.default.parse( "a,\"foo\n\",b\n" +
164
- "\"foo\n baar ,,,\"\n" +
165
- "\"\n\t \n\"" )
166
- end
167
-
168
-
169
- def test_separator_is_tab
170
- parser.strict.sep = "\t"
171
- assert_equal [["one",
172
- "two",
173
- "",
174
- "four ",
175
- " five",
176
- " six" ]], parser.strict.parse( "one\ttwo\t\tfour \t five\t six" )
177
- parser.strict.sep = "," ## reset back to comma
178
- end
179
-
180
-
181
-
182
-
183
- def test_escaped_cr
184
- assert_equal [[ "character" + CR + "Escaped" ]],
185
- parser.default.parse( "character\\" + CR + "Escaped" )
186
- end
187
-
188
-
189
- def test_cr
190
- assert_equal [[ "character" ],
191
- [ "NotEscaped" ]],
192
- parser.default.parse( "character" + CR + "NotEscaped" )
193
- end
194
-
195
-
196
-
197
- def test_escaped_lf
198
- assert_equal [[ "character" + LF + "Escaped" ]],
199
- parser.default.parse( "character\\" + LF + "Escaped" )
200
- end
201
-
202
- def test_lf
203
- assert_equal [[ "character" ],
204
- [ "NotEscaped" ]],
205
- parser.default.parse( "character" + LF + "NotEscaped" )
206
- end
207
-
208
- end # class TestParserJava
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_parser_java.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ ##########################
11
+ # try some tests from apache java (commons) csv reader
12
+ # see https://github.com/apache/commons-csv/blob/master/src/test/java/org/apache/commons/csv/LexerTest.java
13
+
14
+
15
+ class TestParserJava < MiniTest::Test
16
+
17
+
18
+ LF = "\n" ## \n == ASCII 0x0A (hex) 10 (dec) = LF (Newline/line feed)
19
+ CR = "\r" ## \r == ASCII 0x0D (hex) 13 (dec) = CR (Carriage return)
20
+
21
+
22
+
23
+ def parser
24
+ CsvReader::Parser
25
+ end
26
+
27
+ def test_surrounding_spaces_are_deleted
28
+ assert_equal [["noSpaces",
29
+ "leadingSpaces",
30
+ "trailingSpaces",
31
+ "surroundingSpaces",
32
+ "",
33
+ "",
34
+ ""]], parser.default.parse( "noSpaces, leadingSpaces,trailingSpaces , surroundingSpaces , ,," )
35
+ end
36
+
37
+
38
+ def test_surrounding_tabs_are_deleted
39
+ assert_equal [["noTabs",
40
+ "leadingTab",
41
+ "trailingTab",
42
+ "surroundingTabs",
43
+ "",
44
+ "",
45
+ ""]], parser.default.parse( "noTabs,\tleadingTab,trailingTab\t,\tsurroundingTabs\t,\t\t,," )
46
+ end
47
+
48
+ def test_ignore_empty_lines
49
+ assert_equal [[ "first", "line", "" ],
50
+ [ "second", "line" ],
51
+ [ "third line" ],
52
+ [ "last", "line" ]],
53
+ parser.default.parse( "first,line,\n" + "\n" + "\n" +
54
+ "second,line\n" + "\n" + "\n" +
55
+ "third line \n" + "\n" + "\n" +
56
+ "last, line \n" + "\n" + "\n" + "\n" )
57
+ end
58
+
59
+
60
+ def test_comments
61
+ assert_equal [["first", "line", "" ],
62
+ ["second", "line", "tokenWith#no-comment" ],
63
+ ["third", "line" ]],
64
+ parser.default.parse( "first,line,\n" +
65
+ "second,line,tokenWith#no-comment\n" +
66
+ "# comment line \n" +
67
+ "third,line #inline-end-of-line-comment\n" +
68
+ "# penultimate comment\n" +
69
+ "# Final comment\n" )
70
+ end
71
+
72
+
73
+
74
+
75
+
76
+ def test_comments_and_empty_lines
77
+ parser.strict.comment = '#'
78
+
79
+ assert_equal [[ "1", "2", "3", "" ], ## 1
80
+ [ "" ], ## 1b
81
+ [ "" ], ## 1c
82
+ [ "a", "b x", "c#no-comment" ], ## 2
83
+ [ "" ], ## 4
84
+ [ "" ], ## 4b
85
+ [ "d", "e", "#no-comment" ], ## 5
86
+ [ "" ], ## 5b
87
+ [ "" ], ## 5c
88
+ [ "" ], ## 6b
89
+ [ "" ] ## 6c
90
+ ],
91
+ parser.strict.parse(
92
+ "1,2,3,\n" + ## 1
93
+ "\n" + ## 1b
94
+ "\n" + ## 1c
95
+ "a,b x,c#no-comment\n" + ## 2
96
+ "#foo\n" + ## 3
97
+ "\n" + ## 4
98
+ "\n" + ## 4b
99
+ "d,e,#no-comment\n" + ## 5
100
+ "\n" + ## 5b
101
+ "\n" + ## 5c
102
+ "# penultimate comment\n" + ## 6
103
+ "\n" + ## 6b
104
+ "\n" + ## 6c
105
+ "# Final comment\n" ## 7
106
+ )
107
+
108
+ parser.strict.comment = false ## reset to defaults
109
+ end
110
+
111
+
112
+ def test_backslash_with_escaping
113
+ ## simple token with escaping enabled
114
+ assert_equal [[ "a", ",", "b\\" ],
115
+ [ ",", "\nc", "d\r" ],
116
+ [ "e" ]], parser.default.parse( "a,\\,,b\\\\\n" +
117
+ "\\,,\\\nc,d\\\r\n" +
118
+ "e" )
119
+
120
+
121
+ parser.strict.escape = "\\"
122
+ assert_equal [[ "a", ",", "b\\" ],
123
+ [ ",", "\nc", "d\r" ],
124
+ [ "e" ]], parser.strict.parse( "a,\\,,b\\\\\n" +
125
+ "\\,,\\\nc,d\\\r\n" +
126
+ "e" )
127
+ parser.strict.escape = false
128
+ end
129
+
130
+
131
+ def test_backslash_without_escaping
132
+ ## simple token with escaping not enabled
133
+ assert_equal [[ "a",
134
+ "\\", ## an unquoted single backslash is not an escape char
135
+ "",
136
+ "b\\" ## an unquoted single backslash is not an escape char
137
+ ],
138
+ [ "\\", "", "" ]], parser.strict.parse( "a,\\,,b\\\n" +
139
+ "\\,," )
140
+
141
+ end
142
+
143
+
144
+
145
+ def test_next_token4
146
+ ## encapsulator tokenizer (single line)
147
+ assert_equal [[ "a", "foo", "b" ],
148
+ [ "a", " foo", "b" ],
149
+ [ "a", "foo ", "b" ],
150
+ [ "a", " foo ", "b" ]],
151
+ parser.default.parse( "a,\"foo\",b\n" +
152
+ "a, \" foo\",b\n" +
153
+ "a,\"foo \" ,b\n" +
154
+ "a, \" foo \" ,b" )
155
+ end
156
+
157
+
158
+ def test_next_token5
159
+ ## encapsulator tokenizer (multi line, delimiter in string)
160
+ assert_equal [[ "a", "foo\n", "b" ],
161
+ [ "foo\n baar ,,," ],
162
+ [ "\n\t \n" ]],
163
+ parser.default.parse( "a,\"foo\n\",b\n" +
164
+ "\"foo\n baar ,,,\"\n" +
165
+ "\"\n\t \n\"" )
166
+ end
167
+
168
+
169
+ def test_separator_is_tab
170
+ parser.strict.sep = "\t"
171
+ assert_equal [["one",
172
+ "two",
173
+ "",
174
+ "four ",
175
+ " five",
176
+ " six" ]], parser.strict.parse( "one\ttwo\t\tfour \t five\t six" )
177
+ parser.strict.sep = "," ## reset back to comma
178
+ end
179
+
180
+
181
+
182
+
183
+ def test_escaped_cr
184
+ assert_equal [[ "character" + CR + "Escaped" ]],
185
+ parser.default.parse( "character\\" + CR + "Escaped" )
186
+ end
187
+
188
+
189
+ def test_cr
190
+ assert_equal [[ "character" ],
191
+ [ "NotEscaped" ]],
192
+ parser.default.parse( "character" + CR + "NotEscaped" )
193
+ end
194
+
195
+
196
+
197
+ def test_escaped_lf
198
+ assert_equal [[ "character" + LF + "Escaped" ]],
199
+ parser.default.parse( "character\\" + LF + "Escaped" )
200
+ end
201
+
202
+ def test_lf
203
+ assert_equal [[ "character" ],
204
+ [ "NotEscaped" ]],
205
+ parser.default.parse( "character" + LF + "NotEscaped" )
206
+ end
207
+
208
+ end # class TestParserJava
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvreader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-27 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tabreader
@@ -56,43 +56,47 @@ dependencies:
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '4.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '7'
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - "~>"
69
+ - - ">="
67
70
  - !ruby/object:Gem::Version
68
71
  version: '4.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '7'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: hoe
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: '3.16'
81
+ version: '3.22'
76
82
  type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: '3.16'
88
+ version: '3.22'
83
89
  description: csvreader - read tabular data in the comma-separated values (csv) format
84
90
  the right way (uses best practices out-of-the-box with zero-configuration)
85
91
  email: wwwmake@googlegroups.com
86
92
  executables: []
87
93
  extensions: []
88
94
  extra_rdoc_files:
89
- - HISTORY.md
90
- - LICENSE.md
95
+ - CHANGELOG.md
91
96
  - Manifest.txt
92
97
  - README.md
93
98
  files:
94
- - HISTORY.md
95
- - LICENSE.md
99
+ - CHANGELOG.md
96
100
  - Manifest.txt
97
101
  - README.md
98
102
  - Rakefile
@@ -147,7 +151,7 @@ homepage: https://github.com/csvreader/csvreader
147
151
  licenses:
148
152
  - Public Domain
149
153
  metadata: {}
150
- post_install_message:
154
+ post_install_message:
151
155
  rdoc_options:
152
156
  - "--main"
153
157
  - README.md
@@ -164,9 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
168
  - !ruby/object:Gem::Version
165
169
  version: '0'
166
170
  requirements: []
167
- rubyforge_project:
168
- rubygems_version: 2.5.2
169
- signing_key:
171
+ rubygems_version: 3.1.4
172
+ signing_key:
170
173
  specification_version: 4
171
174
  summary: csvreader - read tabular data in the comma-separated values (csv) format
172
175
  the right way (uses best practices out-of-the-box with zero-configuration)
data/LICENSE.md DELETED
@@ -1,116 +0,0 @@
1
- CC0 1.0 Universal
2
-
3
- Statement of Purpose
4
-
5
- The laws of most jurisdictions throughout the world automatically confer
6
- exclusive Copyright and Related Rights (defined below) upon the creator and
7
- subsequent owner(s) (each and all, an "owner") of an original work of
8
- authorship and/or a database (each, a "Work").
9
-
10
- Certain owners wish to permanently relinquish those rights to a Work for the
11
- purpose of contributing to a commons of creative, cultural and scientific
12
- works ("Commons") that the public can reliably and without fear of later
13
- claims of infringement build upon, modify, incorporate in other works, reuse
14
- and redistribute as freely as possible in any form whatsoever and for any
15
- purposes, including without limitation commercial purposes. These owners may
16
- contribute to the Commons to promote the ideal of a free culture and the
17
- further production of creative, cultural and scientific works, or to gain
18
- reputation or greater distribution for their Work in part through the use and
19
- efforts of others.
20
-
21
- For these and/or other purposes and motivations, and without any expectation
22
- of additional consideration or compensation, the person associating CC0 with a
23
- Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
- and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
- and publicly distribute the Work under its terms, with knowledge of his or her
26
- Copyright and Related Rights in the Work and the meaning and intended legal
27
- effect of CC0 on those rights.
28
-
29
- 1. Copyright and Related Rights. A Work made available under CC0 may be
30
- protected by copyright and related or neighboring rights ("Copyright and
31
- Related Rights"). Copyright and Related Rights include, but are not limited
32
- to, the following:
33
-
34
- i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
- and translate a Work;
36
-
37
- ii. moral rights retained by the original author(s) and/or performer(s);
38
-
39
- iii. publicity and privacy rights pertaining to a person's image or likeness
40
- depicted in a Work;
41
-
42
- iv. rights protecting against unfair competition in regards to a Work,
43
- subject to the limitations in paragraph 4(a), below;
44
-
45
- v. rights protecting the extraction, dissemination, use and reuse of data in
46
- a Work;
47
-
48
- vi. database rights (such as those arising under Directive 96/9/EC of the
49
- European Parliament and of the Council of 11 March 1996 on the legal
50
- protection of databases, and under any national implementation thereof,
51
- including any amended or successor version of such directive); and
52
-
53
- vii. other similar, equivalent or corresponding rights throughout the world
54
- based on applicable law or treaty, and any national implementations thereof.
55
-
56
- 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
- applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
- unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
- and Related Rights and associated claims and causes of action, whether now
60
- known or unknown (including existing as well as future claims and causes of
61
- action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
- duration provided by applicable law or treaty (including future time
63
- extensions), (iii) in any current or future medium and for any number of
64
- copies, and (iv) for any purpose whatsoever, including without limitation
65
- commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
- the Waiver for the benefit of each member of the public at large and to the
67
- detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
- shall not be subject to revocation, rescission, cancellation, termination, or
69
- any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
- by the public as contemplated by Affirmer's express Statement of Purpose.
71
-
72
- 3. Public License Fallback. Should any part of the Waiver for any reason be
73
- judged legally invalid or ineffective under applicable law, then the Waiver
74
- shall be preserved to the maximum extent permitted taking into account
75
- Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
- is so judged Affirmer hereby grants to each affected person a royalty-free,
77
- non transferable, non sublicensable, non exclusive, irrevocable and
78
- unconditional license to exercise Affirmer's Copyright and Related Rights in
79
- the Work (i) in all territories worldwide, (ii) for the maximum duration
80
- provided by applicable law or treaty (including future time extensions), (iii)
81
- in any current or future medium and for any number of copies, and (iv) for any
82
- purpose whatsoever, including without limitation commercial, advertising or
83
- promotional purposes (the "License"). The License shall be deemed effective as
84
- of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
- License for any reason be judged legally invalid or ineffective under
86
- applicable law, such partial invalidity or ineffectiveness shall not
87
- invalidate the remainder of the License, and in such case Affirmer hereby
88
- affirms that he or she will not (i) exercise any of his or her remaining
89
- Copyright and Related Rights in the Work or (ii) assert any associated claims
90
- and causes of action with respect to the Work, in either case contrary to
91
- Affirmer's express Statement of Purpose.
92
-
93
- 4. Limitations and Disclaimers.
94
-
95
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
- surrendered, licensed or otherwise affected by this document.
97
-
98
- b. Affirmer offers the Work as-is and makes no representations or warranties
99
- of any kind concerning the Work, express, implied, statutory or otherwise,
100
- including without limitation warranties of title, merchantability, fitness
101
- for a particular purpose, non infringement, or the absence of latent or
102
- other defects, accuracy, or the present or absence of errors, whether or not
103
- discoverable, all to the greatest extent permissible under applicable law.
104
-
105
- c. Affirmer disclaims responsibility for clearing rights of other persons
106
- that may apply to the Work or any use thereof, including without limitation
107
- any person's Copyright and Related Rights in the Work. Further, Affirmer
108
- disclaims responsibility for obtaining any necessary consents, permissions
109
- or other rights required for any use of the Work.
110
-
111
- d. Affirmer understands and acknowledges that Creative Commons is not a
112
- party to this document and has no duty or obligation with respect to this
113
- CC0 or use of the Work.
114
-
115
- For more information, please see
116
- <http://creativecommons.org/publicdomain/zero/1.0/>