OLD | NEW |
---|---|
(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 library polymer.test.refactor_test; | |
6 | |
7 import 'package:unittest/unittest.dart'; | |
8 import 'package:source_maps/refactor.dart'; | |
9 import 'package:source_maps/span.dart'; | |
10 import 'package:source_maps/parser.dart' show parse, Mapping; | |
11 | |
12 main() { | |
13 group('conflict detection', () { | |
14 var original = "0123456789abcdefghij"; | |
15 var file = new SourceFile.text('', original); | |
16 | |
17 test('no conflict, in order', () { | |
18 var txn = new TextEditTransaction(original, file); | |
19 txn.edit(2, 4, '.'); | |
20 txn.edit(5, 5, '|'); | |
21 txn.edit(6, 6, '-'); | |
22 txn.edit(6, 7, '_'); | |
23 expect((txn.commit()..build('')).text, "01.4|5-_789abcdefghij"); | |
24 }); | |
25 | |
26 test('no conflict, out of order', () { | |
27 var txn = new TextEditTransaction(original, file); | |
28 txn.edit(2, 4, '.'); | |
29 txn.edit(5, 5, '|'); | |
30 | |
31 // Regresion test for issue #404: there is no conflict/overlap for edits | |
32 // that don't remove any of the original code. | |
33 txn.edit(6, 7, '_'); | |
34 txn.edit(6, 6, '-'); | |
35 expect((txn.commit()..build('')).text, "01.4|5-_789abcdefghij"); | |
36 | |
37 }); | |
38 | |
39 test('conflict', () { | |
40 var txn = new TextEditTransaction(original, file); | |
41 txn.edit(2, 4, '.'); | |
42 txn.edit(3, 3, '-'); | |
43 expect(() => txn.commit(), throwsA(predicate( | |
44 (e) => e.toString().contains('overlapping edits')))); | |
45 }); | |
46 }); | |
Siggi Cherem (dart-lang)
2013/08/09 22:09:09
Above this line is the same tests as before (chang
| |
47 | |
48 test('generated source maps', () { | |
49 var original = | |
50 "0123456789\n0*23456789\n01*3456789\nabcdefghij\nabcd*fghij\n"; | |
51 var file = new SourceFile.text('', original); | |
52 var txn = new TextEditTransaction(original, file); | |
53 txn.edit(27, 29, '__\n '); | |
54 txn.edit(34, 35, '___'); | |
55 var printer = (txn.commit()..build('')); | |
56 var output = printer.text; | |
57 var map = parse(printer.map); | |
58 expect(output, | |
59 "0123456789\n0*23456789\n01*34__\n 789\na___cdefghij\nabcd*fghij\n"); | |
60 | |
61 // Line 1 and 2 are unmodified: mapping any column returns the beginning | |
62 // of the corresponding line: | |
63 expect(_span(1, 1, map, file), ":1:1: \n0123456789"); | |
64 expect(_span(1, 5, map, file), ":1:1: \n0123456789"); | |
65 expect(_span(2, 1, map, file), ":2:1: \n0*23456789"); | |
66 expect(_span(2, 8, map, file), ":2:1: \n0*23456789"); | |
67 | |
68 // Line 3 is modified part way: mappings before the edits have the right | |
69 // mapping, after the edits the mapping is null. | |
70 expect(_span(3, 1, map, file), ":3:1: \n01*3456789"); | |
71 expect(_span(3, 5, map, file), ":3:1: \n01*3456789"); | |
72 | |
73 // Start of edits map to beginning of the edit secion: | |
74 expect(_span(3, 6, map, file), ":3:6: \n01*3456789"); | |
75 expect(_span(3, 7, map, file), ":3:6: \n01*3456789"); | |
76 | |
77 // Lines added have no mapping (they should inherit the last mapping), | |
78 // but the end of the edit region continues were we left off: | |
79 expect(_span(4, 1, map, file), isNull); | |
80 expect(_span(4, 5, map, file), ":3:8: \n01*3456789"); | |
81 | |
82 // Subsequent lines are still mapped correctly: | |
83 expect(_span(5, 1, map, file), ":4:1: \nabcdefghij"); // a (in a___cd...) | |
84 expect(_span(5, 2, map, file), ":4:2: \nabcdefghij"); // _ (in a___cd...) | |
85 expect(_span(5, 3, map, file), ":4:2: \nabcdefghij"); // _ (in a___cd...) | |
86 expect(_span(5, 4, map, file), ":4:2: \nabcdefghij"); // _ (in a___cd...) | |
87 expect(_span(5, 5, map, file), ":4:3: \nabcdefghij"); // c (in a___cd...) | |
88 expect(_span(6, 1, map, file), ":5:1: \nabcd*fghij"); | |
89 expect(_span(6, 8, map, file), ":5:1: \nabcd*fghij"); | |
90 }); | |
91 } | |
92 | |
93 String _span(int line, int column, Mapping map, SourceFile file) { | |
94 var span = map.spanFor(line - 1, column - 1, files: {'': file}); | |
95 return span == null ? null : span.getLocationMessage('').trim(); | |
96 } | |
OLD | NEW |