| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 test.protocol; | 5 library test.protocol; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_testing/reflective_tests.dart'; | 10 import 'package:analysis_testing/reflective_tests.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 import 'package:analysis_server/src/collections.dart'; |
| 12 | 13 |
| 13 | 14 |
| 14 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>()); | 15 Matcher _throwsRequestFailure = throwsA(new isInstanceOf<RequestFailure>()); |
| 15 | 16 |
| 16 | 17 |
| 17 main() { | 18 main() { |
| 18 groupSep = ' | '; | 19 groupSep = ' | '; |
| 19 group('Notification', () { | 20 group('Notification', () { |
| 20 runReflectiveTests(NotificationTest); | 21 runReflectiveTests(NotificationTest); |
| 21 }); | 22 }); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 99 |
| 99 void test_getParameter_undefined() { | 100 void test_getParameter_undefined() { |
| 100 Notification notification = new Notification('foo'); | 101 Notification notification = new Notification('foo'); |
| 101 expect(notification.event, equals('foo')); | 102 expect(notification.event, equals('foo')); |
| 102 expect(notification.params.length, equals(0)); | 103 expect(notification.params.length, equals(0)); |
| 103 expect(notification.getParameter('x'), isNull); | 104 expect(notification.getParameter('x'), isNull); |
| 104 expect(notification.toJson(), equals({ | 105 expect(notification.toJson(), equals({ |
| 105 'event': 'foo' | 106 'event': 'foo' |
| 106 })); | 107 })); |
| 107 } | 108 } |
| 109 |
| 110 void test_setParameter_HasToJson() { |
| 111 Notification notification = new Notification('foo'); |
| 112 notification.setParameter('my', new _MyHasToJsonObject(42)); |
| 113 expect(notification.toJson(), equals({ |
| 114 'event': 'foo', |
| 115 'params': { |
| 116 'my': { |
| 117 'offset': 42 |
| 118 } |
| 119 } |
| 120 })); |
| 121 } |
| 122 |
| 123 void test_setParameter_Iterable_HasToJson() { |
| 124 Notification notification = new Notification('foo'); |
| 125 notification.setParameter('my', [ |
| 126 new _MyHasToJsonObject(1), |
| 127 new _MyHasToJsonObject(2), |
| 128 new _MyHasToJsonObject(3)]); |
| 129 expect(notification.toJson(), equals({ |
| 130 'event': 'foo', |
| 131 'params': { |
| 132 'my': [{'offset': 1}, {'offset': 2}, {'offset': 3}] |
| 133 } |
| 134 })); |
| 135 } |
| 108 } | 136 } |
| 109 | 137 |
| 110 | 138 |
| 139 class _MyHasToJsonObject implements HasToJson { |
| 140 int offset; |
| 141 _MyHasToJsonObject(this.offset); |
| 142 Map<String, Object> toJson() => {'offset': offset}; |
| 143 } |
| 144 |
| 145 |
| 111 @ReflectiveTestCase() | 146 @ReflectiveTestCase() |
| 112 class RequestDatumTest { | 147 class RequestDatumTest { |
| 113 static Matcher isRequestDatum = new isInstanceOf<RequestDatum>( | 148 static Matcher isRequestDatum = new isInstanceOf<RequestDatum>( |
| 114 "RequestDatum"); | 149 "RequestDatum"); |
| 115 | 150 |
| 116 static Request request; | 151 static Request request; |
| 117 static Matcher _throwsInvalidParameter = throwsA( | 152 static Matcher _throwsInvalidParameter = throwsA( |
| 118 new InvalidParameterResponseMatcher()); | 153 new InvalidParameterResponseMatcher()); |
| 119 | 154 |
| 120 void setUp() { | 155 void setUp() { |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 response.setResult(resultName, resultValue); | 704 response.setResult(resultName, resultValue); |
| 670 expect(response.getResult(resultName), same(resultValue)); | 705 expect(response.getResult(resultName), same(resultValue)); |
| 671 expect(response.toJson(), equals({ | 706 expect(response.toJson(), equals({ |
| 672 Response.ID: '0', | 707 Response.ID: '0', |
| 673 Response.RESULT: { | 708 Response.RESULT: { |
| 674 resultName: resultValue | 709 resultName: resultValue |
| 675 } | 710 } |
| 676 })); | 711 })); |
| 677 } | 712 } |
| 678 } | 713 } |
| OLD | NEW |