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.services.src.index.store.codec; | 5 library test.services.src.index.store.codec; |
6 | 6 |
7 import 'package:analysis_services/index/index.dart'; | 7 import 'package:analysis_services/index/index.dart'; |
8 import 'package:analysis_services/src/index/store/codec.dart'; | 8 import 'package:analysis_services/src/index/store/codec.dart'; |
9 import 'package:analysis_testing/abstract_single_unit.dart'; | 9 import 'package:analysis_testing/abstract_single_unit.dart'; |
10 import 'package:analysis_testing/mocks.dart'; | 10 import 'package:analysis_testing/mocks.dart'; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 int id = codec.encode(element); | 140 int id = codec.encode(element); |
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); |
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('f/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); |
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); |
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('f/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); |
192 expect(codec.encode(element), id); | 192 expect(codec.encode(element), 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('f/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 |
203 @ReflectiveTestCase() | 203 @ReflectiveTestCase() |
204 class _RelationshipCodecTest { | 204 class _RelationshipCodecTest { |
205 StringCodec stringCodec = new StringCodec(); | 205 StringCodec stringCodec = new StringCodec(); |
206 RelationshipCodec codec; | 206 RelationshipCodec codec; |
(...skipping 14 matching lines...) Expand all Loading... |
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 } |
OLD | NEW |