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 import 'package:test/test.dart'; |
| 6 import 'package:source_span/src/utils.dart'; |
| 7 |
| 8 main() { |
| 9 group('find line start', () { |
| 10 test('skip entries in wrong column', () { |
| 11 var context = '0_bb\n1_bbb\n2b____\n3bbb\n'; |
| 12 var index = findLineStart(context, 'b', 1); |
| 13 expect(index, 11); |
| 14 expect(context.substring(index - 1, index + 3), '\n2b_'); |
| 15 }); |
| 16 |
| 17 test('end of line column for empty text', () { |
| 18 var context = '0123\n56789\nabcdefgh\n'; |
| 19 var index = findLineStart(context, '', 5); |
| 20 expect(index, 5); |
| 21 expect(context[index], '5'); |
| 22 }); |
| 23 |
| 24 test('column at the end of the file for empty text', () { |
| 25 var context = '0\n2\n45\n'; |
| 26 var index = findLineStart(context, '', 2); |
| 27 expect(index, 4); |
| 28 expect(context[index], '4'); |
| 29 |
| 30 context = '0\n2\n45'; |
| 31 index = findLineStart(context, '', 2); |
| 32 expect(index, 4); |
| 33 }); |
| 34 |
| 35 test('found on the first line', () { |
| 36 var context = '0\n2\n45\n'; |
| 37 var index = findLineStart(context, '0', 0); |
| 38 expect(index, 0); |
| 39 }); |
| 40 |
| 41 test('not found', () { |
| 42 var context = '0\n2\n45\n'; |
| 43 var index = findLineStart(context, '0', 1); |
| 44 expect(index, isNull); |
| 45 }); |
| 46 }); |
| 47 } |
| 48 |
| 49 _linearSearch(list, predicate) { |
| 50 if (list.length == 0) return -1; |
| 51 for (int i = 0; i < list.length; i++) { |
| 52 if (predicate(list[i])) return i; |
| 53 } |
| 54 return list.length; |
| 55 } |
OLD | NEW |