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

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

Issue 703963002: Use Element's source paths instead of URIs as a key in the index. (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 '../../../abstract_single_unit.dart'; 9 import '../../../abstract_single_unit.dart';
10 import '../../../mocks.dart'; 10 import '../../../mocks.dart';
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 void test_field() { 100 void test_field() {
101 resolveTestUnit(''' 101 resolveTestUnit('''
102 class A { 102 class A {
103 int field; 103 int field;
104 } 104 }
105 '''); 105 ''');
106 FieldElement field = findElement('field', ElementKind.FIELD); 106 FieldElement field = findElement('field', ElementKind.FIELD);
107 PropertyAccessorElement getter = field.getter; 107 PropertyAccessorElement getter = field.getter;
108 PropertyAccessorElement setter = field.setter; 108 PropertyAccessorElement setter = field.setter;
109 { 109 {
110 int id = codec.encode(getter); 110 int id = codec.encode(getter, false);
111 expect(codec.decode(context, id), getter); 111 expect(codec.decode(context, id), getter);
112 } 112 }
113 { 113 {
114 int id = codec.encode(setter); 114 int id = codec.encode(setter, false);
115 expect(codec.decode(context, id), setter); 115 expect(codec.decode(context, id), setter);
116 } 116 }
117 { 117 {
118 int id = codec.encode(field); 118 int id = codec.encode(field, false);
119 expect(codec.decode(context, id), field); 119 expect(codec.decode(context, id), field);
120 } 120 }
121 } 121 }
122 122
123 void test_localLocalVariable() { 123 void test_localLocalVariable() {
124 resolveTestUnit(''' 124 resolveTestUnit('''
125 main() { 125 main() {
126 { 126 {
127 foo() { 127 foo() {
128 int bar; // A 128 int bar; // A
129 } 129 }
130 } 130 }
131 { 131 {
132 foo() { 132 foo() {
133 int bar; // B 133 int bar; // B
134 } 134 }
135 } 135 }
136 } 136 }
137 '''); 137 ''');
138 { 138 {
139 LocalVariableElement element = findNodeElementAtString('bar; // A', null); 139 LocalVariableElement element = findNodeElementAtString('bar; // A', null);
140 int id = codec.encode(element); 140 int id = codec.encode(element, false);
141 expect(codec.decode(context, id), element); 141 expect(codec.decode(context, id), element);
142 } 142 }
143 { 143 {
144 LocalVariableElement element = findNodeElementAtString('bar; // B', null); 144 LocalVariableElement element = findNodeElementAtString('bar; // B', null);
145 int id = codec.encode(element); 145 int id = codec.encode(element, false);
146 expect(codec.decode(context, id), element); 146 expect(codec.decode(context, id), element);
147 } 147 }
148 // check strings, "foo" as a single string, no "foo@17" or "bar@35" 148 // check strings, "foo" as a single string, no "foo@17" or "bar@35"
149 expect(stringCodec.nameToIndex, hasLength(4)); 149 expect(stringCodec.nameToIndex, hasLength(4));
150 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 150 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
151 expect(stringCodec.nameToIndex, containsPair('main', 1)); 151 expect(stringCodec.nameToIndex, containsPair('main', 1));
152 expect(stringCodec.nameToIndex, containsPair('foo', 2)); 152 expect(stringCodec.nameToIndex, containsPair('foo', 2));
153 expect(stringCodec.nameToIndex, containsPair('bar', 3)); 153 expect(stringCodec.nameToIndex, containsPair('bar', 3));
154 } 154 }
155 155
156 void test_localVariable() { 156 void test_localVariable() {
157 resolveTestUnit(''' 157 resolveTestUnit('''
158 main() { 158 main() {
159 { 159 {
160 int foo; // A 160 int foo; // A
161 } 161 }
162 { 162 {
163 int foo; // B 163 int foo; // B
164 } 164 }
165 } 165 }
166 '''); 166 ''');
167 { 167 {
168 LocalVariableElement element = findNodeElementAtString('foo; // A', null); 168 LocalVariableElement element = findNodeElementAtString('foo; // A', null);
169 int id = codec.encode(element); 169 int id = codec.encode(element, false);
170 expect(codec.decode(context, id), element); 170 expect(codec.decode(context, id), element);
171 } 171 }
172 { 172 {
173 LocalVariableElement element = findNodeElementAtString('foo; // B', null); 173 LocalVariableElement element = findNodeElementAtString('foo; // B', null);
174 int id = codec.encode(element); 174 int id = codec.encode(element, false);
175 expect(codec.decode(context, id), element); 175 expect(codec.decode(context, id), element);
176 } 176 }
177 // check strings, "foo" as a single string, no "foo@21" or "foo@47" 177 // check strings, "foo" as a single string, no "foo@21" or "foo@47"
178 expect(stringCodec.nameToIndex, hasLength(3)); 178 expect(stringCodec.nameToIndex, hasLength(3));
179 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 179 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
180 expect(stringCodec.nameToIndex, containsPair('main', 1)); 180 expect(stringCodec.nameToIndex, containsPair('main', 1));
181 expect(stringCodec.nameToIndex, containsPair('foo', 2)); 181 expect(stringCodec.nameToIndex, containsPair('foo', 2));
182 } 182 }
183 183
184 void test_notLocal() { 184 void test_notLocal() {
185 resolveTestUnit(''' 185 resolveTestUnit('''
186 main() { 186 main() {
187 int foo; 187 int foo;
188 } 188 }
189 '''); 189 ''');
190 LocalVariableElement element = findElement('foo'); 190 LocalVariableElement element = findElement('foo');
191 int id = codec.encode(element); 191 int id = codec.encode(element, false);
192 expect(codec.encode(element), id); 192 expect(codec.encode(element, false), id);
193 expect(codec.decode(context, id), element); 193 expect(codec.decode(context, id), element);
194 // check strings 194 // check strings
195 expect(stringCodec.nameToIndex, hasLength(3)); 195 expect(stringCodec.nameToIndex, hasLength(3));
196 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0)); 196 expect(stringCodec.nameToIndex, containsPair('file:///test.dart', 0));
197 expect(stringCodec.nameToIndex, containsPair('main', 1)); 197 expect(stringCodec.nameToIndex, containsPair('main', 1));
198 expect(stringCodec.nameToIndex, containsPair('foo', 2)); 198 expect(stringCodec.nameToIndex, containsPair('foo', 2));
199 } 199 }
200 } 200 }
201 201
202 202
(...skipping 18 matching lines...) Expand all
221 class _StringCodecTest { 221 class _StringCodecTest {
222 StringCodec codec = new StringCodec(); 222 StringCodec codec = new StringCodec();
223 223
224 void test_all() { 224 void test_all() {
225 int idA = codec.encode('aaa'); 225 int idA = codec.encode('aaa');
226 int idB = codec.encode('bbb'); 226 int idB = codec.encode('bbb');
227 expect(codec.decode(idA), 'aaa'); 227 expect(codec.decode(idA), 'aaa');
228 expect(codec.decode(idB), 'bbb'); 228 expect(codec.decode(idB), 'bbb');
229 } 229 }
230 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698