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

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

Issue 402333006: Implementation of the 'edit.getFixes' API in server. (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
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/mocks.dart'; 10 import 'package:analysis_testing/mocks.dart';
10 import 'package:analysis_testing/reflective_tests.dart'; 11 import 'package:analysis_testing/reflective_tests.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:unittest/unittest.dart'; 14 import 'package:unittest/unittest.dart';
14 15
15 import '../abstract_single_unit.dart';
16
17 16
18 main() { 17 main() {
19 groupSep = ' | '; 18 groupSep = ' | ';
20 group('ContextCodec', () { 19 group('ContextCodec', () {
21 runReflectiveTests(_ContextCodecTest); 20 runReflectiveTests(_ContextCodecTest);
22 }); 21 });
23 group('ElementCodec', () { 22 group('ElementCodec', () {
24 runReflectiveTests(_ElementCodecTest); 23 runReflectiveTests(_ElementCodecTest);
25 }); 24 });
26 group('RelationshipCodec', () { 25 group('RelationshipCodec', () {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 class _ElementCodecTest extends AbstractSingleUnitTest { 74 class _ElementCodecTest extends AbstractSingleUnitTest {
76 ElementCodec codec; 75 ElementCodec codec;
77 AnalysisContext context = new MockAnalysisContext('context'); 76 AnalysisContext context = new MockAnalysisContext('context');
78 StringCodec stringCodec = new StringCodec(); 77 StringCodec stringCodec = new StringCodec();
79 78
80 void setUp() { 79 void setUp() {
81 super.setUp(); 80 super.setUp();
82 codec = new ElementCodec(stringCodec); 81 codec = new ElementCodec(stringCodec);
83 } 82 }
84 83
85 void test_field() {
86 resolveTestUnit('''
87 class A {
88 int field;
89 }
90 ''');
91 FieldElement field = findElement('field', ElementKind.FIELD);
92 PropertyAccessorElement getter = field.getter;
93 PropertyAccessorElement setter = field.setter;
94 {
95 int id = codec.encode(getter);
96 expect(codec.decode(context, id), getter);
97 }
98 {
99 int id = codec.encode(setter);
100 expect(codec.decode(context, id), setter);
101 }
102 {
103 int id = codec.encode(field);
104 expect(codec.decode(context, id), field);
105 }
106 }
107
108 void test_encodeHash_notLocal() { 84 void test_encodeHash_notLocal() {
109 resolveTestUnit(''' 85 resolveTestUnit('''
110 class A { 86 class A {
111 void mainA() { 87 void mainA() {
112 int foo; // A 88 int foo; // A
113 } 89 }
114 void mainB() { 90 void mainB() {
115 int foo; // B 91 int foo; // B
116 int bar; 92 int bar;
117 } 93 }
118 } 94 }
119 '''); 95 ''');
120 MethodElement mainA = findElement('mainA'); 96 MethodElement mainA = findElement('mainA');
121 MethodElement mainB = findElement('mainB'); 97 MethodElement mainB = findElement('mainB');
122 Element fooA = mainA.localVariables[0]; 98 Element fooA = mainA.localVariables[0];
123 Element fooB = mainB.localVariables[0]; 99 Element fooB = mainB.localVariables[0];
124 Element bar = mainB.localVariables[1]; 100 Element bar = mainB.localVariables[1];
125 int id_fooA = codec.encodeHash(fooA); 101 int id_fooA = codec.encodeHash(fooA);
126 int id_fooB = codec.encodeHash(fooB); 102 int id_fooB = codec.encodeHash(fooB);
127 int id_bar = codec.encodeHash(bar); 103 int id_bar = codec.encodeHash(bar);
128 expect(id_fooA == id_fooB, isTrue); 104 expect(id_fooA == id_fooB, isTrue);
129 expect(id_fooA == id_bar, isFalse); 105 expect(id_fooA == id_bar, isFalse);
130 } 106 }
131 107
108 void test_field() {
109 resolveTestUnit('''
110 class A {
111 int field;
112 }
113 ''');
114 FieldElement field = findElement('field', ElementKind.FIELD);
115 PropertyAccessorElement getter = field.getter;
116 PropertyAccessorElement setter = field.setter;
117 {
118 int id = codec.encode(getter);
119 expect(codec.decode(context, id), getter);
120 }
121 {
122 int id = codec.encode(setter);
123 expect(codec.decode(context, id), setter);
124 }
125 {
126 int id = codec.encode(field);
127 expect(codec.decode(context, id), field);
128 }
129 }
130
132 void test_localLocalVariable() { 131 void test_localLocalVariable() {
133 resolveTestUnit(''' 132 resolveTestUnit('''
134 main() { 133 main() {
135 { 134 {
136 foo() { 135 foo() {
137 int bar; // A 136 int bar; // A
138 } 137 }
139 } 138 }
140 { 139 {
141 foo() { 140 foo() {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 class _StringCodecTest { 229 class _StringCodecTest {
231 StringCodec codec = new StringCodec(); 230 StringCodec codec = new StringCodec();
232 231
233 void test_all() { 232 void test_all() {
234 int idA = codec.encode('aaa'); 233 int idA = codec.encode('aaa');
235 int idB = codec.encode('bbb'); 234 int idB = codec.encode('bbb');
236 expect(codec.decode(idA), 'aaa'); 235 expect(codec.decode(idA), 'aaa');
237 expect(codec.decode(idB), 'bbb'); 236 expect(codec.decode(idB), 'bbb');
238 } 237 }
239 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698