v / vlib / encoding / csv / writer_test.v
27 lines · 20 sloc · 1.02 KB · 3d2588f1012b1b175acbfb9445a6c1a694b8def2
Raw
1import encoding.csv
2
3fn test_encoding_csv_writer() {
4 mut csv_writer := csv.new_writer()
5
6 csv_writer.write(['name', 'email', 'phone', 'other']) or {}
7 csv_writer.write(['joe', '[email protected]', '0400000000', 'test']) or {}
8 csv_writer.write(['sam', '[email protected]', '0433000000', 'needs, quoting']) or {}
9
10 assert csv_writer.str() == 'name,email,phone,other\njoe,[email protected],0400000000,test\nsam,[email protected],0433000000,"needs, quoting"\n'
11
12 /*
13 mut csv_writer2 := csv.new_writer(delimiter:':')
14 csv_writer.write(['foo', 'bar', '2']) or {}
15 assert csv_writer.str() == 'foo:bar:2'
16 */
17}
18
19fn test_encoding_csv_writer_delimiter() {
20 mut csv_writer := csv.new_writer(delimiter: ` `)
21
22 csv_writer.write(['name', 'email', 'phone', 'other']) or {}
23 csv_writer.write(['joe', '[email protected]', '0400000000', 'test']) or {}
24 csv_writer.write(['sam', '[email protected]', '0433000000', 'needs, quoting']) or {}
25
26 assert csv_writer.str() == 'name email phone other\njoe [email protected] 0400000000 test\nsam [email protected] 0433000000 "needs, quoting"\n'
27}
28