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

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

Powered by Google App Engine
This is Rietveld 408576698