OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library test.printer_test; | 5 library test.printer_test; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'package:source_maps/printer.dart'; | 9 import 'package:source_maps/source_maps.dart'; |
10 import 'package:source_maps/span.dart'; | 10 import 'package:source_span/source_span.dart'; |
11 import 'common.dart'; | 11 import 'common.dart'; |
12 | 12 |
13 main() { | 13 main() { |
14 test('printer', () { | 14 test('printer', () { |
15 var printer = new Printer('output.dart'); | 15 var printer = new Printer('output.dart'); |
16 printer..add('var ') | 16 printer..add('var ') |
17 ..mark(inputVar1) | 17 ..mark(inputVar1) |
18 ..add('x = 3;\n') | 18 ..add('x = 3;\n') |
19 ..mark(inputFunction) | 19 ..mark(inputFunction) |
20 ..add('f(') | 20 ..add('f(') |
(...skipping 25 matching lines...) Expand all Loading... |
46 ..mark(inputExpr) | 46 ..mark(inputExpr) |
47 ..add('_s') | 47 ..add('_s') |
48 ..add(segments[4], projectMarks: true) | 48 ..add(segments[4], projectMarks: true) |
49 ..add('_s') | 49 ..add('_s') |
50 ..add(segments[5], projectMarks: true); | 50 ..add(segments[5], projectMarks: true); |
51 | 51 |
52 expect(printer.text, out); | 52 expect(printer.text, out); |
53 // 8 new lines in the source map: | 53 // 8 new lines in the source map: |
54 expect(printer.map.split(';').length, 8); | 54 expect(printer.map.split(';').length, 8); |
55 | 55 |
56 asFixed(Span s) => new FixedSpan(s.sourceUrl, | 56 asFixed(SourceMapSpan s) => new SourceMapSpan(s.start, s.end, s.text, |
57 s.start.offset, s.start.line, s.start.column, | 57 isIdentifier: s.isIdentifier); |
58 text: s.text, isIdentifier: s.isIdentifier); | |
59 | 58 |
60 // The result is the same if we use fixed positions | 59 // The result is the same if we use fixed positions |
61 var printer2 = new Printer('output2.dart'); | 60 var printer2 = new Printer('output2.dart'); |
62 printer2..mark(new FixedSpan('input.dart', 0, 0, 0)) | 61 printer2..mark(new SourceLocation(0, sourceUrl: 'input.dart').pointSpan()) |
63 ..add(segments[0], projectMarks: true) | 62 ..add(segments[0], projectMarks: true) |
64 ..mark(asFixed(inputVar1)) | 63 ..mark(asFixed(inputVar1)) |
65 ..add('_s') | 64 ..add('_s') |
66 ..add(segments[1], projectMarks: true) | 65 ..add(segments[1], projectMarks: true) |
67 ..mark(asFixed(inputFunction)) | 66 ..mark(asFixed(inputFunction)) |
68 ..add('_s') | 67 ..add('_s') |
69 ..add(segments[2], projectMarks: true) | 68 ..add(segments[2], projectMarks: true) |
70 ..mark(asFixed(inputVar2)) | 69 ..mark(asFixed(inputVar2)) |
71 ..add('_s') | 70 ..add('_s') |
72 ..add(segments[3], projectMarks: true) | 71 ..add(segments[3], projectMarks: true) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 for (int i = 0; i < lines.length; i++) { | 112 for (int i = 0; i < lines.length; i++) { |
114 if (i == 5) printer.indent++; | 113 if (i == 5) printer.indent++; |
115 printer.addLine(lines[i].replaceAll('long', '_s').trim()); | 114 printer.addLine(lines[i].replaceAll('long', '_s').trim()); |
116 if (i == 5) printer.indent--; | 115 if (i == 5) printer.indent--; |
117 } | 116 } |
118 printer.build('output.dart'); | 117 printer.build('output.dart'); |
119 expect(printer.text, out); | 118 expect(printer.text, out); |
120 }); | 119 }); |
121 }); | 120 }); |
122 } | 121 } |
OLD | NEW |