Chromium Code Reviews| 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 library polymer.test.refactor_test; | 5 library polymer.test.refactor_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import 'package:source_maps/refactor.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; | 9 import 'package:source_maps/parser.dart' show parse, Mapping; |
| 10 import 'package:source_span/source_span.dart'; | |
| 11 | 11 |
| 12 main() { | 12 main() { |
| 13 group('conflict detection', () { | 13 group('conflict detection', () { |
| 14 var original = "0123456789abcdefghij"; | 14 var original = "0123456789abcdefghij"; |
| 15 var file = new SourceFile.text('', original); | 15 var file = new SourceFile(original); |
| 16 | 16 |
| 17 test('no conflict, in order', () { | 17 test('no conflict, in order', () { |
| 18 var txn = new TextEditTransaction(original, file); | 18 var txn = new TextEditTransaction(original, file); |
| 19 txn.edit(2, 4, '.'); | 19 txn.edit(2, 4, '.'); |
| 20 txn.edit(5, 5, '|'); | 20 txn.edit(5, 5, '|'); |
| 21 txn.edit(6, 6, '-'); | 21 txn.edit(6, 6, '-'); |
| 22 txn.edit(6, 7, '_'); | 22 txn.edit(6, 7, '_'); |
| 23 expect((txn.commit()..build('')).text, "01.4|5-_789abcdefghij"); | 23 expect((txn.commit()..build('')).text, "01.4|5-_789abcdefghij"); |
| 24 }); | 24 }); |
| 25 | 25 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 41 txn.edit(2, 4, '.'); | 41 txn.edit(2, 4, '.'); |
| 42 txn.edit(3, 3, '-'); | 42 txn.edit(3, 3, '-'); |
| 43 expect(() => txn.commit(), throwsA(predicate( | 43 expect(() => txn.commit(), throwsA(predicate( |
| 44 (e) => e.toString().contains('overlapping edits')))); | 44 (e) => e.toString().contains('overlapping edits')))); |
| 45 }); | 45 }); |
| 46 }); | 46 }); |
| 47 | 47 |
| 48 test('generated source maps', () { | 48 test('generated source maps', () { |
| 49 var original = | 49 var original = |
| 50 "0123456789\n0*23456789\n01*3456789\nabcdefghij\nabcd*fghij\n"; | 50 "0123456789\n0*23456789\n01*3456789\nabcdefghij\nabcd*fghij\n"; |
| 51 var file = new SourceFile.text('', original); | 51 var file = new SourceFile(original); |
| 52 var txn = new TextEditTransaction(original, file); | 52 var txn = new TextEditTransaction(original, file); |
| 53 txn.edit(27, 29, '__\n '); | 53 txn.edit(27, 29, '__\n '); |
| 54 txn.edit(34, 35, '___'); | 54 txn.edit(34, 35, '___'); |
| 55 var printer = (txn.commit()..build('')); | 55 var printer = (txn.commit()..build('')); |
| 56 var output = printer.text; | 56 var output = printer.text; |
| 57 var map = parse(printer.map); | 57 var map = parse(printer.map); |
| 58 expect(output, | 58 expect(output, |
| 59 "0123456789\n0*23456789\n01*34__\n 789\na___cdefghij\nabcd*fghij\n"); | 59 "0123456789\n0*23456789\n01*34__\n 789\na___cdefghij\nabcd*fghij\n"); |
| 60 | 60 |
| 61 // Line 1 and 2 are unmodified: mapping any column returns the beginning | 61 // Line 1 and 2 are unmodified: mapping any column returns the beginning |
| 62 // of the corresponding line: | 62 // of the corresponding line: |
| 63 expect(_span(1, 1, map, file), "line 1, column 1 of .: \n0123456789"); | 63 expect(_span(1, 1, map, file), |
| 64 expect(_span(1, 5, map, file), "line 1, column 1 of .: \n0123456789"); | 64 "line 1, column 1: \n" |
| 65 expect(_span(2, 1, map, file), "line 2, column 1 of .: \n0*23456789"); | 65 "0123456789\n" |
| 66 expect(_span(2, 8, map, file), "line 2, column 1 of .: \n0*23456789"); | 66 "^"); |
| 67 expect(_span(1, 5, map, file), | |
| 68 "line 1, column 1: \n" | |
| 69 "0123456789\n" | |
| 70 "^"); | |
| 71 expect(_span(2, 1, map, file), | |
| 72 "line 2, column 1: \n" | |
| 73 "0*23456789\n" | |
| 74 "^"); | |
| 75 expect(_span(2, 8, map, file), | |
| 76 "line 2, column 1: \n" | |
| 77 "0*23456789\n" | |
| 78 "^"); | |
| 67 | 79 |
| 68 // Line 3 is modified part way: mappings before the edits have the right | 80 // Line 3 is modified part way: mappings before the edits have the right |
| 69 // mapping, after the edits the mapping is null. | 81 // mapping, after the edits the mapping is null. |
| 70 expect(_span(3, 1, map, file), "line 3, column 1 of .: \n01*3456789"); | 82 expect(_span(3, 1, map, file), |
| 71 expect(_span(3, 5, map, file), "line 3, column 1 of .: \n01*3456789"); | 83 "line 3, column 1: \n" |
| 84 "01*3456789\n" | |
| 85 "^"); | |
| 86 expect(_span(3, 5, map, file), | |
| 87 "line 3, column 1: \n" | |
| 88 "01*3456789\n" | |
| 89 "^"); | |
| 72 | 90 |
| 73 // Start of edits map to beginning of the edit secion: | 91 // Start of edits map to beginning of the edit secion: |
| 74 expect(_span(3, 6, map, file), "line 3, column 6 of .: \n01*3456789"); | 92 expect(_span(3, 6, map, file), |
| 75 expect(_span(3, 7, map, file), "line 3, column 6 of .: \n01*3456789"); | 93 "line 3, column 6: \n" |
| 94 "01*3456789\n" | |
| 95 " ^"); | |
| 96 expect(_span(3, 7, map, file), | |
| 97 "line 3, column 6: \n" | |
| 98 "01*3456789\n" | |
| 99 " ^"); | |
| 76 | 100 |
| 77 // Lines added have no mapping (they should inherit the last mapping), | 101 // Lines added have no mapping (they should inherit the last mapping), |
| 78 // but the end of the edit region continues were we left off: | 102 // but the end of the edit region continues were we left off: |
| 79 expect(_span(4, 1, map, file), isNull); | 103 expect(_span(4, 1, map, file), isNull); |
| 80 expect(_span(4, 5, map, file), "line 3, column 8 of .: \n01*3456789"); | 104 expect(_span(4, 5, map, file), |
| 105 "line 3, column 8: \n" | |
| 106 "01*3456789\n" | |
| 107 " ^"); | |
| 81 | 108 |
| 82 // Subsequent lines are still mapped correctly: | 109 // Subsequent lines are still mapped correctly: |
| 83 // a (in a___cd...) | 110 // a (in a___cd...) |
| 84 expect(_span(5, 1, map, file), "line 4, column 1 of .: \nabcdefghij"); | 111 expect(_span(5, 1, map, file), |
| 112 "line 4, column 1: \n" | |
| 113 "abcdefghij\n" | |
| 114 "^"); | |
| 85 // _ (in a___cd...) | 115 // _ (in a___cd...) |
| 86 expect(_span(5, 2, map, file), "line 4, column 2 of .: \nabcdefghij"); | 116 expect(_span(5, 2, map, file), |
| 117 "line 4, column 2: \n" | |
| 118 "abcdefghij\n" | |
| 119 " ^"); | |
| 87 // _ (in a___cd...) | 120 // _ (in a___cd...) |
| 88 expect(_span(5, 3, map, file), "line 4, column 2 of .: \nabcdefghij"); | 121 expect(_span(5, 3, map, file), |
| 122 "line 4, column 2: \n" | |
| 123 "abcdefghij\n" | |
| 124 " ^"); | |
| 89 // _ (in a___cd...) | 125 // _ (in a___cd...) |
| 90 expect(_span(5, 4, map, file), "line 4, column 2 of .: \nabcdefghij"); | 126 expect(_span(5, 4, map, file), |
| 127 "line 4, column 2: \n" | |
| 128 "abcdefghij\n" | |
| 129 " ^"); | |
| 91 // c (in a___cd...) | 130 // c (in a___cd...) |
| 92 expect(_span(5, 5, map, file), "line 4, column 3 of .: \nabcdefghij"); | 131 expect(_span(5, 5, map, file), |
| 93 expect(_span(6, 1, map, file), "line 5, column 1 of .: \nabcd*fghij"); | 132 "line 4, column 3: \n" |
| 94 expect(_span(6, 8, map, file), "line 5, column 1 of .: \nabcd*fghij"); | 133 "abcdefghij\n" |
| 134 " ^"); | |
| 135 expect(_span(6, 1, map, file), | |
| 136 "line 5, column 1: \n" | |
| 137 "abcd*fghij\n" | |
| 138 "^"); | |
| 139 expect(_span(6, 8, map, file), | |
| 140 "line 5, column 1: \n" | |
| 141 "abcd*fghij\n" | |
| 142 "^"); | |
| 95 }); | 143 }); |
| 96 } | 144 } |
| 97 | 145 |
| 98 String _span(int line, int column, Mapping map, SourceFile file) { | 146 String _span(int line, int column, Mapping map, SourceFile file) { |
| 99 var span = map.spanFor(line - 1, column - 1, files: {'': file}); | 147 var span = map.spanFor(line - 1, column - 1, files: {'': file}); |
| 100 return span == null ? null : span.getLocationMessage('').trim(); | 148 return span == null ? null : span.message('').trim(); |
|
Siggi Cherem (dart-lang)
2014/07/31 21:01:38
mmm... seeing this test made me realize that 'mess
nweiz
2014/07/31 22:01:24
What's the point of formatting a message if it's n
| |
| 101 } | 149 } |
| OLD | NEW |