Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: pkg/analysis_server/test/services/index/store/codec_test.dart

Issue 736603005: Rollback r41807. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.services.src.index.store.codec; 5 library test.services.src.index.store.codec;
6 6
7 import 'package:analysis_server/src/services/index/index.dart'; 7 import 'package:analysis_server/src/services/index/index.dart';
8 import 'package:analysis_server/src/services/index/store/codec.dart'; 8 import 'package:analysis_server/src/services/index/store/codec.dart';
9 import 'package:analyzer/src/generated/element.dart'; 9 import 'package:analyzer/src/generated/element.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
12 12
13 import '../../../abstract_single_unit.dart'; 13 import '../../../abstract_single_unit.dart';
14 import '../../../mocks.dart'; 14 import '../../../mocks.dart';
15 import '../../../reflective_tests.dart'; 15 import '../../../reflective_tests.dart';
16 16
17 17
18 main() { 18 main() {
19 groupSep = ' | '; 19 groupSep = ' | ';
20 runReflectiveTests(_ContextCodecTest); 20 runReflectiveTests(_ContextCodecTest);
21 runReflectiveTests(_ElementCodecTest); 21 runReflectiveTests(_ElementCodecTest);
22 runReflectiveTests(_ElementKindCodecTest);
23 runReflectiveTests(_RelationshipCodecTest); 22 runReflectiveTests(_RelationshipCodecTest);
24 runReflectiveTests(_StringCodecTest); 23 runReflectiveTests(_StringCodecTest);
25 } 24 }
26 25
27 26
28 @ReflectiveTestCase() 27 @ReflectiveTestCase()
29 class _ContextCodecTest { 28 class _ContextCodecTest {
30 ContextCodec codec = new ContextCodec(); 29 ContextCodec codec = new ContextCodec();
31 30
32 void test_encode_decode() { 31 void test_encode_decode() {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 { 139 {
141 LocalVariableElement element = findNodeElementAtString('bar; // A', null); 140 LocalVariableElement element = findNodeElementAtString('bar; // A', null);
142 int id = codec.encode(element, false); 141 int id = codec.encode(element, false);
143 expect(codec.decode(context, id), element); 142 expect(codec.decode(context, id), element);
144 } 143 }
145 { 144 {
146 LocalVariableElement element = findNodeElementAtString('bar; // B', null); 145 LocalVariableElement element = findNodeElementAtString('bar; // B', null);
147 int id = codec.encode(element, false); 146 int id = codec.encode(element, false);
148 expect(codec.decode(context, id), element); 147 expect(codec.decode(context, id), element);
149 } 148 }
150 // check strings, only source encoding 149 // check strings, "foo" as a single string, no "foo@17" or "bar@35"
151 expect(stringCodec.nameToIndex, hasLength(1)); 150 expect(stringCodec.nameToIndex, hasLength(4));
152 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 151 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
152 expect(stringCodec.nameToIndex, containsPair('main', 1));
153 expect(stringCodec.nameToIndex, containsPair('foo', 2));
154 expect(stringCodec.nameToIndex, containsPair('bar', 3));
153 } 155 }
154 156
155 void test_localVariable() { 157 void test_localVariable() {
156 resolveTestUnit(''' 158 resolveTestUnit('''
157 main() { 159 main() {
158 { 160 {
159 int foo; // A 161 int foo; // A
160 } 162 }
161 { 163 {
162 int foo; // B 164 int foo; // B
163 } 165 }
164 } 166 }
165 '''); 167 ''');
166 { 168 {
167 LocalVariableElement element = findNodeElementAtString('foo; // A', null); 169 LocalVariableElement element = findNodeElementAtString('foo; // A', null);
168 int id = codec.encode(element, false); 170 int id = codec.encode(element, false);
169 expect(codec.decode(context, id), element); 171 expect(codec.decode(context, id), element);
170 } 172 }
171 { 173 {
172 LocalVariableElement element = findNodeElementAtString('foo; // B', null); 174 LocalVariableElement element = findNodeElementAtString('foo; // B', null);
173 int id = codec.encode(element, false); 175 int id = codec.encode(element, false);
174 expect(codec.decode(context, id), element); 176 expect(codec.decode(context, id), element);
175 } 177 }
176 // check strings, only source encoding 178 // check strings, "foo" as a single string, no "foo@21" or "foo@47"
177 expect(stringCodec.nameToIndex, hasLength(1)); 179 expect(stringCodec.nameToIndex, hasLength(3));
178 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 180 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
179 } 181 expect(stringCodec.nameToIndex, containsPair('main', 1));
180 182 expect(stringCodec.nameToIndex, containsPair('foo', 2));
181 void test_name() {
182 Element element = new NameElement('myName');
183 int id = codec.encode(element, false);
184 // we don't need decoding - it is never used as a location
185 expect(codec.decode(null, id), null);
186 } 183 }
187 184
188 void test_notLocal() { 185 void test_notLocal() {
189 resolveTestUnit(''' 186 resolveTestUnit('''
190 main() { 187 main() {
191 int foo; 188 int foo;
192 } 189 }
193 '''); 190 ''');
194 LocalVariableElement element = findElement('foo'); 191 LocalVariableElement element = findElement('foo');
195 int id = codec.encode(element, false); 192 int id = codec.encode(element, false);
196 expect(codec.encode(element, false), id); 193 expect(codec.encode(element, false), id);
197 expect(codec.decode(context, id), element); 194 expect(codec.decode(context, id), element);
198 // check strings 195 // check strings
199 expect(stringCodec.nameToIndex, hasLength(1)); 196 expect(stringCodec.nameToIndex, hasLength(3));
200 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 197 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
198 expect(stringCodec.nameToIndex, containsPair('main', 1));
199 expect(stringCodec.nameToIndex, containsPair('foo', 2));
201 } 200 }
202 } 201 }
203 202
204
205 @ReflectiveTestCase()
206 class _ElementKindCodecTest {
207 ElementKindCodec codec = new ElementKindCodec();
208
209 void test_decode_unknown() {
210 expect(codec.decode(1 << 20), isNull);
211 }
212
213 void test_encodeDecode() {
214 int idClass = codec.encode(ElementKind.CLASS);
215 int idMethod = codec.encode(ElementKind.METHOD);
216 expect(idClass, isNot(idMethod));
217 }
218 }
219
220 203
221 @ReflectiveTestCase() 204 @ReflectiveTestCase()
222 class _RelationshipCodecTest { 205 class _RelationshipCodecTest {
223 StringCodec stringCodec = new StringCodec(); 206 StringCodec stringCodec = new StringCodec();
224 RelationshipCodec codec; 207 RelationshipCodec codec;
225 208
226 void setUp() { 209 void setUp() {
227 codec = new RelationshipCodec(stringCodec); 210 codec = new RelationshipCodec(stringCodec);
228 } 211 }
229 212
230 void test_all() { 213 void test_all() {
231 Relationship relationship = Relationship.getRelationship('my-relationship'); 214 Relationship relationship = Relationship.getRelationship('my-relationship');
232 int id = codec.encode(relationship); 215 int id = codec.encode(relationship);
233 expect(codec.decode(id), relationship); 216 expect(codec.decode(id), relationship);
234 } 217 }
235 } 218 }
236 219
237 220
238 @ReflectiveTestCase() 221 @ReflectiveTestCase()
239 class _StringCodecTest { 222 class _StringCodecTest {
240 StringCodec codec = new StringCodec(); 223 StringCodec codec = new StringCodec();
241 224
242 void test_all() { 225 void test_all() {
243 int idA = codec.encode('aaa'); 226 int idA = codec.encode('aaa');
244 int idB = codec.encode('bbb'); 227 int idB = codec.encode('bbb');
245 expect(codec.decode(idA), 'aaa'); 228 expect(codec.decode(idA), 'aaa');
246 expect(codec.decode(idB), 'bbb'); 229 expect(codec.decode(idB), 'bbb');
247 } 230 }
248 } 231 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698