Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library code_transformers.test.assets_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io' show File, Platform; | |
| 9 | |
| 10 import 'package:barback/barback.dart'; | |
| 11 import 'package:code_transformers/resolver.dart'; | |
| 12 import 'package:code_transformers/tests.dart'; | |
| 13 import 'package:path/path.dart' as path; | |
| 14 import 'package:unittest/compact_vm_config.dart'; | |
| 15 import 'package:unittest/unittest.dart'; | |
| 16 | |
| 17 main() { | |
| 18 useCompactVMConfiguration(); | |
| 19 | |
| 20 Future checkDartEntry({Map<String, String> inputs, bool expectation}) { | |
| 21 var transformer = new Validator((transform) { | |
| 22 return isPossibleDartEntry(transform.primaryInput).then((value) { | |
| 23 expect(value, expectation); | |
| 24 }); | |
| 25 }); | |
| 26 return applyTransformers( | |
| 27 [[transformer]], | |
| 28 inputs: inputs); | |
| 29 } | |
| 30 | |
| 31 group('isPossibleDartEntry', () { | |
| 32 test('should handle empty files', () { | |
| 33 return checkDartEntry( | |
| 34 inputs: { | |
| 35 'a|web/main.dart': '', | |
| 36 }, | |
| 37 expectation: false); | |
| 38 }); | |
| 39 | |
| 40 test('should detect main methods', () { | |
| 41 return checkDartEntry( | |
| 42 inputs: { | |
| 43 'a|web/main.dart': 'main() {}', | |
| 44 }, | |
| 45 expectation: true); | |
| 46 }); | |
| 47 | |
| 48 test('should exclude dart mains in lib folder', () { | |
| 49 return checkDartEntry( | |
| 50 inputs: { | |
| 51 'a|lib/main.dart': 'main() {}', | |
| 52 }, | |
| 53 expectation: false); | |
| 54 }); | |
| 55 | |
| 56 test('should validate file extension', () { | |
| 57 return checkDartEntry( | |
| 58 inputs: { | |
| 59 'a|web/main.not_dart': 'main() {}', | |
| 60 }, | |
| 61 expectation: false); | |
| 62 }); | |
| 63 | |
| 64 test('should count exports as main', () { | |
| 65 return checkDartEntry( | |
| 66 inputs: { | |
| 67 'a|web/main.dart': 'export "foo.dart";', | |
| 68 }, | |
| 69 expectation: true); | |
| 70 }); | |
| 71 | |
| 72 test('should count parts as main', () { | |
| 73 return checkDartEntry( | |
| 74 inputs: { | |
| 75 'a|web/main.dart': 'part "foo.dart";', | |
| 76 }, | |
| 77 expectation: true); | |
| 78 }); | |
| 79 }); | |
| 80 | |
| 81 Future testAssetUri(String name, | |
| 82 {AssetId source, String uri, AssetId result}) { | |
| 83 test(name, () { | |
| 84 var transformer = new Validator((transform) { | |
| 85 var assetId = uriToAssetId(source, uri, transform.logger, null); | |
| 86 expect(result, assetId); | |
| 87 }); | |
| 88 return applyTransformers( | |
| 89 [[transformer]], | |
| 90 inputs: { | |
| 91 source.toString(): '' | |
| 92 }); | |
| 93 }); | |
| 94 } | |
| 95 | |
| 96 group('uriToAssetId', () { | |
| 97 testAssetUri('resolves relative URIs', | |
| 98 source: new AssetId('a', 'web/main.dart'), | |
| 99 uri: 'foo.dart', | |
| 100 result: new AssetId('a', 'web/foo.dart')); | |
| 101 | |
| 102 testAssetUri('resolves package: URIs', | |
| 103 source: new AssetId('a', 'web/main.dart'), | |
| 104 uri: 'package:foo/foo.dart', | |
| 105 result: new AssetId('foo', 'lib/foo.dart')); | |
| 106 | |
| 107 testAssetUri('resolves packages paths', | |
| 108 source: new AssetId('a', 'web/main.dart'), | |
| 109 uri: 'packages/foo/foo.dart', | |
| 110 result: new AssetId('foo', 'lib/foo.dart')); | |
|
Siggi Cherem (dart-lang)
2014/03/18 16:42:16
seems that we didn't have enough unittests in poly
blois
2014/03/18 17:39:07
Done.
| |
| 111 }); | |
| 112 } | |
| 113 | |
| 114 class Validator extends Transformer { | |
| 115 final Function validation; | |
| 116 | |
| 117 Validator(this.validation); | |
| 118 | |
| 119 Future<bool> isPrimary(Asset input) => new Future.value(true); | |
| 120 | |
| 121 Future apply(Transform transform) { | |
| 122 return new Future.value(validation(transform)); | |
| 123 } | |
| 124 } | |
| OLD | NEW |