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

Side by Side Diff: tests/kernel/unsorted/constant_expressions_test.dart

Issue 2434123003: Merge more Kernel infrastructure from kernel_sdk SDK fork. (Closed)
Patch Set: Created 4 years, 2 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 import 'expect.dart';
Kevin Millikin (Google) 2016/10/21 09:10:57 Copyright header.
2
3 const int42 = 40 + 2;
4 const stringAB = 'a' + 'b';
5 const stringAB2 = 'a' + 'b';
6 const list123 = const [1, 2, 3];
7 const mapABC = const {'a' : 'b', 'b': 'c'};
8
9 const boxInt42 = const Box(int42);
10 const boxStringAB = const Box(stringAB);
11
12 class Box {
13 final value;
14 const Box(this.value);
15 }
16
17 returnPositional([a = const Box('posi' + 'tional')]) => a;
18
19 returnNamed({a: const Box('nam' + 'ed')}) => a;
20
21 returnSwitchCasedValue(value) {
22 switch (value) {
23 case const Box(42): return 42;
24 case const Box('abc'): return 'abc';
25 case const Box(const Box('abc')): return const Box('abc');
26 default: return 'default';
27 }
28 }
29
30 testConstantExpressions() {
31 Expect.isTrue(identical(const Box(40 + 2), const Box(40 + 2)));
32 Expect.isTrue(identical(const Box('a' + 'b'), const Box('ab')));
33 Expect.isTrue(identical(const Box(const Box(40 + 2)),
34 const Box(const Box(42))));
35 Expect.isTrue(identical(const Box(const Box('a' + 'b')),
36 const Box(const Box('ab'))));
37 }
38
39 testConstantFieldValues() {
40 Expect.isTrue(identical(42, int42));
41 Expect.isTrue(identical(stringAB, stringAB2));
42 Expect.isTrue(identical(const Box(42), boxInt42));
43 Expect.isTrue(identical(const Box('ab'), boxStringAB));
44 }
45
46 testConstantFunctionParameters() {
47 Expect.isTrue(identical(const Box('positional'), returnPositional()));
48 Expect.isTrue(identical(const Box('named'), returnNamed()));
49 Expect.isTrue(identical(const Box('abc'),
50 returnPositional(const Box('abc'))));
51 Expect.isTrue(identical(const Box('def'),
52 returnNamed(a: const Box('def'))));
53 }
54
55 testConstantSwitchExpressions() {
56 Expect.isTrue(returnSwitchCasedValue(const Box(42)) == 42);
57 Expect.isTrue(returnSwitchCasedValue(const Box('abc')) == 'abc');
58 Expect.isTrue(returnSwitchCasedValue(const Box(const Box('abc')))
59 == const Box('abc'));
60 Expect.isTrue(returnSwitchCasedValue('go-to-default') == 'default');
61 }
62
63 testConstantLocalVariables() {
64 const a = 'a';
65 const b = a + 'b';
66 const c = b + 'c';
67 const box = const Box(c);
68 Expect.isTrue(identical(const Box('abc'), box));
69 }
70
71 testComplextConstLiterals() {
72 Expect.isTrue(identical(const [1, 2, 3], const [1, 2, 3]));
73 Expect.isTrue(identical(const [1, 2, 3], list123));
74 Expect.isTrue(identical(const {'a': 'b', 'b': 'c'}, const {'a': 'b', 'b': 'c'} ));
75 Expect.isTrue(identical(const {'a': 'b', 'b': 'c'}, mapABC));
76
77 Expect.isTrue(mapABC['a'] == 'b');
78 Expect.isTrue(mapABC['b'] == 'c');
79 Expect.isTrue(mapABC.length == 2);
80
81 Expect.isTrue(list123[0] == 1);
82 Expect.isTrue(list123[1] == 2);
83 Expect.isTrue(list123[2] == 3);
84 Expect.isTrue(list123.length == 3);
85 }
86
87 main() {
88 testConstantExpressions();
89 testConstantFieldValues();
90 testConstantFunctionParameters();
91 testConstantSwitchExpressions();
92 testComplextConstLiterals();
93 testConstantExpressions();
94 testConstantLocalVariables();
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698