aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-11-27 09:53:08 +0100
committerReinier Zwitserloot <reinier@tipit.to>2009-11-27 09:53:08 +0100
commit9678c58ec86a18605e62ff813005fddb1cefb392 (patch)
tree1aec17de05371b3a5ca02e25793e43e33c70e9b3 /test
parent6838c6be2f8bd8935fa6853067183cf11c013fcd (diff)
parent2b61c2534b22f07a13d8cb4c97c2ad323c6c4597 (diff)
downloadlombok-9678c58ec86a18605e62ff813005fddb1cefb392.tar.gz
lombok-9678c58ec86a18605e62ff813005fddb1cefb392.tar.bz2
lombok-9678c58ec86a18605e62ff813005fddb1cefb392.zip
Merge branch 'delombok'
Diffstat (limited to 'test')
-rw-r--r--test/core/src/lombok/TestViaDelombok.java97
-rw-r--r--test/delombok/resource/after/Cast.java7
-rw-r--r--test/delombok/resource/after/ForLoop.java13
-rw-r--r--test/delombok/resource/after/WithComments.java5
-rw-r--r--test/delombok/resource/before/Cast.java6
-rw-r--r--test/delombok/resource/before/ForLoop.java12
-rw-r--r--test/delombok/resource/before/WithComments.java4
-rw-r--r--test/delombok/src/lombok/delombok/TestLombokFiles.java38
-rw-r--r--test/delombok/src/lombok/delombok/TestSourceFiles.java38
-rw-r--r--test/lombok/resource/after/CommentsInterspersed.java20
-rw-r--r--test/lombok/resource/before/CommentsInterspersed.java14
11 files changed, 254 insertions, 0 deletions
diff --git a/test/core/src/lombok/TestViaDelombok.java b/test/core/src/lombok/TestViaDelombok.java
new file mode 100644
index 00000000..e8070723
--- /dev/null
+++ b/test/core/src/lombok/TestViaDelombok.java
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import static org.junit.Assert.fail;
+
+import java.io.BufferedReader;
+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.Delombok;
+
+public class TestViaDelombok {
+ private static Delombok delombok = new Delombok();
+
+ private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
+ public static void runComparison(File beforeDir, File afterDir) throws IOException {
+ File[] listFiles = beforeDir.listFiles();
+
+ for (File file : listFiles) {
+ delombok.setVerbose(false);
+ delombok.setForceProcess(true);
+ delombok.setCharset("UTF-8");
+ StringWriter writer = new StringWriter();
+ delombok.delombok(file.getAbsolutePath(), writer);
+ compare(file.getName(), readAfter(afterDir, file), writer.toString());
+ }
+ }
+
+ private static void compare(String name, String expectedFile, String actualFile) {
+ String[] expectedLines = expectedFile.split("(\\r?\\n)");
+ String[] actualLines = actualFile.split("(\\r?\\n)");
+ if (actualLines[0].startsWith("// Generated by delombok at ")) {
+ actualLines[0] = "";
+ }
+ 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 static String readAfter(File afterDir, File file) throws IOException {
+ BufferedReader reader = new BufferedReader(new FileReader(new File(afterDir, 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();
+ }
+
+ private static String[] removeBlanks(String[] in) {
+ List<String> out = new ArrayList<String>();
+ for (String s : in) {
+ if (!s.trim().isEmpty()) out.add(s);
+ }
+ return out.toArray(new String[0]);
+ }
+}
diff --git a/test/delombok/resource/after/Cast.java b/test/delombok/resource/after/Cast.java
new file mode 100644
index 00000000..a1b455f0
--- /dev/null
+++ b/test/delombok/resource/after/Cast.java
@@ -0,0 +1,7 @@
+import java.util.*;
+public class Cast {
+ public void test(List<?> list) {
+ RandomAccess r = (/*before*/
+ RandomAccess /*after*/)list;
+ }
+} \ No newline at end of file
diff --git a/test/delombok/resource/after/ForLoop.java b/test/delombok/resource/after/ForLoop.java
new file mode 100644
index 00000000..609549b7
--- /dev/null
+++ b/test/delombok/resource/after/ForLoop.java
@@ -0,0 +1,13 @@
+
+public class ForLoop {
+
+ public static void main(String[] args) {
+ // before loop
+ for (int i = 0; i < 10; i++) {
+ // start of block
+ System.out.println(i);
+ // end of block
+ }
+ // after loop
+ }
+}
diff --git a/test/delombok/resource/after/WithComments.java b/test/delombok/resource/after/WithComments.java
new file mode 100644
index 00000000..59cc97c4
--- /dev/null
+++ b/test/delombok/resource/after/WithComments.java
@@ -0,0 +1,5 @@
+// Cool Comments
+
+public class WithComments {
+ // Also inside the body
+} \ No newline at end of file
diff --git a/test/delombok/resource/before/Cast.java b/test/delombok/resource/before/Cast.java
new file mode 100644
index 00000000..95237b0f
--- /dev/null
+++ b/test/delombok/resource/before/Cast.java
@@ -0,0 +1,6 @@
+import java.util.*;
+public class Cast {
+ public void test(List<?> list) {
+ RandomAccess r = (/*before*/ RandomAccess /*after*/)list;
+ }
+} \ No newline at end of file
diff --git a/test/delombok/resource/before/ForLoop.java b/test/delombok/resource/before/ForLoop.java
new file mode 100644
index 00000000..2bed7f9b
--- /dev/null
+++ b/test/delombok/resource/before/ForLoop.java
@@ -0,0 +1,12 @@
+public class ForLoop {
+
+ public static void main(String[] args) {
+ // before loop
+ for (int i = 0; i < 10; i++) {
+ // start of block
+ System.out.println(i);
+ // end of block
+ }
+ // after loop
+ }
+}
diff --git a/test/delombok/resource/before/WithComments.java b/test/delombok/resource/before/WithComments.java
new file mode 100644
index 00000000..22d044b3
--- /dev/null
+++ b/test/delombok/resource/before/WithComments.java
@@ -0,0 +1,4 @@
+// Cool Comments
+public class WithComments {
+ // Also inside the body
+}
diff --git a/test/delombok/src/lombok/delombok/TestLombokFiles.java b/test/delombok/src/lombok/delombok/TestLombokFiles.java
new file mode 100644
index 00000000..1d93a4b2
--- /dev/null
+++ b/test/delombok/src/lombok/delombok/TestLombokFiles.java
@@ -0,0 +1,38 @@
+/*
+ * 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 java.io.File;
+
+import lombok.TestViaDelombok;
+
+import org.junit.Test;
+
+public class TestLombokFiles {
+ private static final File BEFORE_DIR = new File("test/lombok/resource/before");
+ private static final File AFTER_DIR = new File("test/lombok/resource/after");
+
+ @Test
+ public void testSources() throws Exception {
+ TestViaDelombok.runComparison(BEFORE_DIR, AFTER_DIR);
+ }
+}
diff --git a/test/delombok/src/lombok/delombok/TestSourceFiles.java b/test/delombok/src/lombok/delombok/TestSourceFiles.java
new file mode 100644
index 00000000..a5df5197
--- /dev/null
+++ b/test/delombok/src/lombok/delombok/TestSourceFiles.java
@@ -0,0 +1,38 @@
+/*
+ * 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 java.io.File;
+
+import lombok.TestViaDelombok;
+
+import org.junit.Test;
+
+public class TestSourceFiles {
+ private static final File BEFORE_DIR = new File("test/delombok/resource/before");
+ private static final File AFTER_DIR = new File("test/delombok/resource/after");
+
+ @Test
+ public void testSources() throws Exception {
+ TestViaDelombok.runComparison(BEFORE_DIR, AFTER_DIR);
+ }
+}
diff --git a/test/lombok/resource/after/CommentsInterspersed.java b/test/lombok/resource/after/CommentsInterspersed.java
new file mode 100644
index 00000000..f3841606
--- /dev/null
+++ b/test/lombok/resource/after/CommentsInterspersed.java
@@ -0,0 +1,20 @@
+/* cmt */
+/* cmt2 */
+/* cmt3 */
+/*bla */
+public class CommentsInterspersed {
+ /** javadoc for field */
+ private int x;
+
+ /* bla2 */
+ private String test = "foo"; //$NON-NLS-1$
+
+ /** Javadoc on method */
+ public native void gwtTest(); /*-{
+ javascript;
+ }-*/
+
+ public String getTest() {
+ return test;
+ }
+} //haha!
diff --git a/test/lombok/resource/before/CommentsInterspersed.java b/test/lombok/resource/before/CommentsInterspersed.java
new file mode 100644
index 00000000..455c680d
--- /dev/null
+++ b/test/lombok/resource/before/CommentsInterspersed.java
@@ -0,0 +1,14 @@
+import /* cmt */ lombok./* cmt2 */Getter /* cmt3 */ ;
+
+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!
+