OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 dart_style.test.source_code_test; |
| 6 |
| 7 import 'package:test/test.dart'; |
| 8 |
| 9 import 'package:dart_style/dart_style.dart'; |
| 10 |
| 11 void main() { |
| 12 var selection = |
| 13 new SourceCode("123456;", selectionStart: 3, selectionLength: 2); |
| 14 var noSelection = new SourceCode("123456;"); |
| 15 |
| 16 group('constructor', () { |
| 17 test('throws on negative start', () { |
| 18 expect(() { |
| 19 new SourceCode("12345;", selectionStart: -1, selectionLength: 0); |
| 20 }, throwsArgumentError); |
| 21 }); |
| 22 |
| 23 test('throws on out of bounds start', () { |
| 24 expect(() { |
| 25 new SourceCode("12345;", selectionStart: 7, selectionLength: 0); |
| 26 }, throwsArgumentError); |
| 27 }); |
| 28 |
| 29 test('throws on negative length', () { |
| 30 expect(() { |
| 31 new SourceCode("12345;", selectionStart: 1, selectionLength: -1); |
| 32 }, throwsArgumentError); |
| 33 }); |
| 34 |
| 35 test('throws on out of bounds length', () { |
| 36 expect(() { |
| 37 new SourceCode("12345;", selectionStart: 2, selectionLength: 5); |
| 38 }, throwsArgumentError); |
| 39 }); |
| 40 |
| 41 test('throws is start is null and length is not', () { |
| 42 expect(() { |
| 43 new SourceCode("12345;", selectionStart: 0); |
| 44 }, throwsArgumentError); |
| 45 }); |
| 46 |
| 47 test('throws is length is null and start is not', () { |
| 48 expect(() { |
| 49 new SourceCode("12345;", selectionLength: 1); |
| 50 }, throwsArgumentError); |
| 51 }); |
| 52 }); |
| 53 |
| 54 group('textBeforeSelection', () { |
| 55 test('gets substring before selection', () { |
| 56 expect(selection.textBeforeSelection, equals("123")); |
| 57 }); |
| 58 |
| 59 test('gets entire string if no selection', () { |
| 60 expect(noSelection.textBeforeSelection, equals("123456;")); |
| 61 }); |
| 62 }); |
| 63 |
| 64 group('selectedText', () { |
| 65 test('gets selection substring', () { |
| 66 expect(selection.selectedText, equals("45")); |
| 67 }); |
| 68 |
| 69 test('gets empty string if no selection', () { |
| 70 expect(noSelection.selectedText, equals("")); |
| 71 }); |
| 72 }); |
| 73 |
| 74 group('textAfterSelection', () { |
| 75 test('gets substring after selection', () { |
| 76 expect(selection.textAfterSelection, equals("6;")); |
| 77 }); |
| 78 |
| 79 test('gets empty string if no selection', () { |
| 80 expect(noSelection.textAfterSelection, equals("")); |
| 81 }); |
| 82 }); |
| 83 } |
OLD | NEW |