diff options
Diffstat (limited to 'src/test/java/cuchaz/enigma/TestMethodDescriptor.java')
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestMethodDescriptor.java | 247 |
1 files changed, 0 insertions, 247 deletions
diff --git a/src/test/java/cuchaz/enigma/TestMethodDescriptor.java b/src/test/java/cuchaz/enigma/TestMethodDescriptor.java deleted file mode 100644 index a73880d..0000000 --- a/src/test/java/cuchaz/enigma/TestMethodDescriptor.java +++ /dev/null | |||
| @@ -1,247 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.translation.representation.MethodDescriptor; | ||
| 15 | import cuchaz.enigma.translation.representation.TypeDescriptor; | ||
| 16 | import org.junit.Test; | ||
| 17 | |||
| 18 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 19 | import static org.hamcrest.Matchers.*; | ||
| 20 | |||
| 21 | public class TestMethodDescriptor { | ||
| 22 | |||
| 23 | @Test | ||
| 24 | public void easiest() { | ||
| 25 | final MethodDescriptor sig = new MethodDescriptor("()V"); | ||
| 26 | assertThat(sig.getArgumentDescs(), is(empty())); | ||
| 27 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 28 | } | ||
| 29 | |||
| 30 | @Test | ||
| 31 | public void primitives() { | ||
| 32 | { | ||
| 33 | final MethodDescriptor sig = new MethodDescriptor("(I)V"); | ||
| 34 | assertThat(sig.getArgumentDescs(), contains( | ||
| 35 | new TypeDescriptor("I") | ||
| 36 | )); | ||
| 37 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 38 | } | ||
| 39 | { | ||
| 40 | final MethodDescriptor sig = new MethodDescriptor("(I)I"); | ||
| 41 | assertThat(sig.getArgumentDescs(), contains( | ||
| 42 | new TypeDescriptor("I") | ||
| 43 | )); | ||
| 44 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("I"))); | ||
| 45 | } | ||
| 46 | { | ||
| 47 | final MethodDescriptor sig = new MethodDescriptor("(IBCJ)Z"); | ||
| 48 | assertThat(sig.getArgumentDescs(), contains( | ||
| 49 | new TypeDescriptor("I"), | ||
| 50 | new TypeDescriptor("B"), | ||
| 51 | new TypeDescriptor("C"), | ||
| 52 | new TypeDescriptor("J") | ||
| 53 | )); | ||
| 54 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z"))); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test | ||
| 59 | public void classes() { | ||
| 60 | { | ||
| 61 | final MethodDescriptor sig = new MethodDescriptor("([LFoo;)V"); | ||
| 62 | assertThat(sig.getArgumentDescs().size(), is(1)); | ||
| 63 | assertThat(sig.getArgumentDescs().get(0), is(new TypeDescriptor("[LFoo;"))); | ||
| 64 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 65 | } | ||
| 66 | { | ||
| 67 | final MethodDescriptor sig = new MethodDescriptor("(LFoo;)LBar;"); | ||
| 68 | assertThat(sig.getArgumentDescs(), contains( | ||
| 69 | new TypeDescriptor("LFoo;") | ||
| 70 | )); | ||
| 71 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;"))); | ||
| 72 | } | ||
| 73 | { | ||
| 74 | final MethodDescriptor sig = new MethodDescriptor("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 75 | assertThat(sig.getArgumentDescs(), contains( | ||
| 76 | new TypeDescriptor("LFoo;"), | ||
| 77 | new TypeDescriptor("LMoo;"), | ||
| 78 | new TypeDescriptor("LZoo;") | ||
| 79 | )); | ||
| 80 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LBar;"))); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | @Test | ||
| 85 | public void arrays() { | ||
| 86 | { | ||
| 87 | final MethodDescriptor sig = new MethodDescriptor("([I)V"); | ||
| 88 | assertThat(sig.getArgumentDescs(), contains( | ||
| 89 | new TypeDescriptor("[I") | ||
| 90 | )); | ||
| 91 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 92 | } | ||
| 93 | { | ||
| 94 | final MethodDescriptor sig = new MethodDescriptor("([I)[J"); | ||
| 95 | assertThat(sig.getArgumentDescs(), contains( | ||
| 96 | new TypeDescriptor("[I") | ||
| 97 | )); | ||
| 98 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[J"))); | ||
| 99 | } | ||
| 100 | { | ||
| 101 | final MethodDescriptor sig = new MethodDescriptor("([I[Z[F)[D"); | ||
| 102 | assertThat(sig.getArgumentDescs(), contains( | ||
| 103 | new TypeDescriptor("[I"), | ||
| 104 | new TypeDescriptor("[Z"), | ||
| 105 | new TypeDescriptor("[F") | ||
| 106 | )); | ||
| 107 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[D"))); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void mixed() { | ||
| 113 | { | ||
| 114 | final MethodDescriptor sig = new MethodDescriptor("(I[JLFoo;)Z"); | ||
| 115 | assertThat(sig.getArgumentDescs(), contains( | ||
| 116 | new TypeDescriptor("I"), | ||
| 117 | new TypeDescriptor("[J"), | ||
| 118 | new TypeDescriptor("LFoo;") | ||
| 119 | )); | ||
| 120 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("Z"))); | ||
| 121 | } | ||
| 122 | { | ||
| 123 | final MethodDescriptor sig = new MethodDescriptor("(III)[LFoo;"); | ||
| 124 | assertThat(sig.getArgumentDescs(), contains( | ||
| 125 | new TypeDescriptor("I"), | ||
| 126 | new TypeDescriptor("I"), | ||
| 127 | new TypeDescriptor("I") | ||
| 128 | )); | ||
| 129 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[LFoo;"))); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | @Test | ||
| 134 | public void replaceClasses() { | ||
| 135 | { | ||
| 136 | final MethodDescriptor oldSig = new MethodDescriptor("()V"); | ||
| 137 | final MethodDescriptor sig = oldSig.remap(s -> null); | ||
| 138 | assertThat(sig.getArgumentDescs(), is(empty())); | ||
| 139 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 140 | } | ||
| 141 | { | ||
| 142 | final MethodDescriptor oldSig = new MethodDescriptor("(IJLFoo;)V"); | ||
| 143 | final MethodDescriptor sig = oldSig.remap(s -> null); | ||
| 144 | assertThat(sig.getArgumentDescs(), contains( | ||
| 145 | new TypeDescriptor("I"), | ||
| 146 | new TypeDescriptor("J"), | ||
| 147 | new TypeDescriptor("LFoo;") | ||
| 148 | )); | ||
| 149 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("V"))); | ||
| 150 | } | ||
| 151 | { | ||
| 152 | final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;"); | ||
| 153 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 154 | if (s.equals("Foo")) { | ||
| 155 | return "Bar"; | ||
| 156 | } | ||
| 157 | return null; | ||
| 158 | }); | ||
| 159 | assertThat(sig.getArgumentDescs(), contains( | ||
| 160 | new TypeDescriptor("LBar;"), | ||
| 161 | new TypeDescriptor("LBar;") | ||
| 162 | )); | ||
| 163 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LMoo;"))); | ||
| 164 | } | ||
| 165 | { | ||
| 166 | final MethodDescriptor oldSig = new MethodDescriptor("(LFoo;LBar;)LMoo;"); | ||
| 167 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 168 | if (s.equals("Moo")) { | ||
| 169 | return "Cow"; | ||
| 170 | } | ||
| 171 | return null; | ||
| 172 | }); | ||
| 173 | assertThat(sig.getArgumentDescs(), contains( | ||
| 174 | new TypeDescriptor("LFoo;"), | ||
| 175 | new TypeDescriptor("LBar;") | ||
| 176 | )); | ||
| 177 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("LCow;"))); | ||
| 178 | } | ||
| 179 | } | ||
| 180 | |||
| 181 | @Test | ||
| 182 | public void replaceArrayClasses() { | ||
| 183 | { | ||
| 184 | final MethodDescriptor oldSig = new MethodDescriptor("([LFoo;)[[[LBar;"); | ||
| 185 | final MethodDescriptor sig = oldSig.remap(s -> { | ||
| 186 | if (s.equals("Foo")) { | ||
| 187 | return "Food"; | ||
| 188 | } else if (s.equals("Bar")) { | ||
| 189 | return "Beer"; | ||
| 190 | } | ||
| 191 | return null; | ||
| 192 | }); | ||
| 193 | assertThat(sig.getArgumentDescs(), contains( | ||
| 194 | new TypeDescriptor("[LFood;") | ||
| 195 | )); | ||
| 196 | assertThat(sig.getReturnDesc(), is(new TypeDescriptor("[[[LBeer;"))); | ||
| 197 | } | ||
| 198 | } | ||
| 199 | |||
| 200 | @Test | ||
| 201 | public void equals() { | ||
| 202 | |||
| 203 | // base | ||
| 204 | assertThat(new MethodDescriptor("()V"), is(new MethodDescriptor("()V"))); | ||
| 205 | |||
| 206 | // arguments | ||
| 207 | assertThat(new MethodDescriptor("(I)V"), is(new MethodDescriptor("(I)V"))); | ||
| 208 | assertThat(new MethodDescriptor("(ZIZ)V"), is(new MethodDescriptor("(ZIZ)V"))); | ||
| 209 | assertThat(new MethodDescriptor("(LFoo;)V"), is(new MethodDescriptor("(LFoo;)V"))); | ||
| 210 | assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(new MethodDescriptor("(LFoo;LBar;)V"))); | ||
| 211 | assertThat(new MethodDescriptor("([I)V"), is(new MethodDescriptor("([I)V"))); | ||
| 212 | assertThat(new MethodDescriptor("([[D[[[J)V"), is(new MethodDescriptor("([[D[[[J)V"))); | ||
| 213 | |||
| 214 | assertThat(new MethodDescriptor("()V"), is(not(new MethodDescriptor("(I)V")))); | ||
| 215 | assertThat(new MethodDescriptor("(I)V"), is(not(new MethodDescriptor("()V")))); | ||
| 216 | assertThat(new MethodDescriptor("(IJ)V"), is(not(new MethodDescriptor("(JI)V")))); | ||
| 217 | assertThat(new MethodDescriptor("([[Z)V"), is(not(new MethodDescriptor("([[LFoo;)V")))); | ||
| 218 | assertThat(new MethodDescriptor("(LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V")))); | ||
| 219 | assertThat(new MethodDescriptor("([LFoo;LBar;)V"), is(not(new MethodDescriptor("(LFoo;LCow;)V")))); | ||
| 220 | |||
| 221 | // return desc | ||
| 222 | assertThat(new MethodDescriptor("()I"), is(new MethodDescriptor("()I"))); | ||
| 223 | assertThat(new MethodDescriptor("()Z"), is(new MethodDescriptor("()Z"))); | ||
| 224 | assertThat(new MethodDescriptor("()[D"), is(new MethodDescriptor("()[D"))); | ||
| 225 | assertThat(new MethodDescriptor("()[[[Z"), is(new MethodDescriptor("()[[[Z"))); | ||
| 226 | assertThat(new MethodDescriptor("()LFoo;"), is(new MethodDescriptor("()LFoo;"))); | ||
| 227 | assertThat(new MethodDescriptor("()[LFoo;"), is(new MethodDescriptor("()[LFoo;"))); | ||
| 228 | |||
| 229 | assertThat(new MethodDescriptor("()I"), is(not(new MethodDescriptor("()Z")))); | ||
| 230 | assertThat(new MethodDescriptor("()Z"), is(not(new MethodDescriptor("()I")))); | ||
| 231 | assertThat(new MethodDescriptor("()[D"), is(not(new MethodDescriptor("()[J")))); | ||
| 232 | assertThat(new MethodDescriptor("()[[[Z"), is(not(new MethodDescriptor("()[[Z")))); | ||
| 233 | assertThat(new MethodDescriptor("()LFoo;"), is(not(new MethodDescriptor("()LBar;")))); | ||
| 234 | assertThat(new MethodDescriptor("()[LFoo;"), is(not(new MethodDescriptor("()[LBar;")))); | ||
| 235 | } | ||
| 236 | |||
| 237 | @Test | ||
| 238 | public void testToString() { | ||
| 239 | assertThat(new MethodDescriptor("()V").toString(), is("()V")); | ||
| 240 | assertThat(new MethodDescriptor("(I)V").toString(), is("(I)V")); | ||
| 241 | assertThat(new MethodDescriptor("(ZIZ)V").toString(), is("(ZIZ)V")); | ||
| 242 | assertThat(new MethodDescriptor("(LFoo;)V").toString(), is("(LFoo;)V")); | ||
| 243 | assertThat(new MethodDescriptor("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); | ||
| 244 | assertThat(new MethodDescriptor("([I)V").toString(), is("([I)V")); | ||
| 245 | assertThat(new MethodDescriptor("([[D[[[J)V").toString(), is("([[D[[[J)V")); | ||
| 246 | } | ||
| 247 | } | ||