Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: pkg/source_maps/test/printer_test.dart

Issue 23596007: Remove usage of dart:json. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebase. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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: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/printer.dart';
10 import 'package:source_maps/span.dart'; 10 import 'package:source_maps/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(')
21 ..mark(inputVar2) 21 ..mark(inputVar2)
22 ..add('y) => ') 22 ..add('y) => ')
23 ..mark(inputExpr) 23 ..mark(inputExpr)
24 ..add('x + y;\n'); 24 ..add('x + y;\n');
25 expect(printer.text, OUTPUT); 25 expect(printer.text, OUTPUT);
26 expect(printer.map, json.stringify(EXPECTED_MAP)); 26 expect(printer.map, JSON.encode(EXPECTED_MAP));
27 }); 27 });
28 28
29 test('printer projecting marks', () { 29 test('printer projecting marks', () {
30 var out = INPUT.replaceAll('long', '_s'); 30 var out = INPUT.replaceAll('long', '_s');
31 var printer = new Printer('output2.dart'); 31 var printer = new Printer('output2.dart');
32 32
33 var segments = INPUT.split('long'); 33 var segments = INPUT.split('long');
34 expect(segments.length, 6); 34 expect(segments.length, 6);
35 printer..mark(ispan(0, 0)) 35 printer..mark(ispan(0, 0))
36 ..add(segments[0], projectMarks: true) 36 ..add(segments[0], projectMarks: true)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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', span: inputVar1) 87 ..add('x = 3;\n', span: inputVar1)
88 ..add('f(', span: inputFunction) 88 ..add('f(', span: inputFunction)
89 ..add('y) => ', span: inputVar2) 89 ..add('y) => ', span: inputVar2)
90 ..add('x + y;\n', span: 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.encode(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', span: inputVar1)) 99 ..add(new NestedPrinter()..add('x = 3;\n', span: inputVar1))
100 ..add('f(', span: inputFunction) 100 ..add('f(', span: inputFunction)
101 ..add(new NestedPrinter()..add('y) => ', span: inputVar2)) 101 ..add(new NestedPrinter()..add('y) => ', span: inputVar2))
102 ..add('x + y;\n', span: 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.encode(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698