From ecfda21f3db9e62e3acf074e9842e92ace4cb3ab Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 17 Mar 2015 20:01:55 -0400 Subject: parsing generic signatures is tricky. don't write custom code to do it. switching to library instead --- test/cuchaz/enigma/TestType.java | 167 +++------------------------------------ 1 file changed, 10 insertions(+), 157 deletions(-) (limited to 'test') 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.*; import org.junit.Test; -import cuchaz.enigma.mapping.ParameterizedType; import cuchaz.enigma.mapping.Type; @@ -24,7 +23,6 @@ public class TestType { assertThat(new Type("D").isVoid(), is(false)); assertThat(new Type("LFoo;").isVoid(), is(false)); assertThat(new Type("[I").isVoid(), is(false)); - assertThat(new Type("TFoo;").isVoid(), is(false)); } @Test @@ -39,7 +37,6 @@ public class TestType { assertThat(new Type("D").isPrimitive(), is(true)); assertThat(new Type("LFoo;").isPrimitive(), is(false)); assertThat(new Type("[I").isPrimitive(), is(false)); - assertThat(new Type("TFoo;").isPrimitive(), is(false)); } @Test @@ -64,26 +61,19 @@ public class TestType { assertThat(new Type("F").isClass(), is(false)); assertThat(new Type("D").isClass(), is(false)); assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;>;").isClass(), is(true)); assertThat(new Type("[I").isClass(), is(false)); - assertThat(new Type("TFoo;").isClass(), is(false)); } @Test public void getClassEntry() { assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;>;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); } @Test public void getArrayClassEntry() { assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("[[[LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("[[[Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); } @Test @@ -98,7 +88,6 @@ public class TestType { assertThat(new Type("D").isArray(), is(false)); assertThat(new Type("LFoo;").isArray(), is(false)); assertThat(new Type("[I").isArray(), is(true)); - assertThat(new Type("TFoo;").isArray(), is(false)); } @Test @@ -116,34 +105,10 @@ public class TestType { assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); } - @Test - public void isTemplate() { - assertThat(new Type("V").isTemplate(), is(false)); - assertThat(new Type("Z").isTemplate(), is(false)); - assertThat(new Type("B").isTemplate(), is(false)); - assertThat(new Type("C").isTemplate(), is(false)); - assertThat(new Type("I").isTemplate(), is(false)); - assertThat(new Type("J").isTemplate(), is(false)); - assertThat(new Type("F").isTemplate(), is(false)); - assertThat(new Type("D").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;>;").isTemplate(), is(false)); - assertThat(new Type("[I").isTemplate(), is(false)); - assertThat(new Type("TFoo;").isTemplate(), is(true)); - } - - @Test - public void getTemplate() { - assertThat(new Type("TT;").getTemplate(), is("T")); - assertThat(new Type("TFoo;").getTemplate(), is("Foo")); - } - @Test public void hasClass() { assertThat(new Type("LFoo;").hasClass(), is(true)); - assertThat(new Type("LCow;").hasClass(), is(true)); + assertThat(new Type("Ljava/lang/String;").hasClass(), is(true)); assertThat(new Type("[LBar;").hasClass(), is(true)); assertThat(new Type("[[[LCat;").hasClass(), is(true)); @@ -151,37 +116,6 @@ public class TestType { assertThat(new Type("[I").hasClass(), is(false)); assertThat(new Type("[[[I").hasClass(), is(false)); assertThat(new Type("Z").hasClass(), is(false)); - assertThat(new Type("TFoo;").hasClass(), is(false)); - } - - @Test - public void parameters() { - assertThat(new Type("LFoo;").parameters(), contains( - new Type("I") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("I"), - new Type("I"), - new Type("I"), - new Type("I") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("LBar;") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("LBar;"), - new Type("LCow;"), - new Type("LCheese;") - )); - - assertThat(new Type("LFoo;>;").parameters(), contains( - new Type("LBar;") - )); - - assertThat(new Type("LFoo;>;").parameters().iterator().next().parameters(), contains( - new Type("LCow;"), - new Type("LCheese;") - )); } @Test @@ -218,36 +152,16 @@ public class TestType { assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); } { - final String answer = "LFoo;"; - assertThat(Type.parseFirst("LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;I"), is(answer)); - assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("LFoo;[I"), is(answer)); - assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); - } - { - final String answer = "LFoo;"; - assertThat(Type.parseFirst("LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;I"), is(answer)); - assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("LFoo;[I"), is(answer)); - assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); + final String answer = "Ljava/lang/String;"; + assertThat(Type.parseFirst("Ljava/lang/String;"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;I"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;JZ"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;[I"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;LFoo;"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;[LFoo;"), is(answer)); } } - @Test - public void parseTemplate() { - final String answer = "TFoo;"; - assertThat(Type.parseFirst("TFoo;"), is(answer)); - assertThat(Type.parseFirst("TFoo;I"), is(answer)); - assertThat(Type.parseFirst("TFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("TFoo;[I"), is(answer)); - assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer)); - } - @Test public void parseArray() { { @@ -290,9 +204,6 @@ public class TestType { assertThat(new Type("[I"), is(new Type("[I"))); assertThat(new Type("[[[I"), is(new Type("[[[I"))); assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); - assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); - assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); - assertThat(new Type("TFoo;"), is(new Type("TFoo;"))); assertThat(new Type("V"), is(not(new Type("I")))); assertThat(new Type("I"), is(not(new Type("J")))); @@ -302,7 +213,6 @@ public class TestType { assertThat(new Type("[I"), is(not(new Type("[Z")))); assertThat(new Type("[[[I"), is(not(new Type("[I")))); assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); - assertThat(new Type("TFoo;"), is(not(new Type("TBar;")))); } @Test @@ -319,62 +229,5 @@ public class TestType { assertThat(new Type("[I").toString(), is("[I")); assertThat(new Type("[[[I").toString(), is("[[[I")); assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); - assertThat(new Type("LFoo;").toString(), is("LFoo;")); - assertThat(new Type("LFoo;").toString(), is("LFoo;")); - assertThat(new Type("LFoo;>;").toString(), is("LFoo;")); - assertThat(new Type("TFoo;").toString(), is("TFoo;")); - } - - private ParameterizedType ptype(String name) { - return new ParameterizedType(new Type(name)); - } - - @Test - public void equalsWithParameters() { - assertThat(ptype("V"), is(ptype("V"))); - assertThat(ptype("Z"), is(ptype("Z"))); - assertThat(ptype("B"), is(ptype("B"))); - assertThat(ptype("C"), is(ptype("C"))); - assertThat(ptype("I"), is(ptype("I"))); - assertThat(ptype("J"), is(ptype("J"))); - assertThat(ptype("F"), is(ptype("F"))); - assertThat(ptype("D"), is(ptype("D"))); - assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); - assertThat(ptype("[I"), is(ptype("[I"))); - assertThat(ptype("[[[I"), is(ptype("[[[I"))); - assertThat(ptype("[LFoo;"), is(ptype("[LFoo;"))); - assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); - assertThat(ptype("TFoo;"), is(ptype("TFoo;"))); - - assertThat(ptype("V"), is(not(ptype("I")))); - assertThat(ptype("I"), is(not(ptype("J")))); - assertThat(ptype("I"), is(not(ptype("LBar;")))); - assertThat(ptype("I"), is(not(ptype("[I")))); - assertThat(ptype("LFoo;"), is(not(ptype("LBar;")))); - assertThat(ptype("[I"), is(not(ptype("[Z")))); - assertThat(ptype("[[[I"), is(not(ptype("[I")))); - assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;")))); - assertThat(ptype("LFoo;"), is(not(ptype("LFoo;")))); - assertThat(ptype("TFoo;"), is(not(ptype("TBar;")))); - } - - @Test - public void testToStringWithParams() { - assertThat(ptype("V").toString(), is("V")); - assertThat(ptype("Z").toString(), is("Z")); - assertThat(ptype("B").toString(), is("B")); - assertThat(ptype("C").toString(), is("C")); - assertThat(ptype("I").toString(), is("I")); - assertThat(ptype("J").toString(), is("J")); - assertThat(ptype("F").toString(), is("F")); - assertThat(ptype("D").toString(), is("D")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("[I").toString(), is("[I")); - assertThat(ptype("[[[I").toString(), is("[[[I")); - assertThat(ptype("[LFoo;").toString(), is("[LFoo;")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("LFoo;>;").toString(), is("LFoo;>;")); - assertThat(ptype("TFoo;").toString(), is("TFoo;")); } } -- cgit v1.2.3