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

Side by Side Diff: tests/language/src/NamedParametersWithDollarsTest.dart

Issue 10248007: test rename overhaul: step 8 - language tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 to stress Frog's named parameter scheme.
6
7 main() {
8 testDollar();
9 testPsycho();
10 }
11
12 class TestClass {
13 method([a, b, a$b, a$$b]) => [a, b, a$b, a$$b];
14
15 psycho([$, $$, $$$, $$$$]) => [$, $$, $$$, $$$$];
16 }
17 globalMethod([a, b, a$b, a$$b]) => [a, b, a$b, a$$b];
18
19
20 format(thing) {
21 if (thing == null) return '-';
22 if (thing is List) {
23 var fragments = ['['];
24 var sep;
25 for (final item in thing) {
26 if (sep != null) fragments.add(sep);
27 sep = ', ';
28 fragments.add(format(item));
29 }
30 fragments.add(']');
31 return Strings.concatAll(fragments);
32 }
33 return thing.toString();
34 }
35
36 // Hopefully inscrutable to static analysis.
37 makeTestClass(n) => [new TestClass(), new Decoy(), 'string'][n % 3];
38
39 class Decoy {
40 method([a$b, b, a]) { throw const NotImplementedException(); }
41 psycho([$$$, $$, $]) { throw const NotImplementedException(); }
42 }
43
44 testDollar() {
45 Expect.equals('[]', format([]));
46
47 Expect.equals('[-, -, -, -]', format(globalMethod()));
48 Expect.equals('[1, 2, -, -]', format(globalMethod(a: 1, b: 2)));
49 Expect.equals('[1, 2, -, -]', format(globalMethod(b: 2, a: 1)));
50 Expect.equals('[-, -, 3, -]', format(globalMethod(a$b: 3)));
51 Expect.equals('[-, -, -, 4]', format(globalMethod(a$$b: 4)));
52
53 TestClass t = new TestClass(); // Statically typed.
54
55 Expect.equals('[-, -, -, -]', format(t.method()));
56 Expect.equals('[1, 2, -, -]', format(t.method(a: 1, b: 2)));
57 Expect.equals('[1, 2, -, -]', format(t.method(b: 2, a: 1)));
58 Expect.equals('[-, -, 3, -]', format(t.method(a$b: 3)));
59 Expect.equals('[-, -, -, 4]', format(t.method(a$$b: 4)));
60
61 var obj = makeTestClass(0);
62
63 Expect.equals('[-, -, -, -]', format(obj.method()));
64 Expect.equals('[1, 2, -, -]', format(obj.method(a: 1, b: 2)));
65 Expect.equals('[1, 2, -, -]', format(obj.method(b: 2, a: 1)));
66 Expect.equals('[-, -, 3, -]', format(obj.method(a$b: 3)));
67 Expect.equals('[-, -, -, 4]', format(obj.method(a$$b: 4)));
68 }
69
70 testPsycho() {
71 TestClass t = new TestClass(); // Statically typed.
72
73 Expect.equals('[1, 2, 3, -]', format(t.psycho($:1, $$:2, $$$:3)));
74 Expect.equals('[1, 2, 3, -]', format(t.psycho($$$:3, $$:2, $:1)));
75 Expect.equals('[1, 2, -, -]', format(t.psycho($:1, $$:2)));
76 Expect.equals('[-, -, -, 4]', format(t.psycho($$$$: 4)));
77
78 var obj = makeTestClass(0);
79
80 Expect.equals('[1, 2, -, -]', format(obj.psycho($:1, $$:2)));
81 Expect.equals('[-, -, -, 4]', format(obj.psycho($$$$: 4)));
82 Expect.equals('[1, 2, 3, -]', format(obj.psycho($:1, $$:2, $$$:3)));
83 Expect.equals('[1, 2, 3, -]', format(obj.psycho($$$:3, $$:2, $:1)));
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698