OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, 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:analyzer_cli/src/message_grouper.dart'; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 |
| 8 import 'utils.dart'; |
| 9 |
| 10 main() { |
| 11 MessageGrouper messageGrouper; |
| 12 TestStdinStream stdinStream; |
| 13 |
| 14 setUp(() { |
| 15 stdinStream = new TestStdinStream(); |
| 16 messageGrouper = new MessageGrouper(stdinStream); |
| 17 }); |
| 18 |
| 19 group('message_grouper', () { |
| 20 /// Check that if the message grouper produces the [expectedOutput] in |
| 21 /// response to the corresponding [input]. |
| 22 void check(List<int> input, List<List<int>> expectedOutput) { |
| 23 stdinStream.addInputBytes(input); |
| 24 for (var chunk in expectedOutput) { |
| 25 expect(messageGrouper.next, equals(chunk)); |
| 26 } |
| 27 } |
| 28 |
| 29 /// Make a simple message having the given [length] |
| 30 List<int> makeMessage(int length) { |
| 31 var result = <int>[]; |
| 32 for (int i = 0; i < length; i++) { |
| 33 result.add(i & 0xff); |
| 34 } |
| 35 return result; |
| 36 } |
| 37 |
| 38 test('Empty message', () { |
| 39 check([0], [[]]); |
| 40 }); |
| 41 |
| 42 test('Short message', () { |
| 43 check([ |
| 44 5, |
| 45 10, |
| 46 20, |
| 47 30, |
| 48 40, |
| 49 50 |
| 50 ], [ |
| 51 [10, 20, 30, 40, 50] |
| 52 ]); |
| 53 }); |
| 54 |
| 55 test('Message with 2-byte length', () { |
| 56 var len = 0x155; |
| 57 var msg = makeMessage(len); |
| 58 var encodedLen = [0xd5, 0x02]; |
| 59 check([]..addAll(encodedLen)..addAll(msg), [msg]); |
| 60 }); |
| 61 |
| 62 test('Message with 3-byte length', () { |
| 63 var len = 0x4103; |
| 64 var msg = makeMessage(len); |
| 65 var encodedLen = [0x83, 0x82, 0x01]; |
| 66 check([]..addAll(encodedLen)..addAll(msg), [msg]); |
| 67 }); |
| 68 |
| 69 test('Multiple messages', () { |
| 70 check([ |
| 71 2, |
| 72 10, |
| 73 20, |
| 74 2, |
| 75 30, |
| 76 40 |
| 77 ], [ |
| 78 [10, 20], |
| 79 [30, 40] |
| 80 ]); |
| 81 }); |
| 82 |
| 83 test('Empty message at start', () { |
| 84 check([ |
| 85 0, |
| 86 2, |
| 87 10, |
| 88 20 |
| 89 ], [ |
| 90 [], |
| 91 [10, 20] |
| 92 ]); |
| 93 }); |
| 94 |
| 95 test('Empty message at end', () { |
| 96 check([ |
| 97 2, |
| 98 10, |
| 99 20, |
| 100 0 |
| 101 ], [ |
| 102 [10, 20], |
| 103 [] |
| 104 ]); |
| 105 }); |
| 106 |
| 107 test('Empty message in the middle', () { |
| 108 check([ |
| 109 2, |
| 110 10, |
| 111 20, |
| 112 0, |
| 113 2, |
| 114 30, |
| 115 40 |
| 116 ], [ |
| 117 [10, 20], |
| 118 [], |
| 119 [30, 40] |
| 120 ]); |
| 121 }); |
| 122 }); |
| 123 } |
OLD | NEW |