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 /// Common input/output used by builder, parser and end2end tests | 5 /// Common input/output used by builder, parser and end2end tests |
6 library test.common; | 6 library test.common; |
7 | 7 |
8 import 'package:source_maps/source_maps.dart'; | 8 import 'package:source_maps/source_maps.dart'; |
| 9 import 'package:source_span/source_span.dart'; |
9 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
10 | 11 |
11 /// Content of the source file | 12 /// Content of the source file |
12 const String INPUT = ''' | 13 const String INPUT = ''' |
13 /** this is a comment. */ | 14 /** this is a comment. */ |
14 int longVar1 = 3; | 15 int longVar1 = 3; |
15 | 16 |
16 // this is a comment too | 17 // this is a comment too |
17 int longName(int longVar2) { | 18 int longName(int longVar2) { |
18 return longVar1 + longVar2; | 19 return longVar1 + longVar2; |
19 } | 20 } |
20 '''; | 21 '''; |
21 var input = new SourceFile.text('input.dart', INPUT); | 22 var input = new SourceFile(INPUT, url: 'input.dart'); |
22 | 23 |
23 /// A span in the input file | 24 /// A span in the input file |
24 Span ispan(int start, int end, [bool isIdentifier = false]) => | 25 SourceMapSpan ispan(int start, int end, [bool isIdentifier = false]) => |
25 new FileSpan(input, start, end, isIdentifier); | 26 new SourceMapFileSpan(input.span(start, end), isIdentifier: isIdentifier); |
26 | 27 |
27 Span inputVar1 = ispan(30, 38, true); | 28 SourceMapSpan inputVar1 = ispan(30, 38, true); |
28 Span inputFunction = ispan(74, 82, true); | 29 SourceMapSpan inputFunction = ispan(74, 82, true); |
29 Span inputVar2 = ispan(87, 95, true); | 30 SourceMapSpan inputVar2 = ispan(87, 95, true); |
30 | 31 |
31 Span inputVar1NoSymbol = ispan(30, 38); | 32 SourceMapSpan inputVar1NoSymbol = ispan(30, 38); |
32 Span inputFunctionNoSymbol = ispan(74, 82); | 33 SourceMapSpan inputFunctionNoSymbol = ispan(74, 82); |
33 Span inputVar2NoSymbol = ispan(87, 95); | 34 SourceMapSpan inputVar2NoSymbol = ispan(87, 95); |
34 | 35 |
35 Span inputExpr = ispan(108, 127); | 36 SourceMapSpan inputExpr = ispan(108, 127); |
36 | 37 |
37 /// Content of the target file | 38 /// Content of the target file |
38 const String OUTPUT = ''' | 39 const String OUTPUT = ''' |
39 var x = 3; | 40 var x = 3; |
40 f(y) => x + y; | 41 f(y) => x + y; |
41 '''; | 42 '''; |
42 var output = new SourceFile.text('output.dart', OUTPUT); | 43 var output = new SourceFile(OUTPUT, url: 'output.dart'); |
43 | 44 |
44 /// A span in the output file | 45 /// A span in the output file |
45 Span ospan(int start, int end, [bool isIdentifier = false]) => | 46 SourceMapSpan ospan(int start, int end, [bool isIdentifier = false]) => |
46 new FileSpan(output, start, end, isIdentifier); | 47 new SourceMapFileSpan(output.span(start, end), isIdentifier: isIdentifier); |
47 | 48 |
48 Span outputVar1 = ospan(4, 5, true); | 49 SourceMapSpan outputVar1 = ospan(4, 5, true); |
49 Span outputFunction = ospan(11, 12, true); | 50 SourceMapSpan outputFunction = ospan(11, 12, true); |
50 Span outputVar2 = ospan(13, 14, true); | 51 SourceMapSpan outputVar2 = ospan(13, 14, true); |
51 Span outputVar1NoSymbol = ospan(4, 5); | 52 SourceMapSpan outputVar1NoSymbol = ospan(4, 5); |
52 Span outputFunctionNoSymbol = ospan(11, 12); | 53 SourceMapSpan outputFunctionNoSymbol = ospan(11, 12); |
53 Span outputVar2NoSymbol = ospan(13, 14); | 54 SourceMapSpan outputVar2NoSymbol = ospan(13, 14); |
54 Span outputExpr = ospan(19, 24); | 55 SourceMapSpan outputExpr = ospan(19, 24); |
55 | 56 |
56 /// Expected output mapping when recording the following four mappings: | 57 /// Expected output mapping when recording the following four mappings: |
57 /// inputVar1 <= outputVar1 | 58 /// inputVar1 <= outputVar1 |
58 /// inputFunction <= outputFunction | 59 /// inputFunction <= outputFunction |
59 /// inputVar2 <= outputVar2 | 60 /// inputVar2 <= outputVar2 |
60 /// inputExpr <= outputExpr | 61 /// inputExpr <= outputExpr |
61 /// | 62 /// |
62 /// This mapping is stored in the tests so we can independently test the builder | 63 /// This mapping is stored in the tests so we can independently test the builder |
63 /// and parser algorithms without relying entirely on end2end tests. | 64 /// and parser algorithms without relying entirely on end2end tests. |
64 const Map<String, dynamic> EXPECTED_MAP = const { | 65 const Map<String, dynamic> EXPECTED_MAP = const { |
65 'version': 3, | 66 'version': 3, |
66 'sourceRoot': '', | 67 'sourceRoot': '', |
67 'sources': const ['input.dart'], | 68 'sources': const ['input.dart'], |
68 'names': const ['longVar1','longName','longVar2'], | 69 'names': const ['longVar1','longName','longVar2'], |
69 'mappings': 'IACIA;AAGAC,EAAaC,MACR', | 70 'mappings': 'IACIA;AAGAC,EAAaC,MACR', |
70 'file': 'output.dart' | 71 'file': 'output.dart' |
71 }; | 72 }; |
72 | 73 |
73 check(Span outputSpan, Mapping mapping, Span inputSpan, bool realOffsets) { | 74 check(SourceSpan outputSpan, Mapping mapping, SourceMapSpan inputSpan, |
| 75 bool realOffsets) { |
74 var line = outputSpan.start.line; | 76 var line = outputSpan.start.line; |
75 var column = outputSpan.start.column; | 77 var column = outputSpan.start.column; |
76 var files = realOffsets ? {'input.dart': input} : null; | 78 var files = realOffsets ? {'input.dart': input} : null; |
77 var span = mapping.spanFor(line, column, files: files); | 79 var span = mapping.spanFor(line, column, files: files); |
78 var span2 = mapping.spanForLocation(outputSpan.start, files: files); | 80 var span2 = mapping.spanForLocation(outputSpan.start, files: files); |
79 | 81 |
80 // Both mapping APIs are equivalent. | 82 // Both mapping APIs are equivalent. |
81 expect(span.start.offset, span2.start.offset); | 83 expect(span.start.offset, span2.start.offset); |
82 expect(span.start.line, span2.start.line); | 84 expect(span.start.line, span2.start.line); |
83 expect(span.start.column, span2.start.column); | 85 expect(span.start.column, span2.start.column); |
(...skipping 12 matching lines...) Expand all Loading... |
96 expect(span.end.line, inputSpan.end.line); | 98 expect(span.end.line, inputSpan.end.line); |
97 expect(span.end.column, inputSpan.end.column); | 99 expect(span.end.column, inputSpan.end.column); |
98 expect(span.end.offset, span.start.offset + inputSpan.text.length); | 100 expect(span.end.offset, span.start.offset + inputSpan.text.length); |
99 if (realOffsets) expect(span.end.offset, inputSpan.end.offset); | 101 if (realOffsets) expect(span.end.offset, inputSpan.end.offset); |
100 } else { | 102 } else { |
101 expect(span.end.offset, span.start.offset); | 103 expect(span.end.offset, span.start.offset); |
102 expect(span.end.line, span.start.line); | 104 expect(span.end.line, span.start.line); |
103 expect(span.end.column, span.start.column); | 105 expect(span.end.column, span.start.column); |
104 } | 106 } |
105 } | 107 } |
OLD | NEW |