aboutsummaryrefslogtreecommitdiff
path: root/javatests
diff options
context:
space:
mode:
authorcushon <cushon@google.com>2018-10-21 15:10:51 -0700
committerLiam Miller-Cushon <cushon@google.com>2018-10-22 12:48:53 -0700
commit7867013530435dd5718b0b80637fa3cda7361c03 (patch)
tree9c3d63dbebbbeba4fc63f078a7008026c550629f /javatests
parentdb60838c741ffebfe7141071da243beb901384e4 (diff)
downloadturbine-7867013530435dd5718b0b80637fa3cda7361c03.tar.gz
Implement equals, hashCode, and toString for `Const` model objects
MOE_MIGRATED_REVID=218089802
Diffstat (limited to 'javatests')
-rw-r--r--javatests/com/google/turbine/model/ConstTest.java73
1 files changed, 73 insertions, 0 deletions
diff --git a/javatests/com/google/turbine/model/ConstTest.java b/javatests/com/google/turbine/model/ConstTest.java
new file mode 100644
index 0000000..9b34343
--- /dev/null
+++ b/javatests/com/google/turbine/model/ConstTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2018 Google Inc. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.turbine.model;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.testing.EqualsTester;
+import com.google.turbine.binder.bound.AnnotationValue;
+import com.google.turbine.binder.sym.ClassSymbol;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class ConstTest {
+ @Test
+ public void equalsTest() {
+ new EqualsTester()
+ .addEqualityGroup(new Const.BooleanValue(true), new Const.BooleanValue(true))
+ .addEqualityGroup(new Const.BooleanValue(false), new Const.BooleanValue(false))
+ .addEqualityGroup(new Const.IntValue(1), new Const.IntValue(1))
+ .addEqualityGroup(new Const.IntValue(2), new Const.IntValue(2))
+ .addEqualityGroup(new Const.LongValue(1), new Const.LongValue(1))
+ .addEqualityGroup(new Const.LongValue(2), new Const.LongValue(2))
+ .addEqualityGroup(new Const.CharValue('x'), new Const.CharValue('x'))
+ .addEqualityGroup(new Const.CharValue('y'), new Const.CharValue('y'))
+ .addEqualityGroup(new Const.FloatValue(1), new Const.FloatValue(1))
+ .addEqualityGroup(new Const.FloatValue(2), new Const.FloatValue(2))
+ .addEqualityGroup(new Const.DoubleValue(1), new Const.DoubleValue(1))
+ .addEqualityGroup(new Const.DoubleValue(2), new Const.DoubleValue(2))
+ .addEqualityGroup(new Const.StringValue("a"), new Const.StringValue("a"))
+ .addEqualityGroup(new Const.StringValue("b"), new Const.StringValue("b"))
+ .addEqualityGroup(new Const.ShortValue((short) 1), new Const.ShortValue((short) 1))
+ .addEqualityGroup(new Const.ShortValue((short) 2), new Const.ShortValue((short) 2))
+ .addEqualityGroup(new Const.ByteValue((byte) 1), new Const.ByteValue((byte) 1))
+ .addEqualityGroup(new Const.ByteValue((byte) 2), new Const.ByteValue((byte) 2))
+ .addEqualityGroup(
+ new Const.ArrayInitValue(
+ ImmutableList.of(new Const.IntValue(1), new Const.IntValue(2))),
+ new Const.ArrayInitValue(
+ ImmutableList.of(new Const.IntValue(1), new Const.IntValue(2))))
+ .addEqualityGroup(
+ new Const.ArrayInitValue(
+ ImmutableList.of(new Const.IntValue(3), new Const.IntValue(4))),
+ new Const.ArrayInitValue(
+ ImmutableList.of(new Const.IntValue(3), new Const.IntValue(4))))
+ .addEqualityGroup(
+ new AnnotationValue(
+ new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(3))),
+ new AnnotationValue(
+ new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(3))))
+ .addEqualityGroup(
+ new AnnotationValue(
+ new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(4))),
+ new AnnotationValue(
+ new ClassSymbol("test/Anno"), ImmutableMap.of("value", new Const.IntValue(4))))
+ .testEquals();
+ }
+}