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

Unified Diff: tests/language_2/if_null_behavior_test.dart

Issue 3003933002: Migrate block 116. (Closed)
Patch Set: Created 3 years, 4 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: tests/language_2/if_null_behavior_test.dart
diff --git a/tests/language_2/if_null_behavior_test.dart b/tests/language_2/if_null_behavior_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b973647e69a233b1dc4145ca7e7e3739cdac27be
--- /dev/null
+++ b/tests/language_2/if_null_behavior_test.dart
@@ -0,0 +1,53 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Evaluation of an if-null expression e of the form e1 ?? e2 is equivalent to
+// the evaluation of the expression ((x) => x == null ? e2 : x)(e1). The
+// static type of e is the least upper bound of the static type of e1 and the
+// static type of e2.
+
+import "package:expect/expect.dart";
+
+class A {
+ final String a;
+ A(this.a);
+}
+
+class B extends A {
+ B(String v)
+ : b = v,
+ super(v);
+ final String b;
+}
+
+class C extends A {
+ C(String v)
+ : c = v,
+ super(v);
+ final String c;
+}
+
+B nullB() => null;
+C nullC() => null;
+
+noMethod(e) => e is NoSuchMethodError;
+
+main() {
+ Expect.equals(1, 1 ?? 2);
+ Expect.equals(1, 1 ?? null);
+ Expect.equals(2, null ?? 2);
+ Expect.equals(null, null ?? null);
+ Expect.equals('B', (new B('B') ?? new C('C')).a);
+ Expect.equals('B', ((new B('B') ?? new C('C')) as dynamic).b);
+ Expect.throwsNoSuchMethodError(() => ((new B('B') ?? new C('C')) as dynamic).c);
+ Expect.equals('B', (new B('B') ?? nullC()).a);
+ Expect.equals('B', ((new B('B') ?? nullC()) as dynamic).b);
+ Expect.throwsNoSuchMethodError(() => ((new B('B') ?? nullC()) as dynamic).c);
+ Expect.equals('C', (nullB() ?? new C('C')).a);
+ Expect.throwsNoSuchMethodError(() => ((nullB() ?? new C('C')) as dynamic).b);
+ Expect.equals('C', ((nullB() ?? new C('C')) as dynamic).c);
+ Expect.throwsNoSuchMethodError(() => (nullB() ?? nullC()).a);
+ Expect.throwsNoSuchMethodError(() => ((nullB() ?? nullC()) as dynamic).b);
+ Expect.throwsNoSuchMethodError(() => ((nullB() ?? nullC()) as dynamic).c);
+}

Powered by Google App Engine
This is Rietveld 408576698