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

Side by Side Diff: tests/language_2/if_null_behavior_test.dart

Issue 3003933002: Migrate block 116. (Closed)
Patch Set: Created 3 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Evaluation of an if-null expression e of the form e1 ?? e2 is equivalent to
6 // the evaluation of the expression ((x) => x == null ? e2 : x)(e1). The
7 // static type of e is the least upper bound of the static type of e1 and the
8 // static type of e2.
9
10 import "package:expect/expect.dart";
11
12 class A {
13 final String a;
14 A(this.a);
15 }
16
17 class B extends A {
18 B(String v)
19 : b = v,
20 super(v);
21 final String b;
22 }
23
24 class C extends A {
25 C(String v)
26 : c = v,
27 super(v);
28 final String c;
29 }
30
31 B nullB() => null;
32 C nullC() => null;
33
34 noMethod(e) => e is NoSuchMethodError;
35
36 main() {
37 Expect.equals(1, 1 ?? 2);
38 Expect.equals(1, 1 ?? null);
39 Expect.equals(2, null ?? 2);
40 Expect.equals(null, null ?? null);
41 Expect.equals('B', (new B('B') ?? new C('C')).a);
42 Expect.equals('B', ((new B('B') ?? new C('C')) as dynamic).b);
43 Expect.throwsNoSuchMethodError(() => ((new B('B') ?? new C('C')) as dynamic).c );
44 Expect.equals('B', (new B('B') ?? nullC()).a);
45 Expect.equals('B', ((new B('B') ?? nullC()) as dynamic).b);
46 Expect.throwsNoSuchMethodError(() => ((new B('B') ?? nullC()) as dynamic).c);
47 Expect.equals('C', (nullB() ?? new C('C')).a);
48 Expect.throwsNoSuchMethodError(() => ((nullB() ?? new C('C')) as dynamic).b);
49 Expect.equals('C', ((nullB() ?? new C('C')) as dynamic).c);
50 Expect.throwsNoSuchMethodError(() => (nullB() ?? nullC()).a);
51 Expect.throwsNoSuchMethodError(() => ((nullB() ?? nullC()) as dynamic).b);
52 Expect.throwsNoSuchMethodError(() => ((nullB() ?? nullC()) as dynamic).c);
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698