Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Unified Diff: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java

Issue 221483002: Fix for translation of \!= to \!identical(), but use == and \!= for Enum. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
diff --git a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
index 6b3b547d7f1332e322a1a28de39efa5fdb073169..b63fde3c0b0c581b700fb0786f561b21f66f7a1b 100644
--- a/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
+++ b/editor/util/plugins/com.google.dart.java2dart_test/src/com/google/dart/java2dart/SemanticTest.java
@@ -923,6 +923,45 @@ public class SemanticTest extends AbstractSemanticTest {
getFormattedSource(unit));
}
+ public void test_enum_equals() throws Exception {
+ setFileLines(
+ "test/Test.java",
+ toString(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "public class A {",
+ " public static enum Direction {",
+ " LEFT, RIGHT;",
+ " }",
+ " ",
+ " public void test(Object a, Direction b) {",
+ " print(a == Direction.LEFT);",
+ " print(a != Direction.RIGHT);",
+ " print(b == Direction.LEFT);",
+ " print(b != Direction.RIGHT);",
+ " }",
+ "}"));
+ context.addSourceFolder(tmpFolder);
+ context.addSourceFiles(tmpFolder);
+ translate();
+ assertEquals(
+ toString(
+ "class A {",
+ " void test(Object a, Direction b) {",
+ " print(identical(a, Direction.LEFT));",
+ " print(!identical(a, Direction.RIGHT));",
+ " print(b == Direction.LEFT);",
+ " print(b != Direction.RIGHT);",
+ " }",
+ "}",
+ "class Direction extends Enum<Direction> {",
+ " static const Direction LEFT = const Direction('LEFT', 0);",
+ " static const Direction RIGHT = const Direction('RIGHT', 1);",
+ " static const List<Direction> values = const [LEFT, RIGHT];",
+ " const Direction(String name, int ordinal) : super(name, ordinal);",
+ "}"),
+ getFormattedSource(unit));
+ }
+
public void test_enum_inner() throws Exception {
setFileLines(
"test/Test.java",
@@ -1005,6 +1044,59 @@ public class SemanticTest extends AbstractSemanticTest {
getFormattedSource(unit));
}
+ public void test_expression_equals() throws Exception {
+ setFileLines(
+ "test/Test.java",
+ toString(
+ "// filler filler filler filler filler filler filler filler filler filler",
+ "public class Test {",
+ " boolean testObject(Object a, Object b) {",
+ " return a == b;",
+ " }",
+ " boolean testNull(Object p) {",
+ " return p == null;",
+ " }",
+ " boolean testBool(Object p, boolean t) {",
+ " return p == true || p == t;",
+ " }",
+ " boolean testChar(Object p, char t) {",
+ " return p == '0' || p == t;",
+ " }",
+ " boolean testByte(Object p, byte t) {",
+ " return p == (byte) 1 || p == t;",
+ " }",
+ " boolean testInt(Object p, int t) {",
+ " return p == 2 || p == t;",
+ " }",
+ " boolean testLong(Object p, long t) {",
+ " return p == 3L || p == t;",
+ " }",
+ " boolean testFloat(Object p, float t) {",
+ " return p == 4.0f || p == t;",
+ " }",
+ " boolean testDouble(Object p, double t) {",
+ " return p == 5.0d || p == t;",
+ " }",
+ "}"));
+ context.addSourceFolder(tmpFolder);
+ context.addSourceFiles(tmpFolder);
+ translate();
+ assertEquals(
+ toString(
+ "class Test {",
+ " bool _testObject(Object a, Object b) => identical(a, b);",
+ " bool _testNull(Object p) => p == null;",
+ " bool _testBool(Object p, bool t) => p == true || p == t;",
+ " bool _testChar(Object p, int t) => p == 0x30 || p == t;",
+ " bool _testByte(Object p, int t) => p == 1 || p == t;",
+ " bool _testInt(Object p, int t) => p == 2 || p == t;",
+ " bool _testLong(Object p, int t) => p == 3 || p == t;",
+ " bool _testFloat(Object p, double t) => p == 4.0 || p == t;",
+ " bool _testDouble(Object p, double t) => p == 5.0 || p == t;",
+ "}"),
+ getFormattedSource(unit));
+ }
+
/**
* <p>
* https://code.google.com/p/dart/issues/detail?id=9845

Powered by Google App Engine
This is Rietveld 408576698