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.search.search_result; | 5 library test.search.search_result; |
6 | 6 |
7 import 'package:analysis_server/src/computer/element.dart'; | 7 import 'package:analysis_server/src/protocol2.dart'; |
8 import 'package:analysis_server/src/protocol2.dart' show ElementKind; | |
9 import 'package:analysis_server/src/search/search_result.dart'; | |
10 import 'package:analysis_server/src/constants.dart'; | |
11 import 'package:analysis_server/src/services/search/search_engine.dart'; | 8 import 'package:analysis_server/src/services/search/search_engine.dart'; |
12 import 'package:analysis_testing/reflective_tests.dart'; | 9 import 'package:analysis_testing/reflective_tests.dart'; |
13 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
14 | 11 |
15 | 12 |
16 main() { | 13 main() { |
17 groupSep = ' | '; | 14 groupSep = ' | '; |
18 runReflectiveTests(SearchResultTest); | |
19 runReflectiveTests(SearchResultKindTest); | 15 runReflectiveTests(SearchResultKindTest); |
20 } | 16 } |
21 | 17 |
22 | 18 |
23 @ReflectiveTestCase() | 19 @ReflectiveTestCase() |
24 class SearchResultKindTest { | 20 class SearchResultKindTest { |
25 void test_fromEngine() { | 21 void test_fromEngine() { |
26 expect( | 22 expect( |
27 new SearchResultKind.fromEngine(MatchKind.DECLARATION), | 23 new SearchResultKind.fromEngine(MatchKind.DECLARATION), |
28 SearchResultKind.DECLARATION); | 24 SearchResultKind.DECLARATION); |
(...skipping 10 matching lines...) Expand all Loading... |
39 new SearchResultKind.fromEngine(MatchKind.REFERENCE), | 35 new SearchResultKind.fromEngine(MatchKind.REFERENCE), |
40 SearchResultKind.REFERENCE); | 36 SearchResultKind.REFERENCE); |
41 expect( | 37 expect( |
42 new SearchResultKind.fromEngine(MatchKind.INVOCATION), | 38 new SearchResultKind.fromEngine(MatchKind.INVOCATION), |
43 SearchResultKind.INVOCATION); | 39 SearchResultKind.INVOCATION); |
44 expect(new SearchResultKind.fromEngine(null), SearchResultKind.UNKNOWN); | 40 expect(new SearchResultKind.fromEngine(null), SearchResultKind.UNKNOWN); |
45 } | 41 } |
46 | 42 |
47 void test_fromName() { | 43 void test_fromName() { |
48 expect( | 44 expect( |
49 new SearchResultKind.fromName(SearchResultKind.DECLARATION.name), | 45 new SearchResultKind(SearchResultKind.DECLARATION.name), |
50 SearchResultKind.DECLARATION); | 46 SearchResultKind.DECLARATION); |
51 expect( | 47 expect( |
52 new SearchResultKind.fromName(SearchResultKind.READ.name), | 48 new SearchResultKind(SearchResultKind.READ.name), |
53 SearchResultKind.READ); | 49 SearchResultKind.READ); |
54 expect( | 50 expect( |
55 new SearchResultKind.fromName(SearchResultKind.READ_WRITE.name), | 51 new SearchResultKind(SearchResultKind.READ_WRITE.name), |
56 SearchResultKind.READ_WRITE); | 52 SearchResultKind.READ_WRITE); |
57 expect( | 53 expect( |
58 new SearchResultKind.fromName(SearchResultKind.WRITE.name), | 54 new SearchResultKind(SearchResultKind.WRITE.name), |
59 SearchResultKind.WRITE); | 55 SearchResultKind.WRITE); |
60 expect( | 56 expect( |
61 new SearchResultKind.fromName(SearchResultKind.REFERENCE.name), | 57 new SearchResultKind(SearchResultKind.REFERENCE.name), |
62 SearchResultKind.REFERENCE); | 58 SearchResultKind.REFERENCE); |
63 expect( | 59 expect( |
64 new SearchResultKind.fromName(SearchResultKind.INVOCATION.name), | 60 new SearchResultKind(SearchResultKind.INVOCATION.name), |
65 SearchResultKind.INVOCATION); | 61 SearchResultKind.INVOCATION); |
66 expect(new SearchResultKind.fromName(null), SearchResultKind.UNKNOWN); | 62 expect( |
| 63 new SearchResultKind(SearchResultKind.UNKNOWN.name), |
| 64 SearchResultKind.UNKNOWN); |
67 } | 65 } |
68 | 66 |
69 void test_toString() { | 67 void test_toString() { |
70 expect(SearchResultKind.DECLARATION.toString(), 'DECLARATION'); | 68 expect(SearchResultKind.DECLARATION.toString(), |
| 69 'SearchResultKind.DECLARATION'); |
71 } | 70 } |
72 } | 71 } |
73 | |
74 | |
75 @ReflectiveTestCase() | |
76 class SearchResultTest { | |
77 void test_fromJson() { | |
78 Map<String, Object> map = { | |
79 KIND: 'READ', | |
80 IS_POTENTIAL: true, | |
81 LOCATION: { | |
82 FILE: '/test.dart', | |
83 OFFSET: 1, | |
84 LENGTH: 2, | |
85 START_LINE: 3, | |
86 START_COLUMN: 4 | |
87 }, | |
88 PATH: [ | |
89 new Element( | |
90 ElementKind.FIELD, | |
91 'myField', | |
92 new Location('/lib.dart', 10, 20, 30, 40), | |
93 false, | |
94 false).toJson()] | |
95 }; | |
96 SearchResult result = new SearchResult.fromJson(map); | |
97 expect(result.kind, SearchResultKind.READ); | |
98 expect(result.location.file, '/test.dart'); | |
99 expect(result.location.offset, 1); | |
100 expect(result.location.length, 2); | |
101 expect(result.location.startLine, 3); | |
102 expect(result.location.startColumn, 4); | |
103 expect(result.path, hasLength(1)); | |
104 expect(result.path[0].kind, ElementKind.FIELD); | |
105 expect(result.path[0].name, 'myField'); | |
106 expect(result.path[0].location.file, '/lib.dart'); | |
107 expect(result.path[0].location.offset, 10); | |
108 // touch toJson(); | |
109 expect(result.toJson(), hasLength(4)); | |
110 // touch asJson(); | |
111 expect(SearchResult.asJson(result), hasLength(4)); | |
112 // touch toString(); | |
113 expect(result.toString(), hasLength(greaterThan(10))); | |
114 } | |
115 } | |
OLD | NEW |