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

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

Issue 351453004: Move split_store.dart to the store/ folder and extract collections/codecs. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months 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.index.split.store; 5 library test.index.split.store;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analysis_server/src/index/split_store.dart'; 10 import 'package:analysis_server/src/index/store/codec.dart';
11 import 'package:analysis_server/src/index/store/split_store.dart';
11 import 'package:analyzer/src/generated/element.dart'; 12 import 'package:analyzer/src/generated/element.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/index.dart'; 14 import 'package:analyzer/src/generated/index.dart';
14 import 'package:analyzer/src/generated/source.dart'; 15 import 'package:analyzer/src/generated/source.dart';
15 import 'package:typed_mock/typed_mock.dart'; 16 import 'package:typed_mock/typed_mock.dart';
16 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
17 18
18 import '../reflective_tests.dart'; 19 import '../../reflective_tests.dart';
20 import 'typed_mocks.dart';
19 21
20 22
21 main() { 23 main() {
22 groupSep = ' | '; 24 groupSep = ' | ';
23 group('ContextCodec', () {
24 runReflectiveTests(_ContextCodecTest);
25 });
26 group('ElementCodec', () {
27 runReflectiveTests(_ElementCodecTest);
28 });
29 group('FileNodeManager', () { 25 group('FileNodeManager', () {
30 runReflectiveTests(_FileNodeManagerTest); 26 runReflectiveTests(_FileNodeManagerTest);
31 }); 27 });
32 group('IndexNode', () { 28 group('IndexNode', () {
33 runReflectiveTests(_IndexNodeTest); 29 runReflectiveTests(_IndexNodeTest);
34 }); 30 });
35 group('IntToIntSetMap', () {
36 runReflectiveTests(_IntToIntSetMapTest);
37 });
38 group('LocationData', () { 31 group('LocationData', () {
39 runReflectiveTests(_LocationDataTest); 32 runReflectiveTests(_LocationDataTest);
40 }); 33 });
41 group('RelationKeyData', () { 34 group('RelationKeyData', () {
42 runReflectiveTests(_RelationKeyDataTest); 35 runReflectiveTests(_RelationKeyDataTest);
43 }); 36 });
44 group('RelationshipCodec', () {
45 runReflectiveTests(_RelationshipCodecTest);
46 });
47 group('SplitIndexStore', () { 37 group('SplitIndexStore', () {
48 runReflectiveTests(_SplitIndexStoreTest); 38 runReflectiveTests(_SplitIndexStoreTest);
49 }); 39 });
50 group('StringCodec', () {
51 runReflectiveTests(_StringCodecTest);
52 });
53 } 40 }
54 41
55 42
56 void _assertHasLocation(List<Location> locations, Element element, int offset, 43 void _assertHasLocation(List<Location> locations, Element element, int offset,
57 int length) { 44 int length) {
58 for (Location location in locations) { 45 for (Location location in locations) {
59 if ((element == null || location.element == element) && location.offset == 46 if ((element == null || location.element == element) && location.offset ==
60 offset && location.length == length) { 47 offset && location.length == length) {
61 return; 48 return;
62 } 49 }
63 } 50 }
64 fail('Expected to find Location' 51 fail('Expected to find Location'
65 '(element=$element, offset=$offset, length=$length)'); 52 '(element=$element, offset=$offset, length=$length)');
66 } 53 }
67 54
68 55
69 @ReflectiveTestCase() 56 @ReflectiveTestCase()
70 class _ContextCodecTest {
71 ContextCodec codec = new ContextCodec();
72
73 void test_encode_decode() {
74 AnalysisContext contextA = new _MockAnalysisContext('contextA');
75 AnalysisContext contextB = new _MockAnalysisContext('contextB');
76 int idA = codec.encode(contextA);
77 int idB = codec.encode(contextB);
78 expect(idA, codec.encode(contextA));
79 expect(idB, codec.encode(contextB));
80 expect(codec.decode(idA), contextA);
81 expect(codec.decode(idB), contextB);
82 }
83
84 void test_remove() {
85 // encode
86 {
87 AnalysisContext context = new _MockAnalysisContext('context');
88 // encode
89 int id = codec.encode(context);
90 expect(id, 0);
91 expect(codec.decode(id), context);
92 // remove
93 codec.remove(context);
94 expect(codec.decode(id), isNull);
95 }
96 // encode again
97 {
98 AnalysisContext context = new _MockAnalysisContext('context');
99 // encode
100 int id = codec.encode(context);
101 expect(id, 1);
102 expect(codec.decode(id), context);
103 }
104 }
105 }
106
107
108 @ReflectiveTestCase()
109 class _ElementCodecTest {
110 ElementCodec codec;
111 AnalysisContext context = new _MockAnalysisContext('context');
112 StringCodec stringCodec = new StringCodec();
113
114 void setUp() {
115 codec = new ElementCodec(stringCodec);
116 }
117
118 void test_localLocalVariable() {
119 {
120 Element element = new _MockElement();
121 ElementLocation location = new ElementLocationImpl.con3(['main', 'foo@1',
122 'bar@2']);
123 when(context.getElement(location)).thenReturn(element);
124 when(element.location).thenReturn(location);
125 int id = codec.encode(element);
126 expect(codec.decode(context, id), element);
127 }
128 {
129 Element element = new _MockElement();
130 ElementLocation location = new ElementLocationImpl.con3(['main', 'foo@10',
131 'bar@20']);
132 when(context.getElement(location)).thenReturn(element);
133 when(element.location).thenReturn(location);
134 int id = codec.encode(element);
135 expect(codec.decode(context, id), element);
136 }
137 // check strings, "foo" as a single string, no "foo@1" or "foo@10"
138 expect(stringCodec.nameToIndex, hasLength(3));
139 expect(stringCodec.nameToIndex, containsPair('main', 0));
140 expect(stringCodec.nameToIndex, containsPair('foo', 1));
141 expect(stringCodec.nameToIndex, containsPair('bar', 2));
142 }
143
144 void test_localVariable() {
145 {
146 Element element = new _MockElement();
147 ElementLocation location = new ElementLocationImpl.con3(['main',
148 'foo@42']);
149 when(context.getElement(location)).thenReturn(element);
150 when(element.location).thenReturn(location);
151 int id = codec.encode(element);
152 expect(codec.decode(context, id), element);
153 }
154 {
155 Element element = new _MockElement();
156 ElementLocation location = new ElementLocationImpl.con3(['main',
157 'foo@4200']);
158 when(context.getElement(location)).thenReturn(element);
159 when(element.location).thenReturn(location);
160 int id = codec.encode(element);
161 expect(codec.decode(context, id), element);
162 }
163 // check strings, "foo" as a single string, no "foo@42" or "foo@4200"
164 expect(stringCodec.nameToIndex, hasLength(2));
165 expect(stringCodec.nameToIndex, containsPair('main', 0));
166 expect(stringCodec.nameToIndex, containsPair('foo', 1));
167 }
168
169 void test_notLocal() {
170 Element element = new _MockElement();
171 ElementLocation location = new ElementLocationImpl.con3(['foo', 'bar']);
172 when(element.location).thenReturn(location);
173 when(context.getElement(location)).thenReturn(element);
174 int id = codec.encode(element);
175 expect(codec.encode(element), id);
176 expect(codec.decode(context, id), element);
177 // check strings
178 expect(stringCodec.nameToIndex, hasLength(2));
179 expect(stringCodec.nameToIndex, containsPair('foo', 0));
180 expect(stringCodec.nameToIndex, containsPair('bar', 1));
181 }
182 }
183
184
185 @ReflectiveTestCase()
186 class _FileNodeManagerTest { 57 class _FileNodeManagerTest {
187 AnalysisContext context = new _MockAnalysisContext('context'); 58 AnalysisContext context = new MockAnalysisContext('context');
188 ContextCodec contextCodec = new _MockContextCodec(); 59 ContextCodec contextCodec = new MockContextCodec();
189 int contextId = 13; 60 int contextId = 13;
190 ElementCodec elementCodec = new _MockElementCodec(); 61 ElementCodec elementCodec = new MockElementCodec();
191 FileManager fileManager = new _MockFileManager(); 62 FileManager fileManager = new _MockFileManager();
192 _MockLogger logger = new _MockLogger(); 63 MockLogger logger = new MockLogger();
193 int nextElementId = 0; 64 int nextElementId = 0;
194 FileNodeManager nodeManager; 65 FileNodeManager nodeManager;
195 RelationshipCodec relationshipCodec; 66 RelationshipCodec relationshipCodec;
196 StringCodec stringCodec = new StringCodec(); 67 StringCodec stringCodec = new StringCodec();
197 68
198 void setUp() { 69 void setUp() {
199 relationshipCodec = new RelationshipCodec(stringCodec); 70 relationshipCodec = new RelationshipCodec(stringCodec);
200 nodeManager = new FileNodeManager(fileManager, logger, stringCodec, 71 nodeManager = new FileNodeManager(fileManager, logger, stringCodec,
201 contextCodec, elementCodec, relationshipCodec); 72 contextCodec, elementCodec, relationshipCodec);
202 when(contextCodec.encode(context)).thenReturn(contextId); 73 when(contextCodec.encode(context)).thenReturn(contextId);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 229 }
359 230
360 void test_removeNode() { 231 void test_removeNode() {
361 String name = '42.index'; 232 String name = '42.index';
362 nodeManager.removeNode(name); 233 nodeManager.removeNode(name);
363 verify(fileManager.delete(name)).once(); 234 verify(fileManager.delete(name)).once();
364 } 235 }
365 236
366 Element _mockElement() { 237 Element _mockElement() {
367 int elementId = nextElementId++; 238 int elementId = nextElementId++;
368 Element element = new _MockElement(); 239 Element element = new MockElement();
369 when(elementCodec.encode(element)).thenReturn(elementId); 240 when(elementCodec.encode(element)).thenReturn(elementId);
370 when(elementCodec.decode(context, elementId)).thenReturn(element); 241 when(elementCodec.decode(context, elementId)).thenReturn(element);
371 return element; 242 return element;
372 } 243 }
373 } 244 }
374 245
375 246
376 @ReflectiveTestCase() 247 @ReflectiveTestCase()
377 class _IndexNodeTest { 248 class _IndexNodeTest {
378 AnalysisContext context = new _MockAnalysisContext('context'); 249 AnalysisContext context = new MockAnalysisContext('context');
379 ElementCodec elementCodec = new _MockElementCodec(); 250 ElementCodec elementCodec = new MockElementCodec();
380 int nextElementId = 0; 251 int nextElementId = 0;
381 IndexNode node; 252 IndexNode node;
382 RelationshipCodec relationshipCodec; 253 RelationshipCodec relationshipCodec;
383 StringCodec stringCodec = new StringCodec(); 254 StringCodec stringCodec = new StringCodec();
384 255
385 void setUp() { 256 void setUp() {
386 relationshipCodec = new RelationshipCodec(stringCodec); 257 relationshipCodec = new RelationshipCodec(stringCodec);
387 node = new IndexNode(context, elementCodec, relationshipCodec); 258 node = new IndexNode(context, elementCodec, relationshipCodec);
388 } 259 }
389 260
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 314 }
444 // request 315 // request
445 List<Location> locations = node.getRelationships(elementA, relationship); 316 List<Location> locations = node.getRelationships(elementA, relationship);
446 expect(locations, hasLength(2)); 317 expect(locations, hasLength(2));
447 _assertHasLocation(locations, elementB, 1, 10); 318 _assertHasLocation(locations, elementB, 1, 10);
448 _assertHasLocation(locations, elementC, 2, 20); 319 _assertHasLocation(locations, elementC, 2, 20);
449 } 320 }
450 321
451 Element _mockElement() { 322 Element _mockElement() {
452 int elementId = nextElementId++; 323 int elementId = nextElementId++;
453 Element element = new _MockElement(); 324 Element element = new MockElement();
454 when(elementCodec.encode(element)).thenReturn(elementId); 325 when(elementCodec.encode(element)).thenReturn(elementId);
455 when(elementCodec.decode(context, elementId)).thenReturn(element); 326 when(elementCodec.decode(context, elementId)).thenReturn(element);
456 return element; 327 return element;
457 } 328 }
458 } 329 }
459 330
460 331
461 @ReflectiveTestCase() 332 @ReflectiveTestCase()
462 class _IntToIntSetMapTest {
463 IntToIntSetMap map = new IntToIntSetMap(32, 0.75);
464
465 void test_clear() {
466 map.add(1, 10);
467 map.add(2, 20);
468 expect(map.length, 2);
469 map.clear();
470 expect(map.length, 0);
471 }
472
473 void test_get() {
474 map.add(1, 10);
475 map.add(1, 11);
476 map.add(1, 12);
477 map.add(2, 20);
478 map.add(2, 21);
479 expect(map.get(1), unorderedEquals([10, 11, 12]));
480 expect(map.get(2), unorderedEquals([20, 21]));
481 }
482
483 void test_get_no() {
484 expect(map.get(3), []);
485 }
486
487 void test_length() {
488 expect(map.length, 0);
489 map.add(1, 10);
490 expect(map.length, 1);
491 map.add(1, 11);
492 expect(map.length, 2);
493 map.add(1, 12);
494 expect(map.length, 3);
495 map.add(2, 20);
496 expect(map.length, 4);
497 map.add(2, 21);
498 expect(map.length, 5);
499 }
500 }
501
502
503 @ReflectiveTestCase()
504 class _LocationDataTest { 333 class _LocationDataTest {
505 AnalysisContext context = new _MockAnalysisContext('context'); 334 AnalysisContext context = new MockAnalysisContext('context');
506 ElementCodec elementCodec = new _MockElementCodec(); 335 ElementCodec elementCodec = new MockElementCodec();
507 StringCodec stringCodec = new StringCodec(); 336 StringCodec stringCodec = new StringCodec();
508 337
509 void test_newForData() { 338 void test_newForData() {
510 Element element = new _MockElement(); 339 Element element = new MockElement();
511 when(elementCodec.decode(context, 0)).thenReturn(element); 340 when(elementCodec.decode(context, 0)).thenReturn(element);
512 LocationData locationData = new LocationData.forData(0, 1, 2); 341 LocationData locationData = new LocationData.forData(0, 1, 2);
513 Location location = locationData.getLocation(context, elementCodec); 342 Location location = locationData.getLocation(context, elementCodec);
514 expect(location.element, element); 343 expect(location.element, element);
515 expect(location.offset, 1); 344 expect(location.offset, 1);
516 expect(location.length, 2); 345 expect(location.length, 2);
517 } 346 }
518 347
519 void test_newForObject() { 348 void test_newForObject() {
520 // prepare Element 349 // prepare Element
521 Element element = new _MockElement(); 350 Element element = new MockElement();
522 when(elementCodec.encode(element)).thenReturn(42); 351 when(elementCodec.encode(element)).thenReturn(42);
523 when(elementCodec.decode(context, 42)).thenReturn(element); 352 when(elementCodec.decode(context, 42)).thenReturn(element);
524 // create 353 // create
525 Location location = new Location(element, 1, 2); 354 Location location = new Location(element, 1, 2);
526 LocationData locationData = new LocationData.forObject(elementCodec, 355 LocationData locationData = new LocationData.forObject(elementCodec,
527 location); 356 location);
528 // touch 'hashCode' 357 // touch 'hashCode'
529 locationData.hashCode; 358 locationData.hashCode;
530 // == 359 // ==
531 expect(locationData == new LocationData.forData(42, 1, 2), isTrue); 360 expect(locationData == new LocationData.forData(42, 1, 2), isTrue);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 return false; 399 return false;
571 } 400 }
572 } 401 }
573 402
574 403
575 class _MemoryNodeManager implements NodeManager { 404 class _MemoryNodeManager implements NodeManager {
576 ContextCodec _contextCodec = new ContextCodec(); 405 ContextCodec _contextCodec = new ContextCodec();
577 ElementCodec _elementCodec; 406 ElementCodec _elementCodec;
578 int _locationCount = 0; 407 int _locationCount = 0;
579 final Map<String, int> _nodeLocationCounts = new HashMap<String, int>(); 408 final Map<String, int> _nodeLocationCounts = new HashMap<String, int>();
580
581 final Map<String, IndexNode> _nodes = new HashMap<String, IndexNode>(); 409 final Map<String, IndexNode> _nodes = new HashMap<String, IndexNode>();
582 RelationshipCodec _relationshipCodec; 410 RelationshipCodec _relationshipCodec;
583 StringCodec _stringCodec = new StringCodec(); 411 StringCodec _stringCodec = new StringCodec();
584 412
585 _MemoryNodeManager() { 413 _MemoryNodeManager() {
586 _elementCodec = new ElementCodec(_stringCodec); 414 _elementCodec = new ElementCodec(_stringCodec);
587 _relationshipCodec = new RelationshipCodec(_stringCodec); 415 _relationshipCodec = new RelationshipCodec(_stringCodec);
588 } 416 }
589 417
590 @override 418 @override
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 _nodes[name] = node; 478 _nodes[name] = node;
651 } 479 }
652 480
653 @override 481 @override
654 void removeNode(String name) { 482 void removeNode(String name) {
655 _nodes.remove(name); 483 _nodes.remove(name);
656 } 484 }
657 } 485 }
658 486
659 487
660 class _MockAnalysisContext extends TypedMock implements AnalysisContext {
661 String _name;
662 _MockAnalysisContext(this._name);
663 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
664 String toString() => _name;
665 }
666
667
668 class _MockCompilationUnitElement extends TypedMock implements
669 CompilationUnitElement {
670 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
671 }
672
673
674 class _MockContextCodec extends TypedMock implements ContextCodec {
675 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
676 }
677
678
679 class _MockElement extends TypedMock implements Element {
680 String _name;
681 _MockElement([this._name = '<element>']);
682 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
683 String toString() => _name;
684 }
685
686
687 class _MockElementCodec extends TypedMock implements ElementCodec {
688 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
689 }
690
691
692 class _MockFileManager extends TypedMock implements FileManager { 488 class _MockFileManager extends TypedMock implements FileManager {
693 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 489 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
694 } 490 }
695 491
696 492
697 class _MockHtmlElement extends TypedMock implements HtmlElement {
698 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
699 }
700
701
702 class _MockIndexNode extends TypedMock implements IndexNode { 493 class _MockIndexNode extends TypedMock implements IndexNode {
703 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 494 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
704 } 495 }
705 496
706 497
707 class _MockInstrumentedAnalysisContextImpl extends TypedMock implements
708 InstrumentedAnalysisContextImpl {
709 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
710 }
711
712
713 class _MockLibraryElement extends TypedMock implements LibraryElement {
714 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
715 }
716
717
718 class _MockLocation extends TypedMock implements Location {
719 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
720 }
721
722
723 class _MockLogger extends TypedMock implements Logger {
724 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
725 }
726
727
728 class _MockRelationshipCodec extends TypedMock implements RelationshipCodec {
729 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
730 }
731
732
733 class _MockSource extends TypedMock implements Source {
734 String _name;
735 _MockSource(this._name);
736 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
737 String toString() => _name;
738 }
739
740
741 @ReflectiveTestCase() 498 @ReflectiveTestCase()
742 class _RelationKeyDataTest { 499 class _RelationKeyDataTest {
743 AnalysisContext context = new _MockAnalysisContext('context'); 500 AnalysisContext context = new MockAnalysisContext('context');
744 ElementCodec elementCodec = new _MockElementCodec(); 501 ElementCodec elementCodec = new MockElementCodec();
745 RelationshipCodec relationshipCodec = new _MockRelationshipCodec(); 502 RelationshipCodec relationshipCodec = new MockRelationshipCodec();
746 StringCodec stringCodec = new StringCodec(); 503 StringCodec stringCodec = new StringCodec();
747 504
748 void test_newFromData() { 505 void test_newFromData() {
749 RelationKeyData keyData = new RelationKeyData.forData(1, 2); 506 RelationKeyData keyData = new RelationKeyData.forData(1, 2);
750 // equals 507 // equals
751 expect(keyData == this, isFalse); 508 expect(keyData == this, isFalse);
752 expect(keyData == new RelationKeyData.forData(10, 20), isFalse); 509 expect(keyData == new RelationKeyData.forData(10, 20), isFalse);
753 expect(keyData == keyData, isTrue); 510 expect(keyData == keyData, isTrue);
754 expect(keyData == new RelationKeyData.forData(1, 2), isTrue); 511 expect(keyData == new RelationKeyData.forData(1, 2), isTrue);
755 } 512 }
756 513
757 void test_newFromObjects() { 514 void test_newFromObjects() {
758 // prepare Element 515 // prepare Element
759 Element element; 516 Element element;
760 int elementId = 2; 517 int elementId = 2;
761 { 518 {
762 element = new _MockElement(); 519 element = new MockElement();
763 ElementLocation location = new ElementLocationImpl.con3(['foo', 'bar']); 520 ElementLocation location = new ElementLocationImpl.con3(['foo', 'bar']);
764 when(element.location).thenReturn(location); 521 when(element.location).thenReturn(location);
765 when(context.getElement(location)).thenReturn(element); 522 when(context.getElement(location)).thenReturn(element);
766 when(elementCodec.encode(element)).thenReturn(elementId); 523 when(elementCodec.encode(element)).thenReturn(elementId);
767 } 524 }
768 // prepare relationship 525 // prepare relationship
769 Relationship relationship = Relationship.getRelationship('my-relationship'); 526 Relationship relationship = Relationship.getRelationship('my-relationship');
770 int relationshipId = 1; 527 int relationshipId = 1;
771 when(relationshipCodec.encode(relationship)).thenReturn(relationshipId); 528 when(relationshipCodec.encode(relationship)).thenReturn(relationshipId);
772 // create RelationKeyData 529 // create RelationKeyData
773 RelationKeyData keyData = new RelationKeyData.forObject(elementCodec, 530 RelationKeyData keyData = new RelationKeyData.forObject(elementCodec,
774 relationshipCodec, element, relationship); 531 relationshipCodec, element, relationship);
775 // touch 532 // touch
776 keyData.hashCode; 533 keyData.hashCode;
777 // equals 534 // equals
778 expect(keyData == this, isFalse); 535 expect(keyData == this, isFalse);
779 expect(keyData == new RelationKeyData.forData(10, 20), isFalse); 536 expect(keyData == new RelationKeyData.forData(10, 20), isFalse);
780 expect(keyData == keyData, isTrue); 537 expect(keyData == keyData, isTrue);
781 expect(keyData == new RelationKeyData.forData(elementId, relationshipId), 538 expect(keyData == new RelationKeyData.forData(elementId, relationshipId),
782 isTrue); 539 isTrue);
783 } 540 }
784 } 541 }
785 542
786 543
787 @ReflectiveTestCase()
788 class _RelationshipCodecTest {
789 RelationshipCodec codec;
790 StringCodec stringCodec = new StringCodec();
791
792 void setUp() {
793 codec = new RelationshipCodec(stringCodec);
794 }
795
796 void test_all() {
797 Relationship relationship = Relationship.getRelationship('my-relationship');
798 int id = codec.encode(relationship);
799 expect(codec.decode(id), relationship);
800 }
801 }
802
803
804 class _SingleSourceContainer implements SourceContainer { 544 class _SingleSourceContainer implements SourceContainer {
805 final Source _source; 545 final Source _source;
806 _SingleSourceContainer(this._source); 546 _SingleSourceContainer(this._source);
807 @override 547 @override
808 bool contains(Source source) => source == _source; 548 bool contains(Source source) => source == _source;
809 } 549 }
810 550
811 551
812 @ReflectiveTestCase() 552 @ReflectiveTestCase()
813 class _SplitIndexStoreTest { 553 class _SplitIndexStoreTest {
814 AnalysisContext contextA = new _MockAnalysisContext('contextA'); 554 AnalysisContext contextA = new MockAnalysisContext('contextA');
815 555
816 AnalysisContext contextB = new _MockAnalysisContext('contextB'); 556 AnalysisContext contextB = new MockAnalysisContext('contextB');
817 557
818 AnalysisContext contextC = new _MockAnalysisContext('contextC'); 558 AnalysisContext contextC = new MockAnalysisContext('contextC');
819 559
820 Element elementA = new _MockElement('elementA'); 560 Element elementA = new MockElement('elementA');
821 Element elementB = new _MockElement('elementB'); 561 Element elementB = new MockElement('elementB');
822 562
823 Element elementC = new _MockElement('elementC'); 563 Element elementC = new MockElement('elementC');
824 Element elementD = new _MockElement('elementD'); 564 Element elementD = new MockElement('elementD');
825 ElementLocation elementLocationA = new ElementLocationImpl.con3( 565 ElementLocation elementLocationA = new ElementLocationImpl.con3(
826 ['/home/user/sourceA.dart', 'ClassA']); 566 ['/home/user/sourceA.dart', 'ClassA']);
827 ElementLocation elementLocationB = new ElementLocationImpl.con3( 567 ElementLocation elementLocationB = new ElementLocationImpl.con3(
828 ['/home/user/sourceB.dart', 'ClassB']); 568 ['/home/user/sourceB.dart', 'ClassB']);
829 ElementLocation elementLocationC = new ElementLocationImpl.con3( 569 ElementLocation elementLocationC = new ElementLocationImpl.con3(
830 ['/home/user/sourceC.dart', 'ClassC']); 570 ['/home/user/sourceC.dart', 'ClassC']);
831 ElementLocation elementLocationD = new ElementLocationImpl.con3( 571 ElementLocation elementLocationD = new ElementLocationImpl.con3(
832 ['/home/user/sourceD.dart', 'ClassD']); 572 ['/home/user/sourceD.dart', 'ClassD']);
833 HtmlElement htmlElementA = new _MockHtmlElement(); 573 HtmlElement htmlElementA = new MockHtmlElement();
834 HtmlElement htmlElementB = new _MockHtmlElement(); 574 HtmlElement htmlElementB = new MockHtmlElement();
835 LibraryElement libraryElement = new _MockLibraryElement(); 575 LibraryElement libraryElement = new MockLibraryElement();
836 Source librarySource = new _MockSource('librarySource'); 576 Source librarySource = new MockSource('librarySource');
837 CompilationUnitElement libraryUnitElement = new _MockCompilationUnitElement(); 577 CompilationUnitElement libraryUnitElement = new MockCompilationUnitElement();
838 _MemoryNodeManager nodeManager = new _MemoryNodeManager(); 578 _MemoryNodeManager nodeManager = new _MemoryNodeManager();
839 Relationship relationship = Relationship.getRelationship('test-relationship'); 579 Relationship relationship = Relationship.getRelationship('test-relationship');
840 Source sourceA = new _MockSource('sourceA'); 580 Source sourceA = new MockSource('sourceA');
841 Source sourceB = new _MockSource('sourceB'); 581 Source sourceB = new MockSource('sourceB');
842 Source sourceC = new _MockSource('sourceC'); 582 Source sourceC = new MockSource('sourceC');
843 Source sourceD = new _MockSource('sourceD'); 583 Source sourceD = new MockSource('sourceD');
844 SplitIndexStore store; 584 SplitIndexStore store;
845 CompilationUnitElement unitElementA = new _MockCompilationUnitElement(); 585 CompilationUnitElement unitElementA = new MockCompilationUnitElement();
846 CompilationUnitElement unitElementB = new _MockCompilationUnitElement(); 586 CompilationUnitElement unitElementB = new MockCompilationUnitElement();
847 CompilationUnitElement unitElementC = new _MockCompilationUnitElement(); 587 CompilationUnitElement unitElementC = new MockCompilationUnitElement();
848 CompilationUnitElement unitElementD = new _MockCompilationUnitElement(); 588 CompilationUnitElement unitElementD = new MockCompilationUnitElement();
849 void setUp() { 589 void setUp() {
850 store = new SplitIndexStore(nodeManager); 590 store = new SplitIndexStore(nodeManager);
851 when(contextA.isDisposed).thenReturn(false); 591 when(contextA.isDisposed).thenReturn(false);
852 when(contextB.isDisposed).thenReturn(false); 592 when(contextB.isDisposed).thenReturn(false);
853 when(contextC.isDisposed).thenReturn(false); 593 when(contextC.isDisposed).thenReturn(false);
854 when(contextA.getElement(elementLocationA)).thenReturn(elementA); 594 when(contextA.getElement(elementLocationA)).thenReturn(elementA);
855 when(contextA.getElement(elementLocationB)).thenReturn(elementB); 595 when(contextA.getElement(elementLocationB)).thenReturn(elementB);
856 when(contextA.getElement(elementLocationC)).thenReturn(elementC); 596 when(contextA.getElement(elementLocationC)).thenReturn(elementC);
857 when(contextA.getElement(elementLocationD)).thenReturn(elementD); 597 when(contextA.getElement(elementLocationD)).thenReturn(elementD);
858 when(sourceA.fullName).thenReturn('/home/user/sourceA.dart'); 598 when(sourceA.fullName).thenReturn('/home/user/sourceA.dart');
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 when(libraryElement.source).thenReturn(librarySource); 635 when(libraryElement.source).thenReturn(librarySource);
896 when(libraryElement.definingCompilationUnit).thenReturn(libraryUnitElement); 636 when(libraryElement.definingCompilationUnit).thenReturn(libraryUnitElement);
897 } 637 }
898 void test_aboutToIndexDart_disposedContext() { 638 void test_aboutToIndexDart_disposedContext() {
899 when(contextA.isDisposed).thenReturn(true); 639 when(contextA.isDisposed).thenReturn(true);
900 expect(store.aboutToIndexDart(contextA, unitElementA), isFalse); 640 expect(store.aboutToIndexDart(contextA, unitElementA), isFalse);
901 } 641 }
902 void test_aboutToIndexDart_disposedContext_wrapped() { 642 void test_aboutToIndexDart_disposedContext_wrapped() {
903 when(contextA.isDisposed).thenReturn(true); 643 when(contextA.isDisposed).thenReturn(true);
904 InstrumentedAnalysisContextImpl instrumentedContext = 644 InstrumentedAnalysisContextImpl instrumentedContext =
905 new _MockInstrumentedAnalysisContextImpl(); 645 new MockInstrumentedAnalysisContextImpl();
906 when(instrumentedContext.basis).thenReturn(contextA); 646 when(instrumentedContext.basis).thenReturn(contextA);
907 expect(store.aboutToIndexDart(instrumentedContext, unitElementA), isFalse); 647 expect(store.aboutToIndexDart(instrumentedContext, unitElementA), isFalse);
908 } 648 }
909 649
910 void test_aboutToIndexDart_library_first() { 650 void test_aboutToIndexDart_library_first() {
911 when(libraryElement.parts).thenReturn(<CompilationUnitElement>[unitElementA, 651 when(libraryElement.parts).thenReturn(<CompilationUnitElement>[unitElementA,
912 unitElementB]); 652 unitElementB]);
913 { 653 {
914 store.aboutToIndexDart(contextA, libraryUnitElement); 654 store.aboutToIndexDart(contextA, libraryUnitElement);
915 store.doneIndex(); 655 store.doneIndex();
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1326 static void assertLocations(List<Location> actual, List<Location> expected) { 1066 static void assertLocations(List<Location> actual, List<Location> expected) {
1327 List<_LocationEqualsWrapper> actualWrappers = wrapLocations(actual); 1067 List<_LocationEqualsWrapper> actualWrappers = wrapLocations(actual);
1328 List<_LocationEqualsWrapper> expectedWrappers = wrapLocations(expected); 1068 List<_LocationEqualsWrapper> expectedWrappers = wrapLocations(expected);
1329 expect(actualWrappers, unorderedEquals(expectedWrappers)); 1069 expect(actualWrappers, unorderedEquals(expectedWrappers));
1330 } 1070 }
1331 1071
1332 /** 1072 /**
1333 * @return the new [Location] mock. 1073 * @return the new [Location] mock.
1334 */ 1074 */
1335 static Location mockLocation(Element element) { 1075 static Location mockLocation(Element element) {
1336 Location location = new _MockLocation(); 1076 Location location = new MockLocation();
1337 when(location.element).thenReturn(element); 1077 when(location.element).thenReturn(element);
1338 when(location.offset).thenReturn(0); 1078 when(location.offset).thenReturn(0);
1339 when(location.length).thenReturn(0); 1079 when(location.length).thenReturn(0);
1340 return location; 1080 return location;
1341 } 1081 }
1342 1082
1343 /** 1083 /**
1344 * Wraps the given locations into [LocationEqualsWrapper]. 1084 * Wraps the given locations into [LocationEqualsWrapper].
1345 */ 1085 */
1346 static List<_LocationEqualsWrapper> wrapLocations(List<Location> locations) { 1086 static List<_LocationEqualsWrapper> wrapLocations(List<Location> locations) {
1347 List<_LocationEqualsWrapper> wrappers = <_LocationEqualsWrapper>[]; 1087 List<_LocationEqualsWrapper> wrappers = <_LocationEqualsWrapper>[];
1348 for (Location location in locations) { 1088 for (Location location in locations) {
1349 wrappers.add(new _LocationEqualsWrapper(location)); 1089 wrappers.add(new _LocationEqualsWrapper(location));
1350 } 1090 }
1351 return wrappers; 1091 return wrappers;
1352 } 1092 }
1353 } 1093 }
1354
1355
1356 @ReflectiveTestCase()
1357 class _StringCodecTest {
1358 StringCodec codec = new StringCodec();
1359
1360 void test_all() {
1361 int idA = codec.encode('aaa');
1362 int idB = codec.encode('bbb');
1363 expect(codec.decode(idA), 'aaa');
1364 expect(codec.decode(idB), 'bbb');
1365 }
1366 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/index/store/collection_test.dart ('k') | pkg/analysis_server/test/index/store/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698