summaryrefslogtreecommitdiff
path: root/test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java')
-rw-r--r--test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java b/test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java
index 2573648..476da87 100644
--- a/test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java
+++ b/test/java/com/google/devtools/build/android/desugar/BytecodeTypeInferenceTest.java
@@ -13,8 +13,11 @@
// limitations under the License.
package com.google.devtools.build.android.desugar;
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableMap;
import com.google.common.io.Files;
-import com.google.common.truth.Truth;
+import com.google.devtools.build.android.desugar.BytecodeTypeInference.InferredType;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -24,6 +27,7 @@ import java.nio.file.Paths;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
+import org.objectweb.asm.Label;
/** Test for {@link BytecodeTypeInference} */
@RunWith(JUnit4.class)
@@ -33,7 +37,7 @@ public class BytecodeTypeInferenceTest {
private static final Path GOLDEN_PATH = Paths.get(System.getProperty("golden_file"));
@Test
- public void test() throws IOException {
+ public void testTypeInference() throws IOException {
StringWriter stringWriter = new StringWriter();
try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
ByteCodeTypePrinter.printClassesWithTypes(JAR_PATH, printWriter);
@@ -41,6 +45,37 @@ public class BytecodeTypeInferenceTest {
}
String inferenceResult = stringWriter.toString().trim();
String golden = Files.asCharSource(GOLDEN_PATH.toFile(), StandardCharsets.UTF_8).read().trim();
- Truth.assertThat(inferenceResult).isEqualTo(golden);
+ assertThat(inferenceResult).isEqualTo(golden);
+ }
+
+ @Test
+ public void testUninitializedInferType() {
+ Label label = new Label();
+ InferredType type = InferredType.createUninitializedType(label);
+ assertThat(type.descriptor()).isEqualTo(InferredType.UNINITIALIZED_PREFIX);
+ assertThat(type.uninitializationLabel()).isEqualTo(label);
+ }
+
+ @Test
+ public void testNonUninitializedInferType() {
+ ImmutableMap<String, InferredType> map =
+ ImmutableMap.<String, InferredType>builder()
+ .put("Z", InferredType.BOOLEAN)
+ .put("B", InferredType.BYTE)
+ .put("I", InferredType.INT)
+ .put("F", InferredType.FLOAT)
+ .put("D", InferredType.DOUBLE)
+ .put("J", InferredType.LONG)
+ .put("TOP", InferredType.TOP)
+ .put("NULL", InferredType.NULL)
+ .put("UNINITIALIZED_THIS", InferredType.UNINITIALIZED_THIS)
+ .build();
+ map.forEach(
+ (descriptor, expected) -> {
+ InferredType type = InferredType.createNonUninitializedType(descriptor);
+ assertThat(type.uninitializationLabel()).isNull();
+ assertThat(type.descriptor()).isEqualTo(descriptor);
+ assertThat(type).isSameAs(expected);
+ });
}
}