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