From c07c1ba9b1cf99bdeaae063798dbfebdd4e092ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Thu, 25 Sep 2014 17:06:01 +0200 Subject: [PATCH] csv: need to handle \r because windows lines ends with \r\n --- basis/csv/csv-tests.factor | 17 ++++++++++++----- basis/csv/csv.factor | 7 ++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/basis/csv/csv-tests.factor b/basis/csv/csv-tests.factor index 844a77d5e7..5beefe283c 100644 --- a/basis/csv/csv-tests.factor +++ b/basis/csv/csv-tests.factor @@ -4,11 +4,11 @@ io.directories ; IN: csv.tests ! I like to name my unit tests -: named-unit-test ( name output input -- ) +: named-unit-test ( name output input -- ) unit-test drop ; inline "Fields are separated by commas" -[ { { "1997" "Ford" "E350" } } ] +[ { { "1997" "Ford" "E350" } } ] [ "1997,Ford,E350" string>csv ] named-unit-test "ignores whitespace before and after elements. n.b.specifically prohibited by RFC 4180, which states, 'Spaces are considered part of a field and should not be ignored.'" @@ -21,7 +21,7 @@ IN: csv.tests "double quotes mean escaped in quotes" [ { { "1997" "Ford" "E350" "Super \"luxurious\" truck" } } ] -[ "1997,Ford,E350,\"Super \"\"luxurious\"\" truck\"" +[ "1997,Ford,E350,\"Super \"\"luxurious\"\" truck\"" string>csv ] named-unit-test "Fields with embedded line breaks must be delimited by double-quote characters." @@ -39,10 +39,10 @@ IN: csv.tests [ "\"1997\",\"Ford\",\"E350\"" string>csv ] named-unit-test "The first record in a csv file may contain column names in each of the fields." -[ { { "Year" "Make" "Model" } +[ { { "Year" "Make" "Model" } { "1997" "Ford" "E350" } { "2000" "Mercury" "Cougar" } } ] -[ "Year,Make,Model\n1997,Ford,E350\n2000,Mercury,Cougar" +[ "Year,Make,Model\n1997,Ford,E350\n2000,Mercury,Cougar" string>csv ] named-unit-test @@ -102,3 +102,10 @@ IN: csv.tests { { { "as,d\"f" "asdf" } } } [ "\"as,\"d\"\"\"\"f,asdf" string>csv ] unit-test [ { } ] [ "" string>csv ] unit-test + +[ + { { "Year" "Make" "Model" } + { "1997" "Ford" "E350" } + } +] +[ "Year,Make,\"Model\"\r\n1997,Ford,E350" string>csv ] unit-test diff --git a/basis/csv/csv.factor b/basis/csv/csv.factor index 350ee0b02e..008c0b2e38 100644 --- a/basis/csv/csv.factor +++ b/basis/csv/csv.factor @@ -12,7 +12,7 @@ CHAR: , delimiter set-global