@@ -79,6 +79,19 @@ class CSVWriterSpec extends FunSpec with ShouldMatchers with BeforeAndAfter with
79
79
80
80
readFileAsString(" test.csv" ) should be (expected)
81
81
}
82
+
83
+ it(" writes null fields as empty strings" ) {
84
+ using (CSVWriter .open(new FileWriter (" test.csv" ))) { writer =>
85
+ writer.writeAll(List (List (" a" , null , " c" ), List (" d" , " e" , null )))
86
+ }
87
+
88
+ val expected = """ |a,,c
89
+ |d,e,
90
+ |""" .stripMargin
91
+
92
+ readFileAsString(" test.csv" ) should be (expected)
93
+ }
94
+
82
95
describe (" When stream is already closed" ) {
83
96
it (" throws an Exception" ) {
84
97
val writer = CSVWriter .open(" test.csv" )
@@ -103,6 +116,18 @@ class CSVWriterSpec extends FunSpec with ShouldMatchers with BeforeAndAfter with
103
116
104
117
readFileAsString(" test.csv" ) should be (expected)
105
118
}
119
+ it(" write single line with null fieldsto file" ) {
120
+ using (CSVWriter .open(new FileWriter (" test.csv" ))) { writer =>
121
+ writer.writeRow(List (" a" , null , " c" ))
122
+ writer.writeRow(List (" d" , " e" , null ))
123
+ }
124
+
125
+ val expected = """ |a,,c
126
+ |d,e,
127
+ |""" .stripMargin
128
+
129
+ readFileAsString(" test.csv" ) should be (expected)
130
+ }
106
131
describe (" When a field contains quoteChar in it" ) {
107
132
it (" should escape the quoteChar" ) {
108
133
using (CSVWriter .open(new FileWriter (" test.csv" ))) { writer =>
0 commit comments