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

Side by Side Diff: pkg/code_transformers/test/assets_test.dart

Issue 196943024: Adding some asset-related utilities to code_transformers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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
OLDNEW
(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/assets.dart';
12 import 'package:code_transformers/resolver.dart';
13 import 'package:code_transformers/tests.dart';
14 import 'package:path/path.dart' as path;
15 import 'package:unittest/compact_vm_config.dart';
16 import 'package:unittest/unittest.dart';
17
18 main() {
19 useCompactVMConfiguration();
20
21
22 Future testAssetUri(String name,
23 {AssetId source, String uri, AssetId result, String message,
24 bool errorOnAbsolute: true}) {
25 test(name, () {
26 var transformer = new Validator((transform) {
27 var assetId = uriToAssetId(source, uri, transform.logger, null,
28 errorOnAbsolute: errorOnAbsolute);
29 expect(assetId, result);
30 });
31 var messages = [];
32 if (message != null) messages.add(message);
33
34 return applyTransformers(
35 [[transformer]],
36 inputs: {
37 source.toString(): ''
38 },
39 messages: messages);
40 });
41 }
42
43 group('uriToAssetId', () {
44 testAssetUri('resolves relative URIs',
45 source: new AssetId('a', 'web/main.dart'),
46 uri: 'foo.dart',
47 result: new AssetId('a', 'web/foo.dart'));
48
49 testAssetUri('resolves package: URIs',
50 source: new AssetId('a', 'web/main.dart'),
51 uri: 'package:foo/foo.dart',
52 result: new AssetId('foo', 'lib/foo.dart'));
53
54 testAssetUri('resolves package: URIs from libs',
55 source: new AssetId('a', 'lib/main.dart'),
56 uri: 'package:foo/foo.dart',
57 result: new AssetId('foo', 'lib/foo.dart'));
58
59 testAssetUri('resolves packages paths',
60 source: new AssetId('a', 'web/main.dart'),
61 uri: 'packages/foo/foo.dart',
62 result: new AssetId('foo', 'lib/foo.dart'));
63
64 testAssetUri('resolves relative packages paths',
65 source: new AssetId('a', 'web/main.dart'),
66 uri: 'packages/foo/foo.dart',
67 result: new AssetId('foo', 'lib/foo.dart'));
68
69 testAssetUri('does not allow packages from non-dart lib files',
70 source: new AssetId('a', 'lib/index.html'),
71 uri: 'packages/foo/bar',
72 message: 'error: Invalid url to reach to another package: '
73 'packages/foo/bar. Path reaching to other packages must first '
74 'reach up all the way to the packages folder. For example, try '
75 'changing the url above to: ../../packages/foo/bar');
76
77 testAssetUri('allows relative packages from non-dart lib files',
78 source: new AssetId('a', 'lib/index.html'),
79 uri: '../../packages/foo/bar',
80 result: new AssetId('foo', 'lib/bar'));
81
82 testAssetUri('does not allow package: imports from non-dart files',
83 source: new AssetId('a', 'lib/index.html'),
84 uri: 'package:foo/bar.dart',
85 message: 'error: absolute paths not allowed: "package:foo/bar.dart"');
86
87 testAssetUri('does not allow absolute /packages by default',
88 source: new AssetId('a', 'lib/index.html'),
89 uri: '/packages/foo/bar.dart',
90 message: 'error: absolute paths not allowed: "/packages/foo/bar.dart"');
91
92 testAssetUri('can suppress error on absolute /packages ',
93 source: new AssetId('a', 'lib/index.html'),
94 uri: '/packages/foo/bar.dart',
95 errorOnAbsolute: false,
96 result: null);
97 });
98 }
99
100 class Validator extends Transformer {
101 final Function validation;
102
103 Validator(this.validation);
104
105 Future<bool> isPrimary(Asset input) => new Future.value(true);
106
107 Future apply(Transform transform) {
108 return new Future.value(validation(transform));
109 }
110 }
OLDNEW
« no previous file with comments | « pkg/code_transformers/lib/src/resolver_impl.dart ('k') | pkg/code_transformers/test/entry_point_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698