@@ -1261,6 +1261,68 @@ public void testPrint() throws IOException {
12611261 }
12621262 }
12631263
1264+ @ Test
1265+ public void testPrintCSVParser () throws IOException {
1266+ final String code = "a1,b1\n " // 1)
1267+ + "a2,b2\n " // 2)
1268+ + "a3,b3\n " // 3)
1269+ + "a4,b4\n " // 4)
1270+ ;
1271+ final String [][] res = {{"a1" , "b1" }, {"a2" , "b2" }, {"a3" , "b3" }, {"a4" , "b4" }};
1272+ CSVFormat format = CSVFormat .DEFAULT ;
1273+ StringWriter sw = new StringWriter ();
1274+ try (final CSVPrinter printer = format .print (sw ); final CSVParser parser = CSVParser .parse (code , format )) {
1275+ printer .printRecords (parser );
1276+ }
1277+ try (final CSVParser parser = CSVParser .parse (sw .toString (), format )) {
1278+ final List <CSVRecord > records = parser .getRecords ();
1279+ assertFalse (records .isEmpty ());
1280+ Utils .compare ("Fail" , res , records );
1281+ }
1282+ }
1283+
1284+ @ Test
1285+ public void testPrintCSVRecord () throws IOException {
1286+ final String code = "a1,b1\n " // 1)
1287+ + "a2,b2\n " // 2)
1288+ + "a3,b3\n " // 3)
1289+ + "a4,b4\n " // 4)
1290+ ;
1291+ final String [][] res = {{"a1" , "b1" }, {"a2" , "b2" }, {"a3" , "b3" }, {"a4" , "b4" }};
1292+ CSVFormat format = CSVFormat .DEFAULT ;
1293+ StringWriter sw = new StringWriter ();
1294+ try (final CSVPrinter printer = format .print (sw ); final CSVParser parser = CSVParser .parse (code , format )) {
1295+ for (CSVRecord record : parser ) {
1296+ printer .printRecord (record );
1297+ }
1298+ }
1299+ try (final CSVParser parser = CSVParser .parse (sw .toString (), format )) {
1300+ final List <CSVRecord > records = parser .getRecords ();
1301+ assertFalse (records .isEmpty ());
1302+ Utils .compare ("Fail" , res , records );
1303+ }
1304+ }
1305+
1306+ @ Test
1307+ public void testPrintCSVRecords () throws IOException {
1308+ final String code = "a1,b1\n " // 1)
1309+ + "a2,b2\n " // 2)
1310+ + "a3,b3\n " // 3)
1311+ + "a4,b4\n " // 4)
1312+ ;
1313+ final String [][] res = {{"a1" , "b1" }, {"a2" , "b2" }, {"a3" , "b3" }, {"a4" , "b4" }};
1314+ CSVFormat format = CSVFormat .DEFAULT ;
1315+ StringWriter sw = new StringWriter ();
1316+ try (final CSVPrinter printer = format .print (sw ); final CSVParser parser = CSVParser .parse (code , format )) {
1317+ printer .printRecords (parser .getRecords ());
1318+ }
1319+ try (final CSVParser parser = CSVParser .parse (sw .toString (), format )) {
1320+ final List <CSVRecord > records = parser .getRecords ();
1321+ assertFalse (records .isEmpty ());
1322+ Utils .compare ("Fail" , res , records );
1323+ }
1324+ }
1325+
12641326 @ Test
12651327 public void testPrintCustomNullValues () throws IOException {
12661328 final StringWriter sw = new StringWriter ();
0 commit comments