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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
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:source_span/source_span.dart';
10 import 'package:unittest/unittest.dart';
11
12 /// Content of the source file
13 const String INPUT = '''
14 /** this is a comment. */
15 int longVar1 = 3;
16
17 // this is a comment too
18 int longName(int longVar2) {
19 return longVar1 + longVar2;
20 }
21 ''';
22 var input = new SourceFile(INPUT, url: 'input.dart');
23
24 /// A span in the input file
25 SourceMapSpan ispan(int start, int end, [bool isIdentifier = false]) =>
26 new SourceMapFileSpan(input.span(start, end), isIdentifier: isIdentifier);
27
28 SourceMapSpan inputVar1 = ispan(30, 38, true);
29 SourceMapSpan inputFunction = ispan(74, 82, true);
30 SourceMapSpan inputVar2 = ispan(87, 95, true);
31
32 SourceMapSpan inputVar1NoSymbol = ispan(30, 38);
33 SourceMapSpan inputFunctionNoSymbol = ispan(74, 82);
34 SourceMapSpan inputVar2NoSymbol = ispan(87, 95);
35
36 SourceMapSpan inputExpr = ispan(108, 127);
37
38 /// Content of the target file
39 const String OUTPUT = '''
40 var x = 3;
41 f(y) => x + y;
42 ''';
43 var output = new SourceFile(OUTPUT, url: 'output.dart');
44
45 /// A span in the output file
46 SourceMapSpan ospan(int start, int end, [bool isIdentifier = false]) =>
47 new SourceMapFileSpan(output.span(start, end), isIdentifier: isIdentifier);
48
49 SourceMapSpan outputVar1 = ospan(4, 5, true);
50 SourceMapSpan outputFunction = ospan(11, 12, true);
51 SourceMapSpan outputVar2 = ospan(13, 14, true);
52 SourceMapSpan outputVar1NoSymbol = ospan(4, 5);
53 SourceMapSpan outputFunctionNoSymbol = ospan(11, 12);
54 SourceMapSpan outputVar2NoSymbol = ospan(13, 14);
55 SourceMapSpan outputExpr = ospan(19, 24);
56
57 /// Expected output mapping when recording the following four mappings:
58 /// inputVar1 <= outputVar1
59 /// inputFunction <= outputFunction
60 /// inputVar2 <= outputVar2
61 /// inputExpr <= outputExpr
62 ///
63 /// This mapping is stored in the tests so we can independently test the builder
64 /// and parser algorithms without relying entirely on end2end tests.
65 const Map<String, dynamic> EXPECTED_MAP = const {
66 'version': 3,
67 'sourceRoot': '',
68 'sources': const ['input.dart'],
69 'names': const ['longVar1','longName','longVar2'],
70 'mappings': 'IACIA;AAGAC,EAAaC,MACR',
71 'file': 'output.dart'
72 };
73
74 check(SourceSpan outputSpan, Mapping mapping, SourceMapSpan inputSpan,
75 bool realOffsets) {
76 var line = outputSpan.start.line;
77 var column = outputSpan.start.column;
78 var files = realOffsets ? {'input.dart': input} : null;
79 var span = mapping.spanFor(line, column, files: files);
80 var span2 = mapping.spanForLocation(outputSpan.start, files: files);
81
82 // Both mapping APIs are equivalent.
83 expect(span.start.offset, span2.start.offset);
84 expect(span.start.line, span2.start.line);
85 expect(span.start.column, span2.start.column);
86 expect(span.end.offset, span2.end.offset);
87 expect(span.end.line, span2.end.line);
88 expect(span.end.column, span2.end.column);
89
90 // Mapping matches our input location (modulo using real offsets)
91 expect(span.start.line, inputSpan.start.line);
92 expect(span.start.column, inputSpan.start.column);
93 expect(span.sourceUrl, inputSpan.sourceUrl);
94 expect(span.start.offset, realOffsets ? inputSpan.start.offset : 0);
95
96 // Mapping includes the identifier, if any
97 if (inputSpan.isIdentifier) {
98 expect(span.end.line, inputSpan.end.line);
99 expect(span.end.column, inputSpan.end.column);
100 expect(span.end.offset, span.start.offset + inputSpan.text.length);
101 if (realOffsets) expect(span.end.offset, inputSpan.end.offset);
102 } else {
103 expect(span.end.offset, span.start.offset);
104 expect(span.end.line, span.start.line);
105 expect(span.end.column, span.start.column);
106 }
107 }
OLDNEW
« no previous file with comments | « packages/source_maps/test/builder_test.dart ('k') | packages/source_maps/test/end2end_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698