|
23 | 23 | import com.google.visualization.datasource.datatable.DataTable; |
24 | 24 | import com.google.visualization.datasource.datatable.TableCell; |
25 | 25 | import com.google.visualization.datasource.datatable.TableRow; |
| 26 | +import com.google.visualization.datasource.datatable.value.BooleanValue; |
26 | 27 | import com.google.visualization.datasource.datatable.value.DateTimeValue; |
27 | 28 | import com.google.visualization.datasource.datatable.value.DateValue; |
28 | 29 | import com.google.visualization.datasource.datatable.value.NumberValue; |
@@ -262,4 +263,50 @@ public void testRenderError() { |
262 | 263 | "\"Error: Operation not supported. Cannot \"\"do\"\" that, too late!\"", |
263 | 264 | CsvRenderer.renderCsvError(responseStatus)); |
264 | 265 | } |
| 266 | + |
| 267 | + public void testRenderDataTableWithCommas() throws DataSourceException { |
| 268 | + testData = new DataTable(); |
| 269 | + ColumnDescription c0 = new ColumnDescription("A", ValueType.TEXT, "col0"); |
| 270 | + ColumnDescription c1 = new ColumnDescription("B", ValueType.NUMBER, "col1"); |
| 271 | + ColumnDescription c2 = new ColumnDescription("C", ValueType.BOOLEAN, "col2"); |
| 272 | + ColumnDescription c3 = new ColumnDescription("D", ValueType.DATE, "col3"); |
| 273 | + ColumnDescription c4 = new ColumnDescription("E", ValueType.DATETIME, "col4"); |
| 274 | + ColumnDescription c5 = new ColumnDescription("F", ValueType.TIMEOFDAY, "col5"); |
| 275 | + |
| 276 | + testData.addColumn(c0); |
| 277 | + testData.addColumn(c1); |
| 278 | + testData.addColumn(c2); |
| 279 | + testData.addColumn(c3); |
| 280 | + testData.addColumn(c4); |
| 281 | + testData.addColumn(c5); |
| 282 | + |
| 283 | + rows = Lists.newArrayList(); |
| 284 | + |
| 285 | + TableRow row = new TableRow(); |
| 286 | + row.addCell(new TableCell(new TextValue("aaa"), "aaa")); |
| 287 | + row.addCell(new TableCell(new NumberValue(222), "222")); |
| 288 | + row.addCell(new TableCell(BooleanValue.TRUE, "true")); |
| 289 | + row.addCell(new TableCell(new DateValue(2009, 1, 1), "2009-02-01")); |
| 290 | + row.addCell(new TableCell(new DateTimeValue(2009, 1, 1, 12, 14, 1, 0), "2009-02-01 12:14:01")); |
| 291 | + row.addCell(new TableCell(new TimeOfDayValue(12, 14, 1), "12:14:01")); |
| 292 | + rows.add(row); |
| 293 | + |
| 294 | + row = new TableRow(); |
| 295 | + row.addCell(new TableCell(new TextValue("aaa"), "a,aa")); |
| 296 | + row.addCell(new TableCell(new NumberValue(222), "2,22")); |
| 297 | + row.addCell(new TableCell(BooleanValue.TRUE, "true,")); |
| 298 | + row.addCell(new TableCell(new DateValue(2009, 1, 1), "2009-02-01")); |
| 299 | + row.addCell(new TableCell(new DateTimeValue(2009, 1, 1, 12, 14, 1, 0), "2009-02-01 12,14,01")); |
| 300 | + row.addCell(new TableCell(new TimeOfDayValue(12, 14, 1), "12:14:01")); |
| 301 | + rows.add(row); |
| 302 | + |
| 303 | + testData.addRows(rows); |
| 304 | + |
| 305 | + String expected = "\"col0\",\"col1\",\"col2\",\"col3\",\"col4\",\"col5\"\n"; |
| 306 | + expected += "\"aaa\",222,true,2009-02-01,2009-02-01 12:14:01,12:14:01\n"; |
| 307 | + expected += "\"a,aa\",\"2,22\",\"true,\",2009-02-01,\"2009-02-01 12,14,01\",12:14:01\n"; |
| 308 | + assertEquals(expected, CsvRenderer.renderDataTable(testData, null, null)); |
| 309 | + |
| 310 | + } |
265 | 311 | } |
| 312 | + |
0 commit comments