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

Unified Diff: tests/compiler/dart2js/type_checker_test.dart

Issue 710343002: Check enums in switch cases. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments + process deferred actions in test Created 6 years, 1 month 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
« no previous file with comments | « tests/compiler/dart2js/resolver_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/type_checker_test.dart
diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart
index c7ab34ba36a8ddb64a05cf47adc9e55a95dfd2b6..f00a0d7823546941a5355955d56299dd6cc65f5a 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -29,6 +29,7 @@ main() {
testWhile,
testTry,
testSwitch,
+ testEnumSwitch,
testOperators,
testConstructorInvocationArgumentCount,
testConstructorInvocationArgumentTypes,
@@ -169,6 +170,89 @@ testSwitch(MockCompiler compiler) {
warnings: [NOT_ASSIGNABLE, NOT_ASSIGNABLE]);
}
+testEnumSwitch(MockCompiler compiler) {
+ String DECLARATIONS = """
+enum Enum { A, B, C }
+""";
+
+ check(String code, {warnings}) {
+ MockCompiler compiler = new MockCompiler.internal(enableEnums: true);
+ return compiler.init(DECLARATIONS).then((_) {
+ analyze(compiler, code, warnings: warnings, flushDeferred: true);
+ });
+ }
+
+ check("""
+switch (Enum.A) {
+default: break;
+}""");
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+default: break;
+}""");
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+case Enum.B: break;
+default: break;
+}""");
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+case Enum.B: break;
+case Enum.C: break;
+default: break;
+}""");
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+case Enum.B: break;
+case Enum.C: break;
+}""");
+
+ check("""
+switch (Enum.A) {
+case Enum.B: break;
+case Enum.C: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+case Enum.C: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+case Enum.B: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+case Enum.A: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+case Enum.B: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+case Enum.C: break;
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+
+ check("""
+switch (Enum.A) {
+}""", warnings: MessageKind.MISSING_ENUM_CASES);
+}
+
testOperators(MockCompiler compiler) {
check(String code, {warnings}) {
analyze(compiler, code, warnings: warnings);
@@ -2061,7 +2145,8 @@ analyzeTopLevel(String text, [expectedWarnings]) {
*/
analyze(MockCompiler compiler,
String text,
- {errors, warnings, List hints, List infos}) {
+ {errors, warnings, List hints, List infos,
+ bool flushDeferred: false}) {
if (warnings == null) warnings = [];
if (warnings is !List) warnings = [warnings];
if (errors == null) errors = [];
@@ -2078,10 +2163,14 @@ analyze(MockCompiler compiler,
new CompilationUnitElementX(new Script(null, null, null), compiler.mainApp);
Element function = new MockElement(compilationUnit);
TreeElements elements = compiler.resolveNodeStatement(node, function);
+ compiler.enqueuer.resolution.emptyDeferredTaskQueue();
TypeCheckerVisitor checker = new TypeCheckerVisitor(
compiler, elements, compiler.types);
compiler.clearMessages();
checker.analyze(node);
+ if (flushDeferred) {
+ compiler.enqueuer.resolution.emptyDeferredTaskQueue();
+ }
compareWarningKinds(text, warnings, compiler.warnings);
compareWarningKinds(text, errors, compiler.errors);
if (hints != null) compareWarningKinds(text, hints, compiler.hints);
« no previous file with comments | « tests/compiler/dart2js/resolver_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698