Skip to content

Commit 8aee20e

Browse files
committed
Preprocessor Enum test
1 parent de45fc9 commit 8aee20e

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import processing.core.*;
2+
import processing.data.*;
3+
import processing.event.*;
4+
import processing.opengl.*;
5+
6+
import java.lang.*;
7+
8+
import java.util.HashMap;
9+
import java.util.ArrayList;
10+
import java.io.File;
11+
import java.io.BufferedReader;
12+
import java.io.PrintWriter;
13+
import java.io.InputStream;
14+
import java.io.OutputStream;
15+
import java.io.IOException;
16+
17+
public class bug1390 extends PApplet {
18+
19+
20+
21+
enum Operation {
22+
@Deprecated ADD_10(10) { protected int apply(int x) { return x + y; } },
23+
MULT_5(5) { protected int apply(int x) { return x * y; } },
24+
@SuppressWarnings("serial") DIV_10(10) { protected int apply(int x) { return x / y; } },
25+
SUB_8(8) { protected int apply(int x) { return x - y; } };
26+
27+
final int y;
28+
29+
Operation(int y) {
30+
this.y = y;
31+
}
32+
33+
protected abstract int apply(int x);
34+
}
35+
36+
Operation operation = Operation.ADD_10;
37+
38+
public void setup() {
39+
int x = 10;
40+
println("Original:", x);
41+
for (Operation op : Operation.values()) {
42+
x = op.apply(x);
43+
println(op.toString(), x);
44+
}
45+
x = operation.apply(x);
46+
println(operation.toString(), x);
47+
}
48+
static public void main(String[] passedArgs) {
49+
String[] appletArgs = new String[] { "bug1390" };
50+
if (passedArgs != null) {
51+
PApplet.main(concat(appletArgs, passedArgs));
52+
} else {
53+
PApplet.main(appletArgs);
54+
}
55+
}
56+
}

app/test/resources/bug1390.pde

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.lang.*;
2+
3+
enum Operation {
4+
@Deprecated ADD_10(10) { protected int apply(int x) { return x + y; } },
5+
MULT_5(5) { protected int apply(int x) { return x * y; } },
6+
@SuppressWarnings("serial") DIV_10(10) { protected int apply(int x) { return x / y; } },
7+
SUB_8(8) { protected int apply(int x) { return x - y; } };
8+
9+
final int y;
10+
11+
Operation(int y) {
12+
this.y = y;
13+
}
14+
15+
protected abstract int apply(int x);
16+
}
17+
18+
Operation operation = Operation.ADD_10;
19+
20+
void setup() {
21+
int x = 10;
22+
println("Original:", x);
23+
for (Operation op : Operation.values()) {
24+
x = op.apply(x);
25+
println(op.toString(), x);
26+
}
27+
x = operation.apply(x);
28+
println(operation.toString(), x);
29+
}

app/test/src/test/processing/mode/java/ParserTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ public void bug1145() {
201201
public void bug1362() {
202202
expectGood("bug1362");
203203
}
204+
205+
@Test
206+
public void bug1390() {
207+
expectGood("bug1390");
208+
}
204209

205210
@Test
206211
public void bug1442() {

0 commit comments

Comments
 (0)