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

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

Issue 12207008: Move source maps package to the dart repo, so it can be used by other internal (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 7 years, 9 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
« no previous file with comments | « pkg/source_maps/test/builder_test.dart ('k') | pkg/source_maps/test/end2end_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 /// Common input/output used by builder, parser and end2end tests
6 library test.common;
7
8 import 'package:source_maps/source_maps.dart';
9 import 'package:unittest/unittest.dart';
10
11 /// Content of the source file
12 const String INPUT = '''
13 /** this is a comment. */
14 int longVar1 = 3;
15
16 // this is a comment too
17 int longName(int longVar2) {
18 return longVar1 + longVar2;
19 }
20 ''';
21 var input = new SourceFile.text('input.dart', INPUT);
22
23 /// A span in the input file
24 Span ispan(int start, int end, [bool isIdentifier = false]) =>
25 new FileSpan(input, start, end, isIdentifier);
26
27 Span inputVar1 = ispan(30, 38, true);
28 Span inputFunction = ispan(74, 82, true);
29 Span inputVar2 = ispan(87, 95, true);
30 Span inputExpr = ispan(108, 127);
31
32 /// Content of the target file
33 const String OUTPUT = '''
34 var x = 3;
35 f(y) => x + y;
36 ''';
37 var output = new SourceFile.text('output.dart', OUTPUT);
38
39 /// A span in the output file
40 Span ospan(int start, int end, [bool isIdentifier = false]) =>
41 new FileSpan(output, start, end, isIdentifier);
42
43 Span outputVar1 = ospan(4, 5, true);
44 Span outputFunction = ospan(11, 12, true);
45 Span outputVar2 = ospan(13, 14, true);
46 Span outputExpr = ospan(19, 24);
47
48 /// Expected output mapping when recording the following four mappings:
49 /// inputVar1 <= outputVar1
50 /// inputFunction <= outputFunction
51 /// inputVar2 <= outputVar2
52 /// inputExpr <= outputExpr
53 ///
54 /// This mapping is stored in the tests so we can independently test the builder
55 /// and parser algorithms without relying entirely on end2end tests.
56 const Map<String, dynamic> EXPECTED_MAP = const {
57 'version': 3,
58 'sourceRoot': '',
59 'sources': const ['input.dart'],
60 'names': const ['longVar1','longName','longVar2'],
61 'mappings': 'IACIA;AAGAC,EAAaC,MACR',
62 'file': 'output.dart'
63 };
64
65 check(Span outputSpan, Mapping mapping, Span inputSpan, bool realOffsets) {
66 var line = outputSpan.start.line;
67 var column = outputSpan.start.column;
68 var files = realOffsets ? {'input.dart': input} : null;
69 var span = mapping.spanFor(line, column, files: files);
70 var span2 = mapping.spanForLocation(outputSpan.start, files: files);
71
72 // Both mapping APIs are equivalent.
73 expect(span.start.offset, span2.start.offset);
74 expect(span.start.line, span2.start.line);
75 expect(span.start.column, span2.start.column);
76 expect(span.end.offset, span2.end.offset);
77 expect(span.end.line, span2.end.line);
78 expect(span.end.column, span2.end.column);
79
80 // Mapping matches our input location (modulo using real offsets)
81 expect(span.start.line, inputSpan.start.line);
82 expect(span.start.column, inputSpan.start.column);
83 expect(span.sourceUrl, inputSpan.sourceUrl);
84 expect(span.start.offset, realOffsets ? inputSpan.start.offset : 0);
85
86 // Mapping includes the identifier, if any
87 if (inputSpan.isIdentifier) {
88 expect(span.end.line, inputSpan.end.line);
89 expect(span.end.column, inputSpan.end.column);
90 expect(span.end.offset, span.start.offset + inputSpan.text.length);
91 if (realOffsets) expect(span.end.offset, inputSpan.end.offset);
92 } else {
93 expect(span.end.offset, span.start.offset);
94 expect(span.end.line, span.start.line);
95 expect(span.end.column, span.start.column);
96 }
97 }
OLDNEW
« no previous file with comments | « pkg/source_maps/test/builder_test.dart ('k') | pkg/source_maps/test/end2end_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698