Chromium Code Reviews| 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 < target.length); | |
|
Johnni Winther
2014/04/10 12:55:01
Check that line.line >= 1 (or is it 0?)
zarah
2014/04/10 13:46:19
Done.
| |
| 34 for (TargetEntry entry in line.entries) { | |
| 35 int urlIndex = entry.sourceUrlId; | |
| 36 | |
| 37 // TODO(zarah): Entry columns sometimes point one or more characters too | |
| 38 // far. Incomment this check when this is fixed. | |
| 39 // | |
| 40 // Expect.isTrue(entry.column < target[line.line].length); | |
|
Johnni Winther
2014/04/10 12:55:01
Check entry.column >= 1 (or 0?)
zarah
2014/04/10 13:46:19
Done.
| |
| 41 Expect.isTrue(urlIndex == null || urlIndex < urlsLength); | |
|
Johnni Winther
2014/04/10 12:55:01
Check urlIndex >= 0.
zarah
2014/04/10 13:46:19
Done.
| |
| 42 Expect.isTrue(entry.sourceLine == null || | |
| 43 entry.sourceLine < sources[urlIndex].length); | |
|
Johnni Winther
2014/04/10 12:55:01
Check entry.sourceLine >= 1 (or 1?).
zarah
2014/04/10 13:46:19
Done.
| |
| 44 Expect.isTrue(entry.sourceColumn == null || | |
| 45 entry.sourceColumn < sources[urlIndex][entry.sourceLine].length); | |
|
Johnni Winther
2014/04/10 12:55:01
Ditto.
zarah
2014/04/10 13:46:19
Done.
| |
| 46 Expect.isTrue(entry.sourceNameId == null || | |
| 47 entry.sourceNameId < sourceMap.names.length); | |
|
Johnni Winther
2014/04/10 12:55:01
Ditto.
zarah
2014/04/10 13:46:19
Done.
| |
| 48 } | |
| 49 }); | |
| 50 } | |
| 51 | |
| 20 checkFileReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) { | 52 checkFileReferences(Uri targetUri, Uri mapUri, SingleMapping sourceMap) { |
| 21 Expect.equals(targetUri, mapUri.resolve(sourceMap.targetUrl)); | 53 Expect.equals(targetUri, mapUri.resolve(sourceMap.targetUrl)); |
| 22 print('Checking sources'); | 54 print('Checking sources'); |
| 23 sourceMap.urls.forEach((String url) { | 55 sourceMap.urls.forEach((String url) { |
| 24 Expect.isTrue(new File.fromUri(mapUri.resolve(url)).existsSync()); | 56 Expect.isTrue(new File.fromUri(mapUri.resolve(url)).existsSync()); |
| 25 }); | 57 }); |
| 26 } | 58 } |
| 27 | 59 |
| 28 checkRedundancy(SingleMapping sourceMap) { | 60 checkRedundancy(SingleMapping sourceMap) { |
| 29 sourceMap.lines.forEach((TargetLineEntry line) { | 61 sourceMap.lines.forEach((TargetLineEntry line) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 }); | 112 }); |
| 81 } | 113 } |
| 82 | 114 |
| 83 Future<Directory> createTempDir() { | 115 Future<Directory> createTempDir() { |
| 84 return Directory.systemTemp | 116 return Directory.systemTemp |
| 85 .createTemp('sourceMap_test-') | 117 .createTemp('sourceMap_test-') |
| 86 .then((Directory dir) { | 118 .then((Directory dir) { |
| 87 return dir; | 119 return dir; |
| 88 }); | 120 }); |
| 89 } | 121 } |
| OLD | NEW |