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

Side by Side Diff: tests/language/map_literal5_test.dart

Issue 22909056: Support general expressions as keys in literal maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/language/map_literal11_test.dart ('k') | tests/language/map_literal6_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 // Test the use of general expression as keys in map literals.
6
7 library map_literal5_test;
8
9 import "package:expect/expect.dart";
10
11 void main() {
12 test(true);
13 test(false);
14 }
15
16 void test(bool b) {
17 var m = create(b);
18 Expect.equals(b, m.containsKey(true));
19 Expect.equals(b, m.containsKey(2));
20 Expect.equals(b, m.containsKey(1));
21 Expect.equals(!b, m.containsKey(false));
22 Expect.equals(!b, m.containsKey("bar"));
23 Expect.equals(!b, m.containsKey("foo"));
24 if (b) {
25 Expect.equals(0, m[true]);
26 Expect.equals(3, m[2]);
27 Expect.equals(2, m[1]);
28 } else {
29 Expect.equals(0, m[false]);
30 Expect.equals("baz", m["bar"]);
31 Expect.equals(2, m["foo"]);
32 }
33 }
34
35 create(bool b) {
36 return {
37 b: 0,
38 m(b): n(b),
39 b ? 1 : "foo": 2,
40 };
41 }
42
43 m(bool b) => b ? 2 : "bar";
44 n(bool b) => b ? 3 : "baz";
OLDNEW
« no previous file with comments | « tests/language/map_literal11_test.dart ('k') | tests/language/map_literal6_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698