OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 test.end2end_test; |
| 6 |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'package:source_maps/source_maps.dart'; |
| 9 import 'common.dart'; |
| 10 |
| 11 main() { |
| 12 test('end-to-end setup', () { |
| 13 expect(inputVar1.text, 'longVar1'); |
| 14 expect(inputFunction.text, 'longName'); |
| 15 expect(inputVar2.text, 'longVar2'); |
| 16 expect(inputExpr.text, 'longVar1 + longVar2'); |
| 17 |
| 18 expect(outputVar1.text, 'x'); |
| 19 expect(outputFunction.text, 'f'); |
| 20 expect(outputVar2.text, 'y'); |
| 21 expect(outputExpr.text, 'x + y'); |
| 22 }); |
| 23 |
| 24 test('build + parse', () { |
| 25 var map = (new SourceMapBuilder() |
| 26 ..addSpan(inputVar1, outputVar1) |
| 27 ..addSpan(inputFunction, outputFunction) |
| 28 ..addSpan(inputVar2, outputVar2) |
| 29 ..addSpan(inputExpr, outputExpr)) |
| 30 .build(output.url); |
| 31 var mapping = parseJson(map); |
| 32 check(outputVar1, mapping, inputVar1, false); |
| 33 check(outputVar2, mapping, inputVar2, false); |
| 34 check(outputFunction, mapping, inputFunction, false); |
| 35 check(outputExpr, mapping, inputExpr, false); |
| 36 }); |
| 37 |
| 38 test('build + parse with file', () { |
| 39 var json = (new SourceMapBuilder() |
| 40 ..addSpan(inputVar1, outputVar1) |
| 41 ..addSpan(inputFunction, outputFunction) |
| 42 ..addSpan(inputVar2, outputVar2) |
| 43 ..addSpan(inputExpr, outputExpr)) |
| 44 .toJson(output.url); |
| 45 var mapping = parse(json); |
| 46 check(outputVar1, mapping, inputVar1, true); |
| 47 check(outputVar2, mapping, inputVar2, true); |
| 48 check(outputFunction, mapping, inputFunction, true); |
| 49 check(outputExpr, mapping, inputExpr, true); |
| 50 }); |
| 51 |
| 52 test('printer projecting marks + parse', () { |
| 53 var out = INPUT.replaceAll('long', '_s'); |
| 54 var file = new SourceFile.text('output2.dart', out); |
| 55 var printer = new Printer('output2.dart'); |
| 56 printer.mark(ispan(0, 0)); |
| 57 |
| 58 bool first = true; |
| 59 var segments = INPUT.split('long'); |
| 60 expect(segments.length, 6); |
| 61 printer.add(segments[0], projectMarks: true); |
| 62 printer.mark(inputVar1); |
| 63 printer.add('_s'); |
| 64 printer.add(segments[1], projectMarks: true); |
| 65 printer.mark(inputFunction); |
| 66 printer.add('_s'); |
| 67 printer.add(segments[2], projectMarks: true); |
| 68 printer.mark(inputVar2); |
| 69 printer.add('_s'); |
| 70 printer.add(segments[3], projectMarks: true); |
| 71 printer.mark(inputExpr); |
| 72 printer.add('_s'); |
| 73 printer.add(segments[4], projectMarks: true); |
| 74 printer.add('_s'); |
| 75 printer.add(segments[5], projectMarks: true); |
| 76 |
| 77 expect(printer.text, out); |
| 78 |
| 79 var mapping = parse(printer.map); |
| 80 checkHelper(Span inputSpan, int adjustment) { |
| 81 var start = inputSpan.start.offset - adjustment; |
| 82 var end = (inputSpan.end.offset - adjustment) - 2; |
| 83 var span = new FileSpan(file, start, end, inputSpan.isIdentifier); |
| 84 check(span, mapping, inputSpan, true); |
| 85 } |
| 86 |
| 87 checkHelper(inputVar1, 0); |
| 88 checkHelper(inputFunction, 2); |
| 89 checkHelper(inputVar2, 4); |
| 90 checkHelper(inputExpr, 6); |
| 91 |
| 92 // We projected correctly lines that have no mappings |
| 93 check(new FileSpan(file, 66, 66, false), mapping, ispan(45, 45), true); |
| 94 check(new FileSpan(file, 63, 64, false), mapping, ispan(45, 45), true); |
| 95 check(new FileSpan(file, 68, 68, false), mapping, ispan(70, 70), true); |
| 96 check(new FileSpan(file, 71, 71, false), mapping, ispan(70, 70), true); |
| 97 |
| 98 // Start of the last line |
| 99 var oOffset = out.length - 2; |
| 100 var iOffset = INPUT.length - 2; |
| 101 check(new FileSpan(file, oOffset, oOffset, false), mapping, |
| 102 ispan(iOffset, iOffset), true); |
| 103 check(new FileSpan(file, oOffset + 1, oOffset + 1, false), mapping, |
| 104 ispan(iOffset, iOffset), true); |
| 105 }); |
| 106 } |
OLD | NEW |