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

Side by Side Diff: tests/compiler/dart2js/source_map_validator_helper.dart

Issue 228003005: Remove redundancy in source map entries. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed command path. Created 6 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/source_map_pub_build_validity_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import 'dart:io';
6 import 'dart:convert';
7 import 'dart:async';
8
9 import 'package:path/path.dart' as path;
10 import 'package:expect/expect.dart';
11 import 'package:source_maps/source_maps.dart';
12
13 validateSourceMap(Uri targetUri) {
14 Uri mapUri = getMapUri(targetUri);
15 SingleMapping sourceMap = getSourceMap(mapUri);
16 checkFileReferences(targetUri, mapUri, sourceMap);
17 checkRedundancy(sourceMap);
18 }
19
20 checkFileReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) {
21 Expect.equals(targetUri, mapUri.resolve(sourceMap.targetUrl));
22 print('Checking sources');
23 sourceMap.urls.forEach((String url) {
24 Expect.isTrue(new File.fromUri(mapUri.resolve(url)).existsSync());
25 });
26 }
27
28 checkRedundancy(SingleMapping sourceMap) {
29 sourceMap.lines.forEach((TargetLineEntry line) {
30 TargetEntry previous = null;
31 for (TargetEntry next in line.entries) {
32 if (previous != null) {
33 Expect.isFalse(sameSourcePoint(previous, next),
34 '$previous and $next are consecutive entries on line $line in the '
35 'source map but point to same source locations');
36 }
37 previous = next;
38 }
39 });
40 }
41
42 sameSourcePoint(TargetEntry entry, TargetEntry otherEntry) {
43 return
44 (entry.sourceUrlId == otherEntry.sourceUrlId) &&
45 (entry.sourceLine == otherEntry.sourceLine) &&
46 (entry.sourceColumn == otherEntry.sourceColumn) &&
47 (entry.sourceNameId == otherEntry.sourceNameId);
48 }
49
50 Uri getMapUri(Uri targetUri) {
51 print('Accessing $targetUri');
52 File targetFile = new File.fromUri(targetUri);
53 Expect.isTrue(targetFile.existsSync());
54 List<String> target = targetFile.readAsStringSync().split('\n');
55 String mapReference = target[target.length - 3]; // #sourceMappingURL=<url>
56 Expect.isTrue(mapReference.startsWith('//# sourceMappingURL='));
57 String mapName = mapReference.substring(mapReference.indexOf('=') + 1);
58 return targetUri.resolve(mapName);
59 }
60
61 SingleMapping getSourceMap(Uri mapUri) {
62 print('Accessing $mapUri');
63 File mapFile = new File.fromUri(mapUri);
64 Expect.isTrue(mapFile.existsSync());
65 return new SingleMapping.fromJson(
66 JSON.decode(mapFile.readAsStringSync()));
67 }
68
69 copyDirectory(Directory sourceDir, Directory destinationDir) {
70 sourceDir.listSync().forEach((FileSystemEntity element) {
71 String newPath = path.join(destinationDir.path,
72 path.basename(element.path));
73 if (element is File) {
74 element.copySync(newPath);
75 } else if (element is Directory) {
76 Directory newDestinationDir = new Directory(newPath);
77 newDestinationDir.createSync();
78 copyDirectory(element, newDestinationDir);
79 }
80 });
81 }
82
83 Future<Directory> createTempDir() {
84 return Directory.systemTemp
85 .createTemp('sourceMap_test-')
86 .then((Directory dir) {
87 return dir;
88 });
89 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/source_map_pub_build_validity_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698