From f465d1a91e30e6e7d6dd674021569708d676db34 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Mon, 11 Aug 2014 13:27:51 +0200 Subject: [PATCH] Preprocessor Enum test --- app/test/resources/bug1390.expected | 56 +++++++++++++++++++ app/test/resources/bug1390.pde | 29 ++++++++++ .../processing/mode/java/ParserTests.java | 5 ++ 3 files changed, 90 insertions(+) create mode 100644 app/test/resources/bug1390.expected create mode 100644 app/test/resources/bug1390.pde diff --git a/app/test/resources/bug1390.expected b/app/test/resources/bug1390.expected new file mode 100644 index 000000000..12f75e6a2 --- /dev/null +++ b/app/test/resources/bug1390.expected @@ -0,0 +1,56 @@ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.lang.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class bug1390 extends PApplet { + + + +enum Operation { + @Deprecated ADD_10(10) { protected int apply(int x) { return x + y; } }, + MULT_5(5) { protected int apply(int x) { return x * y; } }, + @SuppressWarnings("serial") DIV_10(10) { protected int apply(int x) { return x / y; } }, + SUB_8(8) { protected int apply(int x) { return x - y; } }; + + final int y; + + Operation(int y) { + this.y = y; + } + + protected abstract int apply(int x); +} + +Operation operation = Operation.ADD_10; + +public void setup() { + int x = 10; + println("Original:", x); + for (Operation op : Operation.values()) { + x = op.apply(x); + println(op.toString(), x); + } + x = operation.apply(x); + println(operation.toString(), x); +} + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "bug1390" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/app/test/resources/bug1390.pde b/app/test/resources/bug1390.pde new file mode 100644 index 000000000..1513025da --- /dev/null +++ b/app/test/resources/bug1390.pde @@ -0,0 +1,29 @@ +import java.lang.*; + +enum Operation { + @Deprecated ADD_10(10) { protected int apply(int x) { return x + y; } }, + MULT_5(5) { protected int apply(int x) { return x * y; } }, + @SuppressWarnings("serial") DIV_10(10) { protected int apply(int x) { return x / y; } }, + SUB_8(8) { protected int apply(int x) { return x - y; } }; + + final int y; + + Operation(int y) { + this.y = y; + } + + protected abstract int apply(int x); +} + +Operation operation = Operation.ADD_10; + +void setup() { + int x = 10; + println("Original:", x); + for (Operation op : Operation.values()) { + x = op.apply(x); + println(op.toString(), x); + } + x = operation.apply(x); + println(operation.toString(), x); +} diff --git a/app/test/src/test/processing/mode/java/ParserTests.java b/app/test/src/test/processing/mode/java/ParserTests.java index eca3de658..e364f5340 100644 --- a/app/test/src/test/processing/mode/java/ParserTests.java +++ b/app/test/src/test/processing/mode/java/ParserTests.java @@ -201,6 +201,11 @@ public class ParserTests { public void bug1362() { expectGood("bug1362"); } + + @Test + public void bug1390() { + expectGood("bug1390"); + } @Test public void bug1442() {