From 8ab06f3f9ec4efe3902b9f8dd6bed61b6002e843 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2016 09:07:21 +0200 Subject: [PATCH] core - CSVRenderer: add unit test for escaping filenames (#100) --- .../sourceforge/pmd/cpd/CSVRendererTest.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CSVRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CSVRendererTest.java index 4b1c5e70cb..c61f9def48 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CSVRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CSVRendererTest.java @@ -13,7 +13,6 @@ import net.sourceforge.pmd.PMD; import org.junit.Test; public class CSVRendererTest { - @Test public void testLineCountPerFile() { Renderer renderer = new CSVRenderer(true); @@ -32,6 +31,23 @@ public class CSVRendererTest { assertEquals(expectedReport, report); } + @Test + public void testFilenameEscapes() { + Renderer renderer = new CSVRenderer(); + List list = new ArrayList<>(); + String codeFragment = "code\nfragment"; + Mark mark1 = createMark("public", "/var,with,commas/Foo.java", 48, 10, codeFragment); + Mark mark2 = createMark("stuff", "/var,with,commas/Bar.java", 73, 20, codeFragment); + Match match = new Match(75, mark1, mark2); + list.add(match); + + String report = renderer.render(list.iterator()); + String expectedReport = + "lines,tokens,occurrences" + PMD.EOL + + "10,75,2,48,\"/var,with,commas/Foo.java\",73,\"/var,with,commas/Bar.java\"" + PMD.EOL; + assertEquals(expectedReport, report); + } + private Mark createMark(String image, String tokenSrcID, int beginLine, int lineCount, String code) { Mark result = new Mark(new TokenEntry(image, tokenSrcID, beginLine)); @@ -39,9 +55,5 @@ public class CSVRendererTest { result.setSoureCodeSlice(code); return result; } - - public static junit.framework.Test suite() { - return new junit.framework.JUnit4TestAdapter(CSVRendererTest.class); - } }