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:json' as json; | 7 import 'dart:json' as json; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'package:source_maps/printer.dart'; | 9 import 'package:source_maps/printer.dart'; |
10 import 'package:source_maps/span.dart'; | 10 import 'package:source_maps/span.dart'; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 ..add(segments[3], projectMarks: true) | 72 ..add(segments[3], projectMarks: true) |
73 ..mark(asFixed(inputExpr)) | 73 ..mark(asFixed(inputExpr)) |
74 ..add('_s') | 74 ..add('_s') |
75 ..add(segments[4], projectMarks: true) | 75 ..add(segments[4], projectMarks: true) |
76 ..add('_s') | 76 ..add('_s') |
77 ..add(segments[5], projectMarks: true); | 77 ..add(segments[5], projectMarks: true); |
78 | 78 |
79 expect(printer2.text, out); | 79 expect(printer2.text, out); |
80 expect(printer2.map, printer.map); | 80 expect(printer2.map, printer.map); |
81 }); | 81 }); |
| 82 |
| 83 group('nested printer', () { |
| 84 test('simple use', () { |
| 85 var printer = new NestedPrinter(); |
| 86 printer..add('var ') |
| 87 ..add('x = 3;\n', location: inputVar1) |
| 88 ..add('f(', location: inputFunction) |
| 89 ..add('y) => ', location: inputVar2) |
| 90 ..add('x + y;\n', location: inputExpr) |
| 91 ..build('output.dart'); |
| 92 expect(printer.text, OUTPUT); |
| 93 expect(printer.map, json.stringify(EXPECTED_MAP)); |
| 94 }); |
| 95 |
| 96 test('nested use', () { |
| 97 var printer = new NestedPrinter(); |
| 98 printer..add('var ') |
| 99 ..add(new NestedPrinter()..add('x = 3;\n', location: inputVar1)) |
| 100 ..add('f(', location: inputFunction) |
| 101 ..add(new NestedPrinter()..add('y) => ', location: inputVar2)) |
| 102 ..add('x + y;\n', location: inputExpr) |
| 103 ..build('output.dart'); |
| 104 expect(printer.text, OUTPUT); |
| 105 expect(printer.map, json.stringify(EXPECTED_MAP)); |
| 106 }); |
| 107 |
| 108 test('add indentation', () { |
| 109 var out = INPUT.replaceAll('long', '_s'); |
| 110 var lines = INPUT.trim().split('\n'); |
| 111 expect(lines.length, 7); |
| 112 var printer = new NestedPrinter(); |
| 113 for (int i = 0; i < lines.length; i++) { |
| 114 if (i == 5) printer.indent++; |
| 115 printer.addLine(lines[i].replaceAll('long', '_s').trim()); |
| 116 if (i == 5) printer.indent--; |
| 117 } |
| 118 printer.build('output.dart'); |
| 119 expect(printer.text, out); |
| 120 }); |
| 121 }); |
82 } | 122 } |
OLD | NEW |