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

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

Issue 738673002: Use shorter DartElementLocation. (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);
22 runReflectiveTests(_RelationshipCodecTest); 23 runReflectiveTests(_RelationshipCodecTest);
23 runReflectiveTests(_StringCodecTest); 24 runReflectiveTests(_StringCodecTest);
24 } 25 }
25 26
26 27
27 @ReflectiveTestCase() 28 @ReflectiveTestCase()
28 class _ContextCodecTest { 29 class _ContextCodecTest {
29 ContextCodec codec = new ContextCodec(); 30 ContextCodec codec = new ContextCodec();
30 31
31 void test_encode_decode() { 32 void test_encode_decode() {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 { 140 {
140 LocalVariableElement element = findNodeElementAtString('bar; // A', null); 141 LocalVariableElement element = findNodeElementAtString('bar; // A', null);
141 int id = codec.encode(element, false); 142 int id = codec.encode(element, false);
142 expect(codec.decode(context, id), element); 143 expect(codec.decode(context, id), element);
143 } 144 }
144 { 145 {
145 LocalVariableElement element = findNodeElementAtString('bar; // B', null); 146 LocalVariableElement element = findNodeElementAtString('bar; // B', null);
146 int id = codec.encode(element, false); 147 int id = codec.encode(element, false);
147 expect(codec.decode(context, id), element); 148 expect(codec.decode(context, id), element);
148 } 149 }
149 // check strings, "foo" as a single string, no "foo@17" or "bar@35" 150 // check strings, only source encoding
150 expect(stringCodec.nameToIndex, hasLength(4)); 151 expect(stringCodec.nameToIndex, hasLength(1));
151 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 152 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));
155 } 153 }
156 154
157 void test_localVariable() { 155 void test_localVariable() {
158 resolveTestUnit(''' 156 resolveTestUnit('''
159 main() { 157 main() {
160 { 158 {
161 int foo; // A 159 int foo; // A
162 } 160 }
163 { 161 {
164 int foo; // B 162 int foo; // B
165 } 163 }
166 } 164 }
167 '''); 165 ''');
168 { 166 {
169 LocalVariableElement element = findNodeElementAtString('foo; // A', null); 167 LocalVariableElement element = findNodeElementAtString('foo; // A', null);
170 int id = codec.encode(element, false); 168 int id = codec.encode(element, false);
171 expect(codec.decode(context, id), element); 169 expect(codec.decode(context, id), element);
172 } 170 }
173 { 171 {
174 LocalVariableElement element = findNodeElementAtString('foo; // B', null); 172 LocalVariableElement element = findNodeElementAtString('foo; // B', null);
175 int id = codec.encode(element, false); 173 int id = codec.encode(element, false);
176 expect(codec.decode(context, id), element); 174 expect(codec.decode(context, id), element);
177 } 175 }
178 // check strings, "foo" as a single string, no "foo@21" or "foo@47" 176 // check strings, only source encoding
179 expect(stringCodec.nameToIndex, hasLength(3)); 177 expect(stringCodec.nameToIndex, hasLength(1));
180 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 178 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
181 expect(stringCodec.nameToIndex, containsPair('main', 1));
182 expect(stringCodec.nameToIndex, containsPair('foo', 2));
183 } 179 }
184 180
185 void test_notLocal() { 181 void test_notLocal() {
186 resolveTestUnit(''' 182 resolveTestUnit('''
187 main() { 183 main() {
188 int foo; 184 int foo;
189 } 185 }
190 '''); 186 ''');
191 LocalVariableElement element = findElement('foo'); 187 LocalVariableElement element = findElement('foo');
192 int id = codec.encode(element, false); 188 int id = codec.encode(element, false);
193 expect(codec.encode(element, false), id); 189 expect(codec.encode(element, false), id);
194 expect(codec.decode(context, id), element); 190 expect(codec.decode(context, id), element);
195 // check strings 191 // check strings
196 expect(stringCodec.nameToIndex, hasLength(3)); 192 expect(stringCodec.nameToIndex, hasLength(1));
197 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 193 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
198 expect(stringCodec.nameToIndex, containsPair('main', 1));
199 expect(stringCodec.nameToIndex, containsPair('foo', 2));
200 } 194 }
201 } 195 }
202 196
197
198 @ReflectiveTestCase()
199 class _ElementKindCodecTest {
200 ElementKindCodec codec = new ElementKindCodec();
201
202 void test_decode_unknown() {
203 expect(codec.decode(1 << 20), isNull);
204 }
205
206 void test_encodeDecode() {
207 int idClass = codec.encode(ElementKind.CLASS);
208 int idMethod = codec.encode(ElementKind.METHOD);
209 expect(idClass, isNot(idMethod));
210 }
211 }
212
203 213
204 @ReflectiveTestCase() 214 @ReflectiveTestCase()
205 class _RelationshipCodecTest { 215 class _RelationshipCodecTest {
206 StringCodec stringCodec = new StringCodec(); 216 StringCodec stringCodec = new StringCodec();
207 RelationshipCodec codec; 217 RelationshipCodec codec;
208 218
209 void setUp() { 219 void setUp() {
210 codec = new RelationshipCodec(stringCodec); 220 codec = new RelationshipCodec(stringCodec);
211 } 221 }
212 222
213 void test_all() { 223 void test_all() {
214 Relationship relationship = Relationship.getRelationship('my-relationship'); 224 Relationship relationship = Relationship.getRelationship('my-relationship');
215 int id = codec.encode(relationship); 225 int id = codec.encode(relationship);
216 expect(codec.decode(id), relationship); 226 expect(codec.decode(id), relationship);
217 } 227 }
218 } 228 }
219 229
220 230
221 @ReflectiveTestCase() 231 @ReflectiveTestCase()
222 class _StringCodecTest { 232 class _StringCodecTest {
223 StringCodec codec = new StringCodec(); 233 StringCodec codec = new StringCodec();
224 234
225 void test_all() { 235 void test_all() {
226 int idA = codec.encode('aaa'); 236 int idA = codec.encode('aaa');
227 int idB = codec.encode('bbb'); 237 int idB = codec.encode('bbb');
228 expect(codec.decode(idA), 'aaa'); 238 expect(codec.decode(idA), 'aaa');
229 expect(codec.decode(idB), 'bbb'); 239 expect(codec.decode(idB), 'bbb');
230 } 240 }
231 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698