From e5d248c3ccf64211fd8a301f584bde82dd426601 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 27 Nov 2009 00:38:58 +0100 Subject: delombok now calls lombok. wahey! --- .../src/lombok/delombok/TestLombokFiles.java | 95 ++++++++++++++++++++++ .../src/lombok/delombok/TestSourceFiles.java | 21 +++-- .../resource/after/CommentsInterspersed.java | 26 ++++++ .../resource/before/CommentsInterspersed.java | 14 ++++ 4 files changed, 151 insertions(+), 5 deletions(-) create mode 100644 test/delombok/src/lombok/delombok/TestLombokFiles.java create mode 100644 test/lombok/resource/after/CommentsInterspersed.java create mode 100644 test/lombok/resource/before/CommentsInterspersed.java (limited to 'test') diff --git a/test/delombok/src/lombok/delombok/TestLombokFiles.java b/test/delombok/src/lombok/delombok/TestLombokFiles.java new file mode 100644 index 00000000..10782830 --- /dev/null +++ b/test/delombok/src/lombok/delombok/TestLombokFiles.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2009 Reinier Zwitserloot and Roel Spilker. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package lombok.delombok; + +import static org.junit.Assert.fail; +import static lombok.delombok.TestSourceFiles.removeBlanks; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.StringWriter; + +import lombok.delombok.CommentPreservingParser.ParseResult; + +import org.junit.BeforeClass; +import org.junit.Test; + +public class TestLombokFiles { + private static CommentPreservingParser parser; + + private static final File BEFORE_FOLDER = new File("test/lombok/resource/before"); + private static final File AFTER_FOLDER = new File("test/lombok/resource/after"); + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + @BeforeClass + public static void init() { + parser = new CommentPreservingParser(); + } + + @Test + public void testSources() throws Exception { + File[] listFiles = BEFORE_FOLDER.listFiles(); + for (File file : listFiles) { + ParseResult parseResult = parser.parseFile(file.toString()); + StringWriter writer = new StringWriter(); + parseResult.print(writer); + System.out.println(writer); + compare(file.getName(), readAfter(file), writer.toString()); + } + } + + private void compare(String name, String expectedFile, String actualFile) { + String[] expectedLines = expectedFile.split("(\\r?\\n)"); + String[] actualLines = actualFile.split("(\\r?\\n)"); + expectedLines = removeBlanks(expectedLines); + actualLines = removeBlanks(actualLines); + int size = Math.min(expectedLines.length, actualLines.length); + for (int i = 0; i < size; i++) { + String expected = expectedLines[i]; + String actual = actualLines[i]; + if (!expected.equals(actual)) { + fail(String.format("Difference in line %s(%d):\n`%s`\n`%s`\n", name, i, expected, actual)); + } + } + if (expectedLines.length > actualLines.length) { + fail(String.format("Missing line %s(%d): %s\n", name, size, expectedLines[size])); + } + if (expectedLines.length < actualLines.length) { + fail(String.format("Extra line %s(%d): %s\n", name, size, actualLines[size])); + } + } + + private String readAfter(File file) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File(AFTER_FOLDER, file.getName()))); + StringBuilder result = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + result.append(line); + result.append(LINE_SEPARATOR); + } + reader.close(); + return result.toString(); + } +} diff --git a/test/delombok/src/lombok/delombok/TestSourceFiles.java b/test/delombok/src/lombok/delombok/TestSourceFiles.java index 374eeb8b..b662651d 100644 --- a/test/delombok/src/lombok/delombok/TestSourceFiles.java +++ b/test/delombok/src/lombok/delombok/TestSourceFiles.java @@ -28,6 +28,8 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; import lombok.delombok.CommentPreservingParser.ParseResult; @@ -35,14 +37,13 @@ import org.junit.BeforeClass; import org.junit.Test; public class TestSourceFiles { - private static CommentPreservingParser parser; private static final File BEFORE_FOLDER = new File("test/delombok/resource/before"); private static final File AFTER_FOLDER = new File("test/delombok/resource/after"); - - private static final String LINE_SEPARATOR = System.getProperty("line.separator"); - + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + @BeforeClass public static void init() { parser = new CommentPreservingParser(); @@ -59,9 +60,19 @@ public class TestSourceFiles { } } + static String[] removeBlanks(String[] in) { + List out = new ArrayList(); + for (String s : in) { + if (!s.trim().isEmpty()) out.add(s); + } + return out.toArray(new String[0]); + } + private void compare(String name, String expectedFile, String actualFile) { String[] expectedLines = expectedFile.split("(\\r?\\n)"); String[] actualLines = actualFile.split("(\\r?\\n)"); + expectedLines = removeBlanks(expectedLines); + actualLines = removeBlanks(actualLines); int size = Math.min(expectedLines.length, actualLines.length); for (int i = 0; i < size; i++) { String expected = expectedLines[i]; @@ -77,7 +88,7 @@ public class TestSourceFiles { fail(String.format("Extra line %s(%d): %s\n", name, size, actualLines[size])); } } - + private String readAfter(File file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(AFTER_FOLDER, file.getName()))); StringBuilder result = new StringBuilder(); diff --git a/test/lombok/resource/after/CommentsInterspersed.java b/test/lombok/resource/after/CommentsInterspersed.java new file mode 100644 index 00000000..ec5374c0 --- /dev/null +++ b/test/lombok/resource/after/CommentsInterspersed.java @@ -0,0 +1,26 @@ +import lombok.Getter; + +/*bla */ +public class CommentsInterspersed { + /** javadoc for field */ + private int x; + + /* bla2 */ + @Getter() + private String test = "foo"; + //$NON-NLS-1$ + + /** Javadoc on method */ + public native void gwtTest(); + /*-{ + javascript; + }-*/ + + public CommentsInterspersed() { + } + + public String getTest() { + return this.test; + } +} +//haha! diff --git a/test/lombok/resource/before/CommentsInterspersed.java b/test/lombok/resource/before/CommentsInterspersed.java new file mode 100644 index 00000000..2a32d309 --- /dev/null +++ b/test/lombok/resource/before/CommentsInterspersed.java @@ -0,0 +1,14 @@ +import lombok.Getter; + +public /*bla */ class CommentsInterspersed { + /** javadoc for field */ + private int x; + + private /* bla2 */ @Getter String test = "foo"; //$NON-NLS-1$ + + /** Javadoc on method */ + public native void gwtTest(); /*-{ + javascript; + }-*/ +} //haha! + -- cgit