OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library pub.test.preprocess_test; | 5 library pub.test.preprocess_test; |
6 | 6 |
7 import 'package:pub_semver/pub_semver.dart'; | 7 import 'package:pub_semver/pub_semver.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 | 9 |
10 import '../lib/src/preprocess.dart'; | 10 import '../lib/src/preprocess.dart'; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 test("disallows insert directive without space", () { | 241 test("disallows insert directive without space", () { |
242 expect(() => _preprocess('//>foo'), throwsFormatException); | 242 expect(() => _preprocess('//>foo'), throwsFormatException); |
243 }); | 243 }); |
244 | 244 |
245 group("if", () { | 245 group("if", () { |
246 test("disallows if with no arguments", () { | 246 test("disallows if with no arguments", () { |
247 expect(() => _preprocess('//# if\n//# end'), throwsFormatException); | 247 expect(() => _preprocess('//# if\n//# end'), throwsFormatException); |
248 }); | 248 }); |
249 | 249 |
250 test("disallows if with no package", () { | 250 test("disallows if with no package", () { |
251 expect(() => _preprocess('//# if <=1.0.0\n//# end'), | 251 expect( |
| 252 () => _preprocess('//# if <=1.0.0\n//# end'), |
252 throwsFormatException); | 253 throwsFormatException); |
253 }); | 254 }); |
254 | 255 |
255 test("disallows invalid version constraint", () { | 256 test("disallows invalid version constraint", () { |
256 expect(() => _preprocess('//# if barback >=1.0\n//# end'), | 257 expect( |
| 258 () => _preprocess('//# if barback >=1.0\n//# end'), |
257 throwsFormatException); | 259 throwsFormatException); |
258 }); | 260 }); |
259 | 261 |
260 test("disallows dangling end", () { | 262 test("disallows dangling end", () { |
261 expect(() => _preprocess('//# end'), | 263 expect(() => _preprocess('//# end'), throwsFormatException); |
| 264 }); |
| 265 |
| 266 test("disallows if without end", () { |
| 267 expect( |
| 268 () => _preprocess('//# if barback >=1.0.0'), |
262 throwsFormatException); | 269 throwsFormatException); |
263 }); | 270 }); |
264 | 271 |
265 test("disallows if without end", () { | |
266 expect(() => _preprocess('//# if barback >=1.0.0'), | |
267 throwsFormatException); | |
268 }); | |
269 | |
270 test("disallows nested if", () { | 272 test("disallows nested if", () { |
271 expect(() => _preprocess(''' | 273 expect(() => _preprocess(''' |
272 //# if barback >=1.0.0 | 274 //# if barback >=1.0.0 |
273 //# if barback >= 1.5.0 | 275 //# if barback >= 1.5.0 |
274 //# end | 276 //# end |
275 //# end | 277 //# end |
276 '''), | 278 '''), throwsFormatException); |
277 throwsFormatException); | |
278 }); | 279 }); |
279 }); | 280 }); |
280 | 281 |
281 group("else", () { | 282 group("else", () { |
282 test("disallows else without if", () { | 283 test("disallows else without if", () { |
283 expect(() => _preprocess('//# else\n//# end'), throwsFormatException); | 284 expect(() => _preprocess('//# else\n//# end'), throwsFormatException); |
284 }); | 285 }); |
285 | 286 |
286 test("disallows else without end", () { | 287 test("disallows else without end", () { |
287 expect(() => _preprocess('//# if barback >=1.0.0\n//# else'), | 288 expect( |
| 289 () => _preprocess('//# if barback >=1.0.0\n//# else'), |
288 throwsFormatException); | 290 throwsFormatException); |
289 }); | 291 }); |
290 | 292 |
291 test("disallows else with an argument", () { | 293 test("disallows else with an argument", () { |
292 expect(() => _preprocess(''' | 294 expect(() => _preprocess(''' |
293 //# if barback >=1.0.0 | 295 //# if barback >=1.0.0 |
294 //# else barback <0.5.0 | 296 //# else barback <0.5.0 |
295 //# end | 297 //# end |
296 '''), throwsFormatException); | 298 '''), throwsFormatException); |
297 }); | 299 }); |
298 }); | 300 }); |
299 }); | 301 }); |
300 } | 302 } |
301 | 303 |
302 String _preprocess(String input) => | 304 String _preprocess(String input) => preprocess(input, { |
303 preprocess(input, {'barback': new Version.parse("1.2.3")}, 'source/url'); | 305 'barback': new Version.parse("1.2.3") |
| 306 }, 'source/url'); |
OLD | NEW |