summaryrefslogtreecommitdiff
path: root/test/cuchaz/enigma
diff options
context:
space:
mode:
authorGravatar jeff2015-03-17 20:01:55 -0400
committerGravatar jeff2015-03-17 20:01:55 -0400
commitecfda21f3db9e62e3acf074e9842e92ace4cb3ab (patch)
tree1186068f246be4f2da197ce006ccaea79945dfa6 /test/cuchaz/enigma
parentslightly better support for generics (diff)
downloadenigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.tar.gz
enigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.tar.xz
enigma-fork-ecfda21f3db9e62e3acf074e9842e92ace4cb3ab.zip
parsing generic signatures is tricky. don't write custom code to do it. switching to library instead
Diffstat (limited to 'test/cuchaz/enigma')
-rw-r--r--test/cuchaz/enigma/TestType.java167
1 files changed, 10 insertions, 157 deletions
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java
index 544a10c..71aaaee 100644
--- a/test/cuchaz/enigma/TestType.java
+++ b/test/cuchaz/enigma/TestType.java
@@ -6,7 +6,6 @@ import static org.hamcrest.Matchers.*;
6 6
7import org.junit.Test; 7import org.junit.Test;
8 8
9import cuchaz.enigma.mapping.ParameterizedType;
10import cuchaz.enigma.mapping.Type; 9import cuchaz.enigma.mapping.Type;
11 10
12 11
@@ -24,7 +23,6 @@ public class TestType {
24 assertThat(new Type("D").isVoid(), is(false)); 23 assertThat(new Type("D").isVoid(), is(false));
25 assertThat(new Type("LFoo;").isVoid(), is(false)); 24 assertThat(new Type("LFoo;").isVoid(), is(false));
26 assertThat(new Type("[I").isVoid(), is(false)); 25 assertThat(new Type("[I").isVoid(), is(false));
27 assertThat(new Type("TFoo;").isVoid(), is(false));
28 } 26 }
29 27
30 @Test 28 @Test
@@ -39,7 +37,6 @@ public class TestType {
39 assertThat(new Type("D").isPrimitive(), is(true)); 37 assertThat(new Type("D").isPrimitive(), is(true));
40 assertThat(new Type("LFoo;").isPrimitive(), is(false)); 38 assertThat(new Type("LFoo;").isPrimitive(), is(false));
41 assertThat(new Type("[I").isPrimitive(), is(false)); 39 assertThat(new Type("[I").isPrimitive(), is(false));
42 assertThat(new Type("TFoo;").isPrimitive(), is(false));
43 } 40 }
44 41
45 @Test 42 @Test
@@ -64,26 +61,19 @@ public class TestType {
64 assertThat(new Type("F").isClass(), is(false)); 61 assertThat(new Type("F").isClass(), is(false));
65 assertThat(new Type("D").isClass(), is(false)); 62 assertThat(new Type("D").isClass(), is(false));
66 assertThat(new Type("LFoo;").isClass(), is(true)); 63 assertThat(new Type("LFoo;").isClass(), is(true));
67 assertThat(new Type("LFoo<LCow;>;").isClass(), is(true));
68 assertThat(new Type("LFoo<LCow;LBeer;>;").isClass(), is(true));
69 assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").isClass(), is(true));
70 assertThat(new Type("[I").isClass(), is(false)); 64 assertThat(new Type("[I").isClass(), is(false));
71 assertThat(new Type("TFoo;").isClass(), is(false));
72 } 65 }
73 66
74 @Test 67 @Test
75 public void getClassEntry() { 68 public void getClassEntry() {
76 assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); 69 assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo")));
77 assertThat(new Type("LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); 70 assertThat(new Type("Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String")));
78 assertThat(new Type("LFoo<LCow;>;").getClassEntry(), is(newClass("Foo")));
79 assertThat(new Type("LFoo<LCow;LBeer;>;").getClassEntry(), is(newClass("Foo")));
80 assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").getClassEntry(), is(newClass("Foo")));
81 } 71 }
82 72
83 @Test 73 @Test
84 public void getArrayClassEntry() { 74 public void getArrayClassEntry() {
85 assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); 75 assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo")));
86 assertThat(new Type("[[[LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); 76 assertThat(new Type("[[[Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String")));
87 } 77 }
88 78
89 @Test 79 @Test
@@ -98,7 +88,6 @@ public class TestType {
98 assertThat(new Type("D").isArray(), is(false)); 88 assertThat(new Type("D").isArray(), is(false));
99 assertThat(new Type("LFoo;").isArray(), is(false)); 89 assertThat(new Type("LFoo;").isArray(), is(false));
100 assertThat(new Type("[I").isArray(), is(true)); 90 assertThat(new Type("[I").isArray(), is(true));
101 assertThat(new Type("TFoo;").isArray(), is(false));
102 } 91 }
103 92
104 @Test 93 @Test
@@ -117,33 +106,9 @@ public class TestType {
117 } 106 }
118 107
119 @Test 108 @Test
120 public void isTemplate() {
121 assertThat(new Type("V").isTemplate(), is(false));
122 assertThat(new Type("Z").isTemplate(), is(false));
123 assertThat(new Type("B").isTemplate(), is(false));
124 assertThat(new Type("C").isTemplate(), is(false));
125 assertThat(new Type("I").isTemplate(), is(false));
126 assertThat(new Type("J").isTemplate(), is(false));
127 assertThat(new Type("F").isTemplate(), is(false));
128 assertThat(new Type("D").isTemplate(), is(false));
129 assertThat(new Type("LFoo;").isTemplate(), is(false));
130 assertThat(new Type("LFoo<LCow;>;").isTemplate(), is(false));
131 assertThat(new Type("LFoo<LCow;LBeer;>;").isTemplate(), is(false));
132 assertThat(new Type("LFoo<LPair<LCow;LBeer;>;>;").isTemplate(), is(false));
133 assertThat(new Type("[I").isTemplate(), is(false));
134 assertThat(new Type("TFoo;").isTemplate(), is(true));
135 }
136
137 @Test
138 public void getTemplate() {
139 assertThat(new Type("TT;").getTemplate(), is("T"));
140 assertThat(new Type("TFoo;").getTemplate(), is("Foo"));
141 }
142
143 @Test
144 public void hasClass() { 109 public void hasClass() {
145 assertThat(new Type("LFoo;").hasClass(), is(true)); 110 assertThat(new Type("LFoo;").hasClass(), is(true));
146 assertThat(new Type("LCow<LCheese;>;").hasClass(), is(true)); 111 assertThat(new Type("Ljava/lang/String;").hasClass(), is(true));
147 assertThat(new Type("[LBar;").hasClass(), is(true)); 112 assertThat(new Type("[LBar;").hasClass(), is(true));
148 assertThat(new Type("[[[LCat;").hasClass(), is(true)); 113 assertThat(new Type("[[[LCat;").hasClass(), is(true));
149 114
@@ -151,37 +116,6 @@ public class TestType {
151 assertThat(new Type("[I").hasClass(), is(false)); 116 assertThat(new Type("[I").hasClass(), is(false));
152 assertThat(new Type("[[[I").hasClass(), is(false)); 117 assertThat(new Type("[[[I").hasClass(), is(false));
153 assertThat(new Type("Z").hasClass(), is(false)); 118 assertThat(new Type("Z").hasClass(), is(false));
154 assertThat(new Type("TFoo;").hasClass(), is(false));
155 }
156
157 @Test
158 public void parameters() {
159 assertThat(new Type("LFoo<I>;").parameters(), contains(
160 new Type("I")
161 ));
162 assertThat(new Type("LFoo<IIII>;").parameters(), contains(
163 new Type("I"),
164 new Type("I"),
165 new Type("I"),
166 new Type("I")
167 ));
168 assertThat(new Type("LFoo<LBar;>;").parameters(), contains(
169 new Type("LBar;")
170 ));
171 assertThat(new Type("LFoo<LBar;LCow;LCheese;>;").parameters(), contains(
172 new Type("LBar;"),
173 new Type("LCow;"),
174 new Type("LCheese;")
175 ));
176
177 assertThat(new Type("LFoo<LBar<LCow;LCheese;>;>;").parameters(), contains(
178 new Type("LBar<LCow;LCheese;>;")
179 ));
180
181 assertThat(new Type("LFoo<LBar<LCow;LCheese;>;>;").parameters().iterator().next().parameters(), contains(
182 new Type("LCow;"),
183 new Type("LCheese;")
184 ));
185 } 119 }
186 120
187 @Test 121 @Test
@@ -218,37 +152,17 @@ public class TestType {
218 assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); 152 assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer));
219 } 153 }
220 { 154 {
221 final String answer = "LFoo<LFoo;>;"; 155 final String answer = "Ljava/lang/String;";
222 assertThat(Type.parseFirst("LFoo<LFoo;>;"), is(answer)); 156 assertThat(Type.parseFirst("Ljava/lang/String;"), is(answer));
223 assertThat(Type.parseFirst("LFoo<LFoo;>;I"), is(answer)); 157 assertThat(Type.parseFirst("Ljava/lang/String;I"), is(answer));
224 assertThat(Type.parseFirst("LFoo<LFoo;>;JZ"), is(answer)); 158 assertThat(Type.parseFirst("Ljava/lang/String;JZ"), is(answer));
225 assertThat(Type.parseFirst("LFoo<LFoo;>;[I"), is(answer)); 159 assertThat(Type.parseFirst("Ljava/lang/String;[I"), is(answer));
226 assertThat(Type.parseFirst("LFoo<LFoo;>;LFoo;"), is(answer)); 160 assertThat(Type.parseFirst("Ljava/lang/String;LFoo;"), is(answer));
227 assertThat(Type.parseFirst("LFoo<LFoo;>;[LFoo;"), is(answer)); 161 assertThat(Type.parseFirst("Ljava/lang/String;[LFoo;"), is(answer));
228 }
229 {
230 final String answer = "LFoo<LFoo;,LBar;>;";
231 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;"), is(answer));
232 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;I"), is(answer));
233 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;JZ"), is(answer));
234 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[I"), is(answer));
235 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;LFoo;"), is(answer));
236 assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[LFoo;"), is(answer));
237 } 162 }
238 } 163 }
239 164
240 @Test 165 @Test
241 public void parseTemplate() {
242 final String answer = "TFoo;";
243 assertThat(Type.parseFirst("TFoo;"), is(answer));
244 assertThat(Type.parseFirst("TFoo;I"), is(answer));
245 assertThat(Type.parseFirst("TFoo;JZ"), is(answer));
246 assertThat(Type.parseFirst("TFoo;[I"), is(answer));
247 assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer));
248 assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer));
249 }
250
251 @Test
252 public void parseArray() { 166 public void parseArray() {
253 { 167 {
254 final String answer = "[I"; 168 final String answer = "[I";
@@ -290,9 +204,6 @@ public class TestType {
290 assertThat(new Type("[I"), is(new Type("[I"))); 204 assertThat(new Type("[I"), is(new Type("[I")));
291 assertThat(new Type("[[[I"), is(new Type("[[[I"))); 205 assertThat(new Type("[[[I"), is(new Type("[[[I")));
292 assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); 206 assertThat(new Type("[LFoo;"), is(new Type("[LFoo;")));
293 assertThat(new Type("LFoo<LBar;>;"), is(new Type("LFoo<LBar;>;")));
294 assertThat(new Type("LFoo<LBar;>;"), is(new Type("LFoo<LCow;>;")));
295 assertThat(new Type("TFoo;"), is(new Type("TFoo;")));
296 207
297 assertThat(new Type("V"), is(not(new Type("I")))); 208 assertThat(new Type("V"), is(not(new Type("I"))));
298 assertThat(new Type("I"), is(not(new Type("J")))); 209 assertThat(new Type("I"), is(not(new Type("J"))));
@@ -302,7 +213,6 @@ public class TestType {
302 assertThat(new Type("[I"), is(not(new Type("[Z")))); 213 assertThat(new Type("[I"), is(not(new Type("[Z"))));
303 assertThat(new Type("[[[I"), is(not(new Type("[I")))); 214 assertThat(new Type("[[[I"), is(not(new Type("[I"))));
304 assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); 215 assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;"))));
305 assertThat(new Type("TFoo;"), is(not(new Type("TBar;"))));
306 } 216 }
307 217
308 @Test 218 @Test
@@ -319,62 +229,5 @@ public class TestType {
319 assertThat(new Type("[I").toString(), is("[I")); 229 assertThat(new Type("[I").toString(), is("[I"));
320 assertThat(new Type("[[[I").toString(), is("[[[I")); 230 assertThat(new Type("[[[I").toString(), is("[[[I"));
321 assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); 231 assertThat(new Type("[LFoo;").toString(), is("[LFoo;"));
322 assertThat(new Type("LFoo<LBar;>;").toString(), is("LFoo;"));
323 assertThat(new Type("LFoo<LCow;LCheese;>;").toString(), is("LFoo;"));
324 assertThat(new Type("LFoo<LPair<LCow;LCheese;>;>;").toString(), is("LFoo;"));
325 assertThat(new Type("TFoo;").toString(), is("TFoo;"));
326 }
327
328 private ParameterizedType ptype(String name) {
329 return new ParameterizedType(new Type(name));
330 }
331
332 @Test
333 public void equalsWithParameters() {
334 assertThat(ptype("V"), is(ptype("V")));
335 assertThat(ptype("Z"), is(ptype("Z")));
336 assertThat(ptype("B"), is(ptype("B")));
337 assertThat(ptype("C"), is(ptype("C")));
338 assertThat(ptype("I"), is(ptype("I")));
339 assertThat(ptype("J"), is(ptype("J")));
340 assertThat(ptype("F"), is(ptype("F")));
341 assertThat(ptype("D"), is(ptype("D")));
342 assertThat(ptype("LFoo;"), is(ptype("LFoo;")));
343 assertThat(ptype("[I"), is(ptype("[I")));
344 assertThat(ptype("[[[I"), is(ptype("[[[I")));
345 assertThat(ptype("[LFoo;"), is(ptype("[LFoo;")));
346 assertThat(ptype("LFoo<LBar;>;"), is(ptype("LFoo<LBar;>;")));
347 assertThat(ptype("TFoo;"), is(ptype("TFoo;")));
348
349 assertThat(ptype("V"), is(not(ptype("I"))));
350 assertThat(ptype("I"), is(not(ptype("J"))));
351 assertThat(ptype("I"), is(not(ptype("LBar;"))));
352 assertThat(ptype("I"), is(not(ptype("[I"))));
353 assertThat(ptype("LFoo;"), is(not(ptype("LBar;"))));
354 assertThat(ptype("[I"), is(not(ptype("[Z"))));
355 assertThat(ptype("[[[I"), is(not(ptype("[I"))));
356 assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;"))));
357 assertThat(ptype("LFoo<LBar;>;"), is(not(ptype("LFoo<LCow;>;"))));
358 assertThat(ptype("TFoo;"), is(not(ptype("TBar;"))));
359 }
360
361 @Test
362 public void testToStringWithParams() {
363 assertThat(ptype("V").toString(), is("V"));
364 assertThat(ptype("Z").toString(), is("Z"));
365 assertThat(ptype("B").toString(), is("B"));
366 assertThat(ptype("C").toString(), is("C"));
367 assertThat(ptype("I").toString(), is("I"));
368 assertThat(ptype("J").toString(), is("J"));
369 assertThat(ptype("F").toString(), is("F"));
370 assertThat(ptype("D").toString(), is("D"));
371 assertThat(ptype("LFoo;").toString(), is("LFoo;"));
372 assertThat(ptype("[I").toString(), is("[I"));
373 assertThat(ptype("[[[I").toString(), is("[[[I"));
374 assertThat(ptype("[LFoo;").toString(), is("[LFoo;"));
375 assertThat(ptype("LFoo<LBar;>;").toString(), is("LFoo<LBar;>;"));
376 assertThat(ptype("LFoo<LCow;LCheese;>;").toString(), is("LFoo<LCow;LCheese;>;"));
377 assertThat(ptype("LFoo<LPair<LCow;LCheese;>;>;").toString(), is("LFoo<LPair<LCow;LCheese;>;>;"));
378 assertThat(ptype("TFoo;").toString(), is("TFoo;"));
379 } 232 }
380} 233}