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

Side by Side Diff: tests/compiler/dart2js/begin_end_token_test.dart

Issue 10697003: Various token issues fixed in the compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Unit tests updated, co19 status updated. Created 8 years, 5 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/co19/co19-leg.status ('k') | tests/compiler/dart2js/scanner_offset_length_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('parser_helper.dart');
6 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
7 #import("../../../lib/compiler/implementation/tree/tree.dart");
8
9
10 void testNode(Node node, String expected, String text, [bool hard = true]) {
11 var debug = 'text=$text,expected=$expected,node:${node}';
12 Expect.isNotNull(node, debug);
13
14 Token beginToken = node.getBeginToken();
15 Expect.isNotNull(beginToken, debug);
16 Token endToken = node.getEndToken();
17 Expect.isNotNull(endToken, debug);
18
19 int begin = beginToken.charOffset;
20 int end = endToken.charOffset + endToken.slowCharCount;
21 Expect.isTrue(begin <= end, debug);
22
23 if (hard) {
24 Expect.stringEquals(expected, text.substring(begin, end), debug);
25 }
26 }
27
28 Node testExpression(String text) {
29 var node = parseStatement('$text;').expression;
30 testNode(node, text, text);
31 return node;
32 }
33
34 void testUnaryExpression() {
35 testExpression('x++');
36 testExpression('++x');
37 }
38
39 void testAssignment() {
40 Expression node;
41 SendSet sendSet;
42 String text;
43
44 text = "a = b";
45 node = testExpression(text);
46
47 text = "a = b = c";
48 node = testExpression(text);
49 // Should parse as: a = (b = c).
50 Expect.isNotNull(sendSet = node.asSendSet());
51 testNode(sendSet.arguments.head.asSendSet(), 'b = c', text);
52
53 text = "a = b = c = d";
54 node = testExpression(text);
55 // Should parse as: a = (b = (c = d)).
56 Expect.isNotNull(sendSet = node.asSendSet());
57 testNode(sendSet = sendSet.arguments.head.asSendSet(), 'b = c = d', text);
58 testNode(sendSet = sendSet.arguments.head.asSendSet(), 'c = d', text);
59
60 text = "a.b = c";
61 node = testExpression(text);
62 // Should parse as: receiver = a, selector = b, arguments = c.
63 Expect.isNotNull(sendSet = node.asSendSet());
64 testNode(sendSet.receiver, "a", "a.b = c");
65 testNode(sendSet.selector, "b", "a.b = c");
66 testNode(sendSet.arguments.head, "c", "a.b = c");
67
68 text = "a.b = c.d";
69 node = testExpression(text);
70 // Should parse as: a.b = (c.d).
71 Expect.isNotNull(sendSet = node.asSendSet());
72 Expect.stringEquals("a", sendSet.receiver.toString());
73 Expect.stringEquals("b", sendSet.selector.toString());
74 Expect.stringEquals("c.d", sendSet.arguments.head.toString());
75
76 text = "a.b = c.d = e.f";
77 node = testExpression(text);
78 // Should parse as: a.b = (c.d = (e.f)).
79 Expect.isNotNull(sendSet = node.asSendSet());
80 testNode(sendSet.receiver, "a", text);
81 testNode(sendSet.selector, "b", text);
82 Expect.isNotNull(sendSet = sendSet.arguments.head.asSendSet());
83 testNode(sendSet.receiver, "c", text);
84 testNode(sendSet.selector, "d", text);
85 testNode(sendSet.arguments.head, "e.f", text);
86 }
87
88 void testIndex() {
89 Expression node;
90 Send send;
91 SendSet sendSet;
92 String text;
93
94 text = "a[b]";
95 node = testExpression(text);
96 // Should parse as: (a)[b].
97 Expect.isNotNull(send = node.asSend());
98 testNode(send.receiver, "a", text);
99 // TODO(johnniwinther): [selector] is the synthetic [] Operator which doesn't
100 // return the right begin/end tokens:
101 // testNode(send.selector, "[b]", text);
102 testNode(send.arguments.head, "b", text);
103
104 text = "a[b] = c";
105 node = testExpression(text);
106 // Should parse as: (a)[b] = c.
107 Expect.isNotNull(sendSet = node.asSendSet());
108 testNode(sendSet.receiver, "a", text);
109 testNode(sendSet.selector, "[]", text, false); // Operator token is synthetic.
110 testNode(sendSet.assignmentOperator, "=", text);
111 testNode(sendSet.arguments.head, "b", text);
112 testNode(sendSet.arguments.tail.head, "c", text);
113
114 text = "a.b[c]";
115 node = testExpression(text);
116 // Should parse as: (a.b)[c].
117 Expect.isNotNull(send = node.asSend());
118 testNode(send.receiver, "a.b", text);
119 testNode(send.selector, "[]", text, false); // Operator token is synthetic.
120 testNode(send.arguments.head, "c", text);
121
122 text = "a.b[c] = d";
123 node = testExpression(text);
124 // Should parse as: (a.b)[] = (c, d).
125 Expect.isNotNull(sendSet = node.asSendSet());
126 Expect.isNotNull(send = sendSet.receiver.asSend());
127 testNode(send, "a.b", text);
128 testNode(sendSet.selector, "[]", text, false); // Operator token is synthetic.
129 testNode(sendSet.assignmentOperator, "=", text);
130 testNode(sendSet.arguments.head, "c", text);
131 testNode(sendSet.arguments.tail.head, "d", text);
132 }
133
134 void testPostfix() {
135 Expression node;
136 SendSet sendSet;
137 String text;
138
139 text = "a.b++";
140 node = testExpression(text);
141 // Should parse as: (a.b)++.
142 Expect.isNotNull(sendSet = node.asSendSet());
143 testNode(sendSet.receiver, "a", text);
144 testNode(sendSet.selector, "b", text);
145 testNode(sendSet.assignmentOperator, "++", text);
146 Expect.isTrue(sendSet.arguments.isEmpty());
147
148 // TODO(johnniwinther): Generates '++a' instead of '++a[b]'.
149 //text = "++a[b]";
150 //node = testExpression(text);
151 //Expect.isNotNull(sendSet = node.asSendSet());
152 //testNode(sendSet.receiver, "a", text);
153 //testNode(sendSet.selector, "[]", text, false);
154 //testNode(sendSet.assignmentOperator, "++", text);
155 //testNode(sendSet.arguments.head, "b", text);
Lasse Reichstein Nielsen 2012/06/28 13:03:52 Generally, if a test fails, add a test that succee
156
157 text = "a[b]++";
158 node = testExpression(text);
159 Expect.isNotNull(sendSet = node.asSendSet());
160 testNode(sendSet.receiver, "a", text);
161 testNode(sendSet.selector, "[]", text, false); // Operator token is synthetic.
162 testNode(sendSet.assignmentOperator, "++", text);
163 testNode(sendSet.arguments.head, "b", text);
164 }
165
166 void main() {
167 testUnaryExpression();
168 testAssignment();
169 testIndex();
170 testPostfix();
171 }
OLDNEW
« no previous file with comments | « tests/co19/co19-leg.status ('k') | tests/compiler/dart2js/scanner_offset_length_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698