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

Side by Side Diff: tests/corelib_strong/expression_test.dart

Issue 2989643002: Migrate test block 8 to Dart 2.0. (Closed)
Patch Set: Merge Created 3 years, 4 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
« no previous file with comments | « tests/corelib_strong/expando_test.dart ('k') | tests/corelib_strong/file_resource_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) 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 import "package:expect/expect.dart";
6
7 // Tests basic expressions. Does not attempt to validate the details of arithmet ic, coercion, and
8 // so forth.
9 class ExpressionTest {
10 ExpressionTest() {}
11
12 int foo;
13
14 static testMain() {
15 var test = new ExpressionTest();
16 test.testBinary();
17 test.testUnary();
18 test.testShifts();
19 test.testBitwise();
20 test.testIncrement();
21 test.testMangling();
22 }
23
24 testBinary() {
25 int x = 4, y = 2;
26 Expect.equals(6, x + y);
27 Expect.equals(2, x - y);
28 Expect.equals(8, x * y);
29 Expect.equals(2, x / y);
30 Expect.equals(0, x % y);
31 }
32
33 testUnary() {
34 int x = 4, y = 2, z = -5;
35 bool t = true, f = false;
36 Expect.equals(-4, -x);
37 Expect.equals(4, ~z);
38 Expect.equals(f, !t);
39 }
40
41 testShifts() {
42 int x = 4, y = 2;
43 Expect.equals(y, x >> 1);
44 Expect.equals(x, y << 1);
45 }
46
47 testBitwise() {
48 int x = 4, y = 2;
49 Expect.equals(6, (x | y));
50 Expect.equals(0, (x & y));
51 Expect.equals(6, (x ^ y));
52 }
53
54 operator [](int index) {
55 return foo;
56 }
57
58 operator []=(int index, int value) {
59 foo = value;
60 }
61
62 testIncrement() {
63 int x = 4, a = x++;
64 Expect.equals(4, a);
65 Expect.equals(5, x);
66 Expect.equals(6, ++x);
67 Expect.equals(6, x++);
68 Expect.equals(7, x);
69 Expect.equals(6, --x);
70 Expect.equals(6, x--);
71 Expect.equals(5, x);
72
73 this.foo = 0;
74 Expect.equals(0, this.foo++);
75 Expect.equals(1, this.foo);
76 Expect.equals(2, ++this.foo);
77 Expect.equals(2, this.foo);
78 Expect.equals(2, this.foo--);
79 Expect.equals(1, this.foo);
80 Expect.equals(0, --this.foo);
81 Expect.equals(0, this.foo);
82
83 Expect.equals(0, this[0]++);
84 Expect.equals(1, this[0]);
85 Expect.equals(2, ++this[0]);
86 Expect.equals(2, this[0]);
87 Expect.equals(2, this[0]--);
88 Expect.equals(1, this[0]);
89 Expect.equals(0, --this[0]);
90 Expect.equals(0, this[0]);
91
92 int $0 = 42, $1 = 87, $2 = 117;
93 Expect.equals(42, $0++);
94 Expect.equals(43, $0);
95 Expect.equals(44, ++$0);
96 Expect.equals(88, $0 += $0);
97 Expect.equals(87, $1++);
98 Expect.equals(88, $1);
99 Expect.equals(89, ++$1);
100 Expect.equals(178, ($1 += $1));
101 Expect.equals(117, $2++);
102 Expect.equals(118, $2);
103 Expect.equals(119, ++$2);
104 }
105
106 void testMangling() {
107 int $0 = 42, $1 = 87, $2 = 117;
108 this[0] = 0;
109 Expect.equals(42, (this[0] += $0));
110 Expect.equals(129, (this[0] += $1));
111 Expect.equals(246, (this[0] += $2));
112 }
113 }
114
115 main() {
116 ExpressionTest.testMain();
117 }
OLDNEW
« no previous file with comments | « tests/corelib_strong/expando_test.dart ('k') | tests/corelib_strong/file_resource_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698