| 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 import 'dart:io'; | 5 import 'dart:io'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:source_maps/source_maps.dart'; | 11 import 'package:source_maps/source_maps.dart'; |
| 12 | 12 |
| 13 validateSourceMap(Uri targetUri) { | 13 validateSourceMap(Uri targetUri) { |
| 14 Uri mapUri = getMapUri(targetUri); | 14 Uri mapUri = getMapUri(targetUri); |
| 15 SingleMapping sourceMap = getSourceMap(mapUri); | 15 SingleMapping sourceMap = getSourceMap(mapUri); |
| 16 checkFileReferences(targetUri, mapUri, sourceMap); | 16 checkFileReferences(targetUri, mapUri, sourceMap); |
| 17 checkIndexReferences(targetUri, mapUri, sourceMap); |
| 17 checkRedundancy(sourceMap); | 18 checkRedundancy(sourceMap); |
| 18 } | 19 } |
| 19 | 20 |
| 21 checkIndexReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) { |
| 22 List<String> target = |
| 23 new File.fromUri(targetUri).readAsStringSync().split('\n'); |
| 24 int urlsLength = sourceMap.urls.length; |
| 25 List<List<String>> sources = new List(urlsLength); |
| 26 print('Reading sources'); |
| 27 for (int i = 0; i < urlsLength; i++) { |
| 28 sources[i] = new File.fromUri(mapUri.resolve(sourceMap.urls[i])). |
| 29 readAsStringSync().split('\n'); |
| 30 } |
| 31 |
| 32 sourceMap.lines.forEach((TargetLineEntry line) { |
| 33 Expect.isTrue(line.line >= 0); |
| 34 Expect.isTrue(line.line < target.length); |
| 35 for (TargetEntry entry in line.entries) { |
| 36 int urlIndex = entry.sourceUrlId; |
| 37 |
| 38 // TODO(zarah): Entry columns sometimes point one or more characters too |
| 39 // far. Incomment this check when this is fixed. |
| 40 // |
| 41 // Expect.isTrue(entry.column < target[line.line].length); |
| 42 Expect.isTrue(entry.column >= 0); |
| 43 Expect.isTrue(urlIndex == null || |
| 44 (urlIndex >= 0 && urlIndex < urlsLength)); |
| 45 Expect.isTrue(entry.sourceLine == null || |
| 46 (entry.sourceLine >= 0 && |
| 47 entry.sourceLine < sources[urlIndex].length)); |
| 48 Expect.isTrue(entry.sourceColumn == null || |
| 49 (entry.sourceColumn >= 0 && |
| 50 entry.sourceColumn < sources[urlIndex][entry.sourceLine].length)); |
| 51 Expect.isTrue(entry.sourceNameId == null || |
| 52 (entry.sourceNameId >= 0 && |
| 53 entry.sourceNameId < sourceMap.names.length)); |
| 54 } |
| 55 }); |
| 56 } |
| 57 |
| 20 checkFileReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) { | 58 checkFileReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) { |
| 21 Expect.equals(targetUri, mapUri.resolve(sourceMap.targetUrl)); | 59 Expect.equals(targetUri, mapUri.resolve(sourceMap.targetUrl)); |
| 22 print('Checking sources'); | 60 print('Checking sources'); |
| 23 sourceMap.urls.forEach((String url) { | 61 sourceMap.urls.forEach((String url) { |
| 24 Expect.isTrue(new File.fromUri(mapUri.resolve(url)).existsSync()); | 62 Expect.isTrue(new File.fromUri(mapUri.resolve(url)).existsSync()); |
| 25 }); | 63 }); |
| 26 } | 64 } |
| 27 | 65 |
| 28 checkRedundancy(SingleMapping sourceMap) { | 66 checkRedundancy(SingleMapping sourceMap) { |
| 29 sourceMap.lines.forEach((TargetLineEntry line) { | 67 sourceMap.lines.forEach((TargetLineEntry line) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 }); | 118 }); |
| 81 } | 119 } |
| 82 | 120 |
| 83 Future<Directory> createTempDir() { | 121 Future<Directory> createTempDir() { |
| 84 return Directory.systemTemp | 122 return Directory.systemTemp |
| 85 .createTemp('sourceMap_test-') | 123 .createTemp('sourceMap_test-') |
| 86 .then((Directory dir) { | 124 .then((Directory dir) { |
| 87 return dir; | 125 return dir; |
| 88 }); | 126 }); |
| 89 } | 127 } |
| OLD | NEW |