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

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

Issue 375693002: Move index/search to services. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.engine.src.index.store.codec;
6
7 import 'package:analysis_testing/mocks.dart';
8 import 'package:analysis_testing/reflective_tests.dart';
9 import 'package:analyzer/index/index.dart';
10 import 'package:analyzer/src/generated/element.dart';
11 import 'package:analyzer/src/generated/engine.dart';
12 import 'package:analyzer/src/index/store/codec.dart';
13 import 'package:typed_mock/typed_mock.dart';
14 import 'package:unittest/unittest.dart';
15
16
17 main() {
18 groupSep = ' | ';
19 group('ContextCodec', () {
20 runReflectiveTests(_ContextCodecTest);
21 });
22 group('ElementCodec', () {
23 runReflectiveTests(_ElementCodecTest);
24 });
25 group('RelationshipCodec', () {
26 runReflectiveTests(_RelationshipCodecTest);
27 });
28 group('StringCodec', () {
29 runReflectiveTests(_StringCodecTest);
30 });
31 }
32
33
34 @ReflectiveTestCase()
35 class _ContextCodecTest {
36 ContextCodec codec = new ContextCodec();
37
38 void test_encode_decode() {
39 AnalysisContext contextA = new MockAnalysisContext('contextA');
40 AnalysisContext contextB = new MockAnalysisContext('contextB');
41 int idA = codec.encode(contextA);
42 int idB = codec.encode(contextB);
43 expect(idA, codec.encode(contextA));
44 expect(idB, codec.encode(contextB));
45 expect(codec.decode(idA), contextA);
46 expect(codec.decode(idB), contextB);
47 }
48
49 void test_remove() {
50 // encode
51 {
52 AnalysisContext context = new MockAnalysisContext('context');
53 // encode
54 int id = codec.encode(context);
55 expect(id, 0);
56 expect(codec.decode(id), context);
57 // remove
58 codec.remove(context);
59 expect(codec.decode(id), isNull);
60 }
61 // encode again
62 {
63 AnalysisContext context = new MockAnalysisContext('context');
64 // encode
65 int id = codec.encode(context);
66 expect(id, 1);
67 expect(codec.decode(id), context);
68 }
69 }
70 }
71
72
73 @ReflectiveTestCase()
74 class _ElementCodecTest {
75 ElementCodec codec;
76 AnalysisContext context = new MockAnalysisContext('context');
77 StringCodec stringCodec = new StringCodec();
78
79 void setUp() {
80 codec = new ElementCodec(stringCodec);
81 }
82
83 void test_localLocalVariable() {
84 {
85 Element element = new MockElement();
86 ElementLocation location = new ElementLocationImpl.con3(['main', 'foo@1',
87 'bar@2']);
88 when(context.getElement(location)).thenReturn(element);
89 when(element.location).thenReturn(location);
90 int id = codec.encode(element);
91 expect(codec.decode(context, id), element);
92 }
93 {
94 Element element = new MockElement();
95 ElementLocation location = new ElementLocationImpl.con3(['main', 'foo@10',
96 'bar@20']);
97 when(context.getElement(location)).thenReturn(element);
98 when(element.location).thenReturn(location);
99 int id = codec.encode(element);
100 expect(codec.decode(context, id), element);
101 }
102 // check strings, "foo" as a single string, no "foo@1" or "foo@10"
103 expect(stringCodec.nameToIndex, hasLength(3));
104 expect(stringCodec.nameToIndex, containsPair('main', 0));
105 expect(stringCodec.nameToIndex, containsPair('foo', 1));
106 expect(stringCodec.nameToIndex, containsPair('bar', 2));
107 }
108
109 void test_localVariable() {
110 {
111 Element element = new MockElement();
112 ElementLocation location = new ElementLocationImpl.con3(['main',
113 'foo@42']);
114 when(context.getElement(location)).thenReturn(element);
115 when(element.location).thenReturn(location);
116 int id = codec.encode(element);
117 expect(codec.decode(context, id), element);
118 }
119 {
120 Element element = new MockElement();
121 ElementLocation location = new ElementLocationImpl.con3(['main',
122 'foo@4200']);
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 // check strings, "foo" as a single string, no "foo@42" or "foo@4200"
129 expect(stringCodec.nameToIndex, hasLength(2));
130 expect(stringCodec.nameToIndex, containsPair('main', 0));
131 expect(stringCodec.nameToIndex, containsPair('foo', 1));
132 }
133
134 void test_notLocal() {
135 Element element = new MockElement();
136 ElementLocation location = new ElementLocationImpl.con3(['foo', 'bar']);
137 when(element.location).thenReturn(location);
138 when(context.getElement(location)).thenReturn(element);
139 int id = codec.encode(element);
140 expect(codec.encode(element), id);
141 expect(codec.decode(context, id), element);
142 // check strings
143 expect(stringCodec.nameToIndex, hasLength(2));
144 expect(stringCodec.nameToIndex, containsPair('foo', 0));
145 expect(stringCodec.nameToIndex, containsPair('bar', 1));
146 }
147 }
148
149
150 @ReflectiveTestCase()
151 class _RelationshipCodecTest {
152 StringCodec stringCodec = new StringCodec();
153 RelationshipCodec codec;
154
155 void setUp() {
156 codec = new RelationshipCodec(stringCodec);
157 }
158
159 void test_all() {
160 Relationship relationship = Relationship.getRelationship('my-relationship');
161 int id = codec.encode(relationship);
162 expect(codec.decode(id), relationship);
163 }
164 }
165
166
167 @ReflectiveTestCase()
168 class _StringCodecTest {
169 StringCodec codec = new StringCodec();
170
171 void test_all() {
172 int idA = codec.encode('aaa');
173 int idB = codec.encode('bbb');
174 expect(codec.decode(idA), 'aaa');
175 expect(codec.decode(idB), 'bbb');
176 }
177 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/index/local_index_test.dart ('k') | pkg/analyzer/test/index/store/collection_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698