From: Lucas Bajolet Date: Mon, 2 May 2016 19:03:15 +0000 (-0400) Subject: tests: Added new CSV test X-Git-Url: http://nitlanguage.org tests: Added new CSV test Signed-off-by: Lucas Bajolet --- diff --git a/tests/niti.skip b/tests/niti.skip index cd191f7..571f594 100644 --- a/tests/niti.skip +++ b/tests/niti.skip @@ -39,3 +39,4 @@ nitsaf_args test_ffi_c_lots_of_refs test_rubix_cube test_rubix_visual +test_csv diff --git a/tests/nitvm.skip b/tests/nitvm.skip index 2b7be9f..47cb8a0 100644 --- a/tests/nitvm.skip +++ b/tests/nitvm.skip @@ -39,3 +39,4 @@ nitsaf.args test_ffi_c_lots_of_refs test_rubix_visual test_rubix_cube +test_csv diff --git a/tests/sav/test_csv.res b/tests/sav/test_csv.res new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_csv.nit b/tests/test_csv.nit new file mode 100644 index 0000000..179405d --- /dev/null +++ b/tests/test_csv.nit @@ -0,0 +1,48 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import csv + +var words = "../examples/rosettacode/unixdict.txt".to_path.read_all.split('\n') + +var doc = new CsvDocument +for i in [0 .. 8[ do doc.header.add("Col{i}") + +var del = doc.delimiter.to_s +var eol = doc.eol +var sep = doc.separator.to_s +for i in [0 .. 10000[ do + var ln = new Array[String] + for j in [0 .. 8[ do + var add_sep = 100.rand >= 70 + var add_eol = 100.rand >= 70 + var add_del = 100.rand >= 70 + var el = "{words.rand}" + if add_sep then el += sep + if add_eol then el += eol + if add_del then el += del + ln.add el + end + doc.records.add ln +end + +var refst = new StringWriter +doc.write_to(refst) + +var csvd = new CsvReader.from_string(refst.to_s).read_all + +var prodst = new StringWriter +csvd.write_to(prodst) + +assert refst.to_s.trim == prodst.to_s.trim