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

Side by Side Diff: packages/petitparser/test/dart_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers 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
OLDNEW
(Empty)
1 library petitparser.test.dart_test;
2
3 import 'package:test/test.dart';
4
5 import 'package:petitparser/test.dart';
6 import 'package:petitparser/dart.dart';
7
8 void main() {
9 var definition = new DartGrammarDefinition();
10 var dart = new DartGrammar();
11 group('basic', () {
12 test('structure', () {
13 expect('library test;', accept(dart));
14 expect('library test; void main() { }', accept(dart));
15 expect('library test; void main() { print(2 + 3); }', accept(dart));
16 });
17 });
18 group('expression', () {
19 var expression = definition.build(start: definition.expression).end();
20 test('literal numbers', () {
21 expect('1', accept(expression));
22 expect('1.2', accept(expression));
23 expect('1.2e3', accept(expression));
24 expect('1.2e-3', accept(expression));
25 expect('-1.2e3', accept(expression));
26 expect('-1.2e-3', accept(expression));
27 expect('-1.2E-3', accept(expression));
28 });
29 test('literal objects', () {
30 expect('true', accept(expression));
31 expect('false', accept(expression));
32 expect('null', accept(expression));
33 });
34 test('unary increment/decrement', () {
35 expect('++a', accept(expression));
36 expect('--a', accept(expression));
37 expect('a++', accept(expression));
38 expect('a--', accept(expression));
39 });
40 test('unary operators', () {
41 expect('+a', accept(expression));
42 expect('-a', accept(expression));
43 expect('!a', accept(expression));
44 expect('~a', accept(expression));
45 });
46 test('binary arithmetic operators', () {
47 expect('a + b', accept(expression));
48 expect('a - b', accept(expression));
49 expect('a * b', accept(expression));
50 expect('a / b', accept(expression));
51 expect('a ~/ b', accept(expression));
52 expect('a % b', accept(expression));
53 });
54 test('binary logical operators', () {
55 expect('a & b', accept(expression));
56 expect('a | b', accept(expression));
57 expect('a ^ b', accept(expression));
58 expect('a && b', accept(expression));
59 expect('a || b', accept(expression));
60 });
61 test('binary conditional operators', () {
62 expect('a > b', accept(expression));
63 expect('a >= b', accept(expression));
64 expect('a < b', accept(expression));
65 expect('a <= b', accept(expression));
66 expect('a == b', accept(expression));
67 expect('a != b', accept(expression));
68 expect('a === b', accept(expression));
69 expect('a !== b', accept(expression));
70 });
71 test('binary shift operators', () {
72 expect('a << b', accept(expression));
73 expect('a >>> b', accept(expression));
74 expect('a >> b', accept(expression));
75 });
76 test('ternary operator', () {
77 expect('a ? b : c', accept(expression));
78 });
79 test('parenthesis', () {
80 expect('(a + b)', accept(expression));
81 expect('a * (b + c)', accept(expression));
82 expect('(a * b) + c', accept(expression));
83 });
84 test('access', () {
85 expect('a.b', accept(expression));
86 });
87 test('invoke', () {
88 expect('a.b()', accept(expression));
89 expect('a.b(c)', accept(expression));
90 expect('a.b(c, d)', accept(expression));
91 expect('a.b(c: d)', accept(expression));
92 expect('a.b(c: d, e: f)', accept(expression));
93 });
94 test('assignment', () {
95 expect('a = b', accept(expression));
96 expect('a += b', accept(expression));
97 expect('a -= b', accept(expression));
98 expect('a *= b', accept(expression));
99 expect('a /= b', accept(expression));
100 expect('a %= b', accept(expression));
101 expect('a ~/= b', accept(expression));
102 expect('a <<= b', accept(expression));
103 expect('a >>>= b', accept(expression));
104 expect('a >>= b', accept(expression));
105 expect('a &= b', accept(expression));
106 expect('a ^= b', accept(expression));
107 expect('a |= b', accept(expression));
108 });
109 test('indexed', () {
110 expect('a[b]', accept(expression));
111 expect('a[b] = c', accept(expression));
112 });
113 });
114 group('whitespace', () {
115 var whitespaces = definition.build(start: definition.HIDDEN).end();
116 test('whitespace', () {
117 expect(' ', accept(whitespaces));
118 expect('\t', accept(whitespaces));
119 expect('\n', accept(whitespaces));
120 expect('\r', accept(whitespaces));
121 expect('a', isNot(accept(whitespaces)));
122 });
123 test('single-line comment', () {
124 expect('//', accept(whitespaces));
125 expect('// foo', accept(whitespaces));
126 expect('//\n', accept(whitespaces));
127 expect('// foo\n', accept(whitespaces));
128 });
129 test('single-line documentation', () {
130 expect('///', accept(whitespaces));
131 expect('/// foo', accept(whitespaces));
132 expect('/// \n', accept(whitespaces));
133 expect('/// foo\n', accept(whitespaces));
134 });
135 test('multi-line comment', () {
136 expect('/**/', accept(whitespaces));
137 expect('/* foo */', accept(whitespaces));
138 expect('/* foo \n bar */', accept(whitespaces));
139 expect('/* foo ** bar */', accept(whitespaces));
140 expect('/* foo * / bar */', accept(whitespaces));
141 });
142 test('multi-line documentation', () {
143 expect('/***/', accept(whitespaces));
144 expect('/*******/', accept(whitespaces));
145 expect('/** foo */', accept(whitespaces));
146 expect('/**\n *\n *\n */', accept(whitespaces));
147 });
148 test('multi-line nested', () {
149 expect('/* outer /* nested */ */', accept(whitespaces));
150 expect('/* outer /* nested /* deeply nested */ */ */', accept(whitespaces) );
151 expect('/* outer /* not closed */', isNot(accept(whitespaces)));
152 });
153 test('combined', () {
154 expect('/**/', accept(whitespaces));
155 expect(' /**/', accept(whitespaces));
156 expect('/**/ ', accept(whitespaces));
157 expect(' /**/ ', accept(whitespaces));
158 expect('/**///', accept(whitespaces));
159 expect('/**/ //', accept(whitespaces));
160 expect(' /**/ //', accept(whitespaces));
161 });
162 });
163 group('child parsers', () {
164 var parser = definition.build(start: definition.STRING).end();
165 test('singleLineString', () {
166 expect("'hi'", accept(parser));
167 expect('"hi"', accept(parser));
168 expect('no quotes', isNot(accept(parser)));
169 expect('"missing quote', isNot(accept(parser)));
170 expect("'missing quote", isNot(accept(parser)));
171 });
172 });
173 group('offical', () {
174 test('identifier', () {
175 var parser = definition.build(start: definition.identifier).end();
176 expect('foo', accept(parser));
177 expect('bar9', accept(parser));
178 expect('dollar\$', accept(parser));
179 expect('_foo', accept(parser));
180 expect('_bar9', accept(parser));
181 expect('_dollar\$', accept(parser));
182 expect('\$', accept(parser));
183 expect(' leadingSpace', accept(parser));
184 expect('9', isNot(accept(parser)));
185 expect('3foo', isNot(accept(parser)));
186 expect('', isNot(accept(parser)));
187 });
188 test('numeric literal', () {
189 var parser = definition.build(start: definition.literal).end();
190 expect('0', accept(parser));
191 expect('1984', accept(parser));
192 expect(' 1984', accept(parser));
193 expect('0xCAFE', accept(parser));
194 expect('0XCAFE', accept(parser));
195 expect('0xcafe', accept(parser));
196 expect('0Xcafe', accept(parser));
197 expect('0xCaFe', accept(parser));
198 expect('0XCaFe', accept(parser));
199 expect('3e4', accept(parser));
200 expect('3e-4', accept(parser));
201 expect('3E4', accept(parser));
202 expect('3E-4', accept(parser));
203 expect('3.14E4', accept(parser));
204 expect('3.14E-4', accept(parser));
205 expect('3.14', accept(parser));
206 expect('3e--4', isNot(accept(parser)));
207 expect('5.', isNot(accept(parser)));
208 expect('CAFE', isNot(accept(parser)));
209 expect('0xGHIJ', isNot(accept(parser)));
210 expect('-', isNot(accept(parser)));
211 expect('', isNot(accept(parser)));
212 });
213 test('boolean literal', () {
214 var parser = definition.build(start: definition.literal).end();
215 expect('true', accept(parser));
216 expect('false', accept(parser));
217 expect(' true', accept(parser));
218 expect(' false', accept(parser));
219 });
220 });
221 }
OLDNEW
« no previous file with comments | « packages/petitparser/test/dart_file_tests.dart ('k') | packages/petitparser/test/debug_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698