1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 var words
= "../examples/rosettacode/unixdict.txt".to_path
.read_all
.split
('\n')
19 var doc
= new CsvDocument
20 for i
in [0 .. 8[ do doc
.header
.add
("Col{i}")
22 var del
= doc
.delimiter
.to_s
24 var sep
= doc
.separator
.to_s
25 for i
in [0 .. 10000[ do
26 var ln
= new Array[String]
28 var add_sep
= 100.rand
>= 70
29 var add_eol
= 100.rand
>= 70
30 var add_del
= 100.rand
>= 70
31 var el
= "{words.rand}"
32 if add_sep
then el
+= sep
33 if add_eol
then el
+= eol
34 if add_del
then el
+= del
40 var refst
= new StringWriter
43 var csvd
= new CsvReader.from_string
(refst
.to_s
).read_all
45 var prodst
= new StringWriter
48 assert refst
.to_s
.trim
== prodst
.to_s
.trim