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 @TestOn('vm') |
5 library code_transformers.test.assets_test; | 6 library code_transformers.test.assets_test; |
6 | 7 |
7 import 'dart:async'; | 8 import 'dart:async'; |
8 | 9 |
9 import 'package:barback/barback.dart'; | 10 import 'package:barback/barback.dart'; |
10 import 'package:code_transformers/resolver.dart'; | 11 import 'package:code_transformers/resolver.dart'; |
11 import 'package:code_transformers/tests.dart'; | 12 import 'package:transformer_test/utils.dart'; |
12 import 'package:unittest/compact_vm_config.dart'; | 13 import 'package:test/test.dart'; |
13 import 'package:unittest/unittest.dart'; | |
14 | 14 |
15 main() { | 15 main() { |
16 useCompactVMConfiguration(); | |
17 | |
18 Future checkDartEntry({Map<String, String> inputs, bool expectation}) { | 16 Future checkDartEntry({Map<String, String> inputs, bool expectation}) { |
19 var transformer = new Validator((transform) { | 17 var transformer = new Validator((transform) { |
20 return isPossibleDartEntry(transform.primaryInput).then((value) { | 18 return isPossibleDartEntry(transform.primaryInput).then((value) { |
21 expect(value, expectation); | 19 expect(value, expectation); |
22 }); | 20 }); |
23 }); | 21 }); |
24 return applyTransformers([[transformer]], inputs: inputs); | 22 return applyTransformers([ |
| 23 [transformer] |
| 24 ], inputs: inputs); |
25 } | 25 } |
26 | 26 |
27 group('isPossibleDartEntry', () { | 27 group('isPossibleDartEntry', () { |
28 test('should handle empty files', () { | 28 test('should handle empty files', () { |
29 return checkDartEntry( | 29 return checkDartEntry(inputs: { |
30 inputs: {'a|web/main.dart': '',}, expectation: false); | 30 'a|web/main.dart': '', |
| 31 }, expectation: false); |
31 }); | 32 }); |
32 | 33 |
33 test('should detect main methods', () { | 34 test('should detect main methods', () { |
34 return checkDartEntry( | 35 return checkDartEntry(inputs: { |
35 inputs: {'a|web/main.dart': 'main() {}',}, expectation: true); | 36 'a|web/main.dart': 'main() {}', |
| 37 }, expectation: true); |
36 }); | 38 }); |
37 | 39 |
38 test('should exclude dart mains in lib folder', () { | 40 test('should exclude dart mains in lib folder', () { |
39 return checkDartEntry( | 41 return checkDartEntry(inputs: { |
40 inputs: {'a|lib/main.dart': 'main() {}',}, expectation: false); | 42 'a|lib/main.dart': 'main() {}', |
| 43 }, expectation: false); |
41 }); | 44 }); |
42 | 45 |
43 test('should validate file extension', () { | 46 test('should validate file extension', () { |
44 return checkDartEntry( | 47 return checkDartEntry(inputs: { |
45 inputs: {'a|web/main.not_dart': 'main() {}',}, expectation: false); | 48 'a|web/main.not_dart': 'main() {}', |
| 49 }, expectation: false); |
46 }); | 50 }); |
47 | 51 |
48 test('should count exports as main', () { | 52 test('should count exports as main', () { |
49 return checkDartEntry( | 53 return checkDartEntry(inputs: { |
50 inputs: {'a|web/main.dart': 'export "foo.dart";',}, | 54 'a|web/main.dart': 'export "foo.dart";', |
51 expectation: true); | 55 }, expectation: true); |
52 }); | 56 }); |
53 | 57 |
54 test('should count parts as main', () { | 58 test('should count parts as main', () { |
55 return checkDartEntry( | 59 return checkDartEntry(inputs: { |
56 inputs: {'a|web/main.dart': 'part "foo.dart";',}, expectation: true); | 60 'a|web/main.dart': 'part "foo.dart";', |
| 61 }, expectation: true); |
57 }); | 62 }); |
58 | 63 |
59 test('is tolerant of syntax errors with main', () { | 64 test('is tolerant of syntax errors with main', () { |
60 return checkDartEntry( | 65 return checkDartEntry(inputs: { |
61 inputs: {'a|web/main.dart': 'main() {} {',}, expectation: true); | 66 'a|web/main.dart': 'main() {} {', |
| 67 }, expectation: true); |
62 }); | 68 }); |
63 | 69 |
64 test('is tolerant of syntax errors without main', () { | 70 test('is tolerant of syntax errors without main', () { |
65 return checkDartEntry( | 71 return checkDartEntry(inputs: { |
66 inputs: {'a|web/main.dart': 'class Foo {',}, expectation: false); | 72 'a|web/main.dart': 'class Foo {', |
| 73 }, expectation: false); |
67 }); | 74 }); |
68 }); | 75 }); |
69 } | 76 } |
70 | 77 |
71 class Validator extends Transformer { | 78 class Validator extends Transformer { |
72 final Function validation; | 79 final Function validation; |
73 | 80 |
74 Validator(this.validation); | 81 Validator(this.validation); |
75 | 82 |
76 Future apply(Transform transform) { | 83 Future apply(Transform transform) { |
77 return new Future.value(validation(transform)); | 84 return new Future.value(validation(transform)); |
78 } | 85 } |
79 } | 86 } |
OLD | NEW |