2009-02-09 19:11:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								USING:  io.streams.string  csv  tools.test  kernel  strings  
						 
					
						
							
								
									
										
										
										
											2009-01-30 20:23:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								io.pathnames io.files.unique io.encodings.utf8 io.files
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								io.directories ;
 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 00:15:50 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								IN:  csv.tests  
						 
					
						
							
								
									
										
										
										
											2008-04-17 16:29:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								! I like to name my unit tests  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								:  named-unit-test  (  name  output  input  --  )   
						 
					
						
							
								
									
										
										
										
											2009-02-09 19:11:42 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  unit-test drop  ;  inline
 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-17 16:29:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Fields are separated by commas"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  } } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,Ford,E350"  <string-reader> 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.'"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,   Ford   , E350"  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"keeps spaces in quotes"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  "Super, luxurious truck"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,Ford,E350,\"Super, luxurious truck\""  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"double quotes mean escaped in quotes"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  "Super \"luxurious\" truck"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,Ford,E350,\"Super \"\"luxurious\"\" truck\""  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Fields with embedded line breaks must be delimited by double-quote characters."  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  "Go get one now\nthey are going fast"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,Ford,E350,\"Go get one now\nthey are going fast\"" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Fields with leading or trailing spaces must be delimited by double-quote characters. (See comment about leading and trailing spaces above)"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  "  Super luxurious truck    "  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1997,Ford,E350,\"  Super luxurious truck    \"" 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 00:15:50 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
									
										
										
										
											2008-04-17 16:29:04 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Fields may always be delimited by double-quote characters, whether necessary or not."  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1997"  "Ford"  "E350"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "\"1997\",\"Ford\",\"E350\""  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"The first record in a csv file may contain column names in each of the fields."  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "Year"  "Make"  "Model"  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "1997"  "Ford"  "E350"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "2000"  "Mercury"  "Cougar"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "Year,Make,Model\n1997,Ford,E350\n2000,Mercury,Cougar"  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								! !!!!!!!!  other tests  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								   
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "Phil Dawes"  } } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "\"Phil Dawes\""  <string-reader> csv ] unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "1"  "2"  "3"  } { "4"  "5"  "6"  } } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "1,2,3\n4,5,6\n"  <string-reader> csv ] unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"trims leading and trailing whitespace - n.b. this isn't really conformant, but lots of csv seems to assume this"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "foo yeah"  "bah"  "baz"  } } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "  foo yeah  , bah ,baz\n"  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
									
										
										
										
											2008-04-30 12:50:40 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"allows setting of delimiting character"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "foo"  "bah"  "baz"  } } ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "foo\tbah\tbaz\n"  <string-reader> CHAR: \t  [ csv ] with-delimiter ] named-unit-test
							 
						 
					
						
							
								
									
										
										
										
											2008-05-01 06:54:09 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"Quoted field followed immediately by newline"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "foo"  "bar"  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { "1"    "2"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "foo,\"bar\"\n1,2"  <string-reader> csv ] named-unit-test
							 
						 
					
						
							
								
									
										
										
										
											2008-07-25 17:02:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"can write csv too!"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "foo1,bar1\nfoo2,bar2\n"  ]
							 
						 
					
						
							
								
									
										
										
										
											2009-11-05 18:03:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[ { { "foo1"  "bar1"  } { "foo2"  "bar2"  } } <string-writer> [ write-csv ] keep  >string  ] named-unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-07-25 17:02:07 -04:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"escapes quotes commas and newlines when writing"  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ "\"fo\"\"o1\",bar1\n\"fo\no2\",\"b,ar2\"\n"  ]
							 
						 
					
						
							
								
									
										
										
										
											2009-11-05 18:03:24 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[ { { "fo\"o1"  "bar1"  } { "fo\no2"  "b,ar2"  } } <string-writer> [ write-csv ] keep  >string  ] named-unit-test ! " 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-30 20:23:04 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "writing"  "some"  "csv"  "tests"  } } ]
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "writing,some,csv,tests" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    "csv-test1-"  unique-file utf8
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    [ set-file-contents ] [ file>csv ] [ drop  delete-file ] 2tri
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								] unit-test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ t  ] [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    { { "writing,some,csv,tests"  } } dup  "csv-test2-" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    unique-file utf8 [ csv>file ] [ file>csv ] 2bi  =
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								] unit-test
							 
						 
					
						
							
								
									
										
										
										
											2009-02-12 02:32:06 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								[ { { "hello"  ""  ""  ""  "goodbye"  ""  } } ] [ "hello,,\"\",,goodbye,"  <string-reader> csv ] unit-test