| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 // Unittest for the [LineColumnCollector]. |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 import 'package:compiler/src/io/code_output.dart'; |
| 9 import 'package:compiler/src/io/line_column_provider.dart'; |
| 10 |
| 11 import 'output_collector.dart'; |
| 12 |
| 13 test(List events, Map<int, List<int>> expectedPositions) { |
| 14 BufferedEventSink sink = new BufferedEventSink(); |
| 15 LineColumnProvider lineColumnProvider = new LineColumnCollector(); |
| 16 CodeOutput output = new StreamCodeOutput(sink, [lineColumnProvider]); |
| 17 for (var event in events) { |
| 18 if (event is String) { |
| 19 output.add(event); |
| 20 } else if (event is CodeBuffer) { |
| 21 output.addBuffer(event); |
| 22 } |
| 23 } |
| 24 output.close(); |
| 25 |
| 26 expectedPositions.forEach((int offset, List<int> expectedPosition) { |
| 27 if (expectedPosition == null) { |
| 28 Expect.throws(() => lineColumnProvider.getLine(offset), |
| 29 (e) => true, |
| 30 'Expected out-of-bounds offset: $offset\n' |
| 31 'text:"""${sink.text}"""\n' |
| 32 'lineColumnProvider:$lineColumnProvider'); |
| 33 } else { |
| 34 int line = lineColumnProvider.getLine(offset); |
| 35 int column = lineColumnProvider.getColumn(line, offset); |
| 36 Expect.equals(expectedPosition[0], line, |
| 37 'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n' |
| 38 'text:"""${sink.text}"""\n' |
| 39 'lineColumnProvider:$lineColumnProvider'); |
| 40 Expect.equals(expectedPosition[1], column, |
| 41 'Unexpected result: $offset -> $expectedPosition = [$line,$column]\n' |
| 42 'text:"""${sink.text}"""\n' |
| 43 'lineColumnProvider:$lineColumnProvider'); |
| 44 } |
| 45 }); |
| 46 } |
| 47 |
| 48 main() { |
| 49 test([""], {0: [0, 0], 1: null}); |
| 50 |
| 51 test([" "], {0: [0, 0], 1: [0, 1], 2: null}); |
| 52 |
| 53 test(["\n "], {0: [0, 0], 1: [1, 0], 2: [1, 1], 3: null}); |
| 54 |
| 55 Map positions = {0: [0, 0], |
| 56 1: [0, 1], |
| 57 2: [1, 0], |
| 58 3: [1, 1], |
| 59 4: [2, 0], |
| 60 5: [2, 1], |
| 61 6: null}; |
| 62 |
| 63 test(["a\nb\nc"], positions); |
| 64 |
| 65 test(["a", "\nb\nc"], positions); |
| 66 |
| 67 test(["a", "\n", "b\nc"], positions); |
| 68 |
| 69 CodeBuffer buffer1 = new CodeBuffer(); |
| 70 buffer1.add("a\nb\nc"); |
| 71 test([buffer1], positions); |
| 72 |
| 73 CodeBuffer buffer2 = new CodeBuffer(); |
| 74 buffer2.add("\nb\nc"); |
| 75 test(["a", buffer2], positions); |
| 76 |
| 77 CodeBuffer buffer3 = new CodeBuffer(); |
| 78 buffer3.add("a"); |
| 79 test([buffer3, buffer2], positions); |
| 80 |
| 81 CodeBuffer buffer4 = new CodeBuffer(); |
| 82 buffer4.addBuffer(buffer3); |
| 83 test([buffer4, buffer2], positions); |
| 84 } |
| OLD | NEW |