| 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.computer.element; | 5 library test.computer.element; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/computer/element.dart'; | 7 import 'package:analysis_server/src/computer/element.dart'; |
| 8 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
| 9 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart' as engine; | 10 import 'package:analyzer/src/generated/element.dart' as engine; |
| 11 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; | 12 import 'package:analyzer/src/generated/utilities_dart.dart' as engine; |
| 11 import 'package:typed_mock/typed_mock.dart'; | |
| 12 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 13 | 14 |
| 14 import '../index/store/typed_mocks.dart'; | 15 import '../abstract_context.dart'; |
| 15 import '../reflective_tests.dart'; | 16 import '../reflective_tests.dart'; |
| 16 | 17 |
| 17 | 18 |
| 18 main() { | 19 main() { |
| 19 groupSep = ' | '; | 20 groupSep = ' | '; |
| 20 group('Element', () { | 21 group('Element', () { |
| 21 runReflectiveTests(_ElementTest); | 22 runReflectiveTests(ElementTest); |
| 22 }); | 23 }); |
| 23 group('ElementKind', () { | 24 group('ElementKind', () { |
| 24 test('toString', test_ElementKind_toString); | 25 runReflectiveTests(ElementKindTest); |
| 25 test('valueOf', test_ElementKind_valueOf); | |
| 26 test('valueOfEngine', test_ElementKind_valueOfEngine); | |
| 27 }); | 26 }); |
| 28 } | 27 } |
| 29 | 28 |
| 30 | 29 |
| 31 void test_ElementKind_toString() { | 30 class ElementKindTest { |
| 32 expect(ElementKind.CLASS.toString(), 'CLASS'); | 31 void test_toString() { |
| 33 expect(ElementKind.COMPILATION_UNIT.toString(), 'COMPILATION_UNIT'); | 32 expect(ElementKind.CLASS.toString(), 'CLASS'); |
| 33 expect(ElementKind.COMPILATION_UNIT.toString(), 'COMPILATION_UNIT'); |
| 34 } |
| 35 |
| 36 void test_valueOf() { |
| 37 expect(ElementKind.valueOf(ElementKind.CLASS.name), ElementKind.CLASS); |
| 38 expect(ElementKind.valueOf(ElementKind.CLASS_TYPE_ALIAS.name), |
| 39 ElementKind.CLASS_TYPE_ALIAS); |
| 40 expect(ElementKind.valueOf(ElementKind.COMPILATION_UNIT.name), |
| 41 ElementKind.COMPILATION_UNIT); |
| 42 expect(ElementKind.valueOf(ElementKind.CONSTRUCTOR.name), |
| 43 ElementKind.CONSTRUCTOR); |
| 44 expect(ElementKind.valueOf(ElementKind.FIELD.name), ElementKind.FIELD); |
| 45 expect(ElementKind.valueOf(ElementKind.FUNCTION.name), |
| 46 ElementKind.FUNCTION); |
| 47 expect(ElementKind.valueOf(ElementKind.FUNCTION_TYPE_ALIAS.name), |
| 48 ElementKind.FUNCTION_TYPE_ALIAS); |
| 49 expect(ElementKind.valueOf(ElementKind.GETTER.name), ElementKind.GETTER); |
| 50 expect(ElementKind.valueOf(ElementKind.LIBRARY.name), ElementKind.LIBRARY); |
| 51 expect(ElementKind.valueOf(ElementKind.METHOD.name), ElementKind.METHOD); |
| 52 expect(ElementKind.valueOf(ElementKind.SETTER.name), ElementKind.SETTER); |
| 53 expect(ElementKind.valueOf(ElementKind.TOP_LEVEL_VARIABLE.name), |
| 54 ElementKind.TOP_LEVEL_VARIABLE); |
| 55 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_CASE.name), |
| 56 ElementKind.UNIT_TEST_CASE); |
| 57 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_GROUP.name), |
| 58 ElementKind.UNIT_TEST_GROUP); |
| 59 expect(ElementKind.valueOf(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN); |
| 60 expect(() { |
| 61 ElementKind.valueOf('no-such-kind'); |
| 62 }, throws); |
| 63 } |
| 64 |
| 65 void test_valueOfEngine() { |
| 66 expect(ElementKind.valueOfEngine(engine.ElementKind.CLASS), |
| 67 ElementKind.CLASS); |
| 68 expect(ElementKind.valueOfEngine(engine.ElementKind.COMPILATION_UNIT), |
| 69 ElementKind.COMPILATION_UNIT); |
| 70 expect(ElementKind.valueOfEngine(engine.ElementKind.CONSTRUCTOR), |
| 71 ElementKind.CONSTRUCTOR); |
| 72 expect(ElementKind.valueOfEngine(engine.ElementKind.FIELD), |
| 73 ElementKind.FIELD); |
| 74 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION), |
| 75 ElementKind.FUNCTION); |
| 76 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS), |
| 77 ElementKind.FUNCTION_TYPE_ALIAS); |
| 78 expect(ElementKind.valueOfEngine(engine.ElementKind.GETTER), |
| 79 ElementKind.GETTER); |
| 80 expect(ElementKind.valueOfEngine(engine.ElementKind.LIBRARY), |
| 81 ElementKind.LIBRARY); |
| 82 expect(ElementKind.valueOfEngine(engine.ElementKind.METHOD), |
| 83 ElementKind.METHOD); |
| 84 expect(ElementKind.valueOfEngine(engine.ElementKind.SETTER), |
| 85 ElementKind.SETTER); |
| 86 expect(ElementKind.valueOfEngine(engine.ElementKind.TOP_LEVEL_VARIABLE), |
| 87 ElementKind.TOP_LEVEL_VARIABLE); |
| 88 expect(ElementKind.valueOfEngine(engine.ElementKind.ANGULAR_COMPONENT), |
| 89 ElementKind.UNKNOWN); |
| 90 } |
| 34 } | 91 } |
| 35 | 92 |
| 36 | 93 |
| 37 void test_ElementKind_valueOf() { | |
| 38 expect(ElementKind.valueOf(ElementKind.CLASS.name), ElementKind.CLASS); | |
| 39 expect(ElementKind.valueOf(ElementKind.CLASS_TYPE_ALIAS.name), | |
| 40 ElementKind.CLASS_TYPE_ALIAS); | |
| 41 expect(ElementKind.valueOf(ElementKind.COMPILATION_UNIT.name), | |
| 42 ElementKind.COMPILATION_UNIT); | |
| 43 expect(ElementKind.valueOf(ElementKind.CONSTRUCTOR.name), | |
| 44 ElementKind.CONSTRUCTOR); | |
| 45 expect(ElementKind.valueOf(ElementKind.FIELD.name), ElementKind.FIELD); | |
| 46 expect(ElementKind.valueOf(ElementKind.FUNCTION.name), ElementKind.FUNCTION); | |
| 47 expect(ElementKind.valueOf(ElementKind.FUNCTION_TYPE_ALIAS.name), | |
| 48 ElementKind.FUNCTION_TYPE_ALIAS); | |
| 49 expect(ElementKind.valueOf(ElementKind.GETTER.name), ElementKind.GETTER); | |
| 50 expect(ElementKind.valueOf(ElementKind.LIBRARY.name), ElementKind.LIBRARY); | |
| 51 expect(ElementKind.valueOf(ElementKind.METHOD.name), ElementKind.METHOD); | |
| 52 expect(ElementKind.valueOf(ElementKind.SETTER.name), ElementKind.SETTER); | |
| 53 expect(ElementKind.valueOf(ElementKind.TOP_LEVEL_VARIABLE.name), | |
| 54 ElementKind.TOP_LEVEL_VARIABLE); | |
| 55 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_CASE.name), | |
| 56 ElementKind.UNIT_TEST_CASE); | |
| 57 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_GROUP.name), | |
| 58 ElementKind.UNIT_TEST_GROUP); | |
| 59 expect(ElementKind.valueOf(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN); | |
| 60 expect(() { | |
| 61 ElementKind.valueOf('no-such-kind'); | |
| 62 }, throws); | |
| 63 } | |
| 64 | |
| 65 | |
| 66 void test_ElementKind_valueOfEngine() { | |
| 67 expect(ElementKind.valueOfEngine(engine.ElementKind.CLASS), | |
| 68 ElementKind.CLASS); | |
| 69 expect(ElementKind.valueOfEngine(engine.ElementKind.COMPILATION_UNIT), | |
| 70 ElementKind.COMPILATION_UNIT); | |
| 71 expect(ElementKind.valueOfEngine(engine.ElementKind.CONSTRUCTOR), | |
| 72 ElementKind.CONSTRUCTOR); | |
| 73 expect(ElementKind.valueOfEngine(engine.ElementKind.FIELD), | |
| 74 ElementKind.FIELD); | |
| 75 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION), | |
| 76 ElementKind.FUNCTION); | |
| 77 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS), | |
| 78 ElementKind.FUNCTION_TYPE_ALIAS); | |
| 79 expect(ElementKind.valueOfEngine(engine.ElementKind.GETTER), | |
| 80 ElementKind.GETTER); | |
| 81 expect(ElementKind.valueOfEngine(engine.ElementKind.LIBRARY), | |
| 82 ElementKind.LIBRARY); | |
| 83 expect(ElementKind.valueOfEngine(engine.ElementKind.METHOD), | |
| 84 ElementKind.METHOD); | |
| 85 expect(ElementKind.valueOfEngine(engine.ElementKind.SETTER), | |
| 86 ElementKind.SETTER); | |
| 87 expect(ElementKind.valueOfEngine(engine.ElementKind.TOP_LEVEL_VARIABLE), | |
| 88 ElementKind.TOP_LEVEL_VARIABLE); | |
| 89 expect(ElementKind.valueOfEngine(engine.ElementKind.ANGULAR_COMPONENT), | |
| 90 ElementKind.UNKNOWN); | |
| 91 } | |
| 92 | |
| 93 | |
| 94 @ReflectiveTestCase() | 94 @ReflectiveTestCase() |
| 95 class _ElementTest { | 95 class ElementTest extends AbstractContextTest { |
| 96 void test_fromElement_CLASS() { | 96 void test_fromElement_CLASS() { |
| 97 engine.ClassElement engineElement = new MockClassElement(); | 97 Source source = addSource('/test.dart', ''' |
| 98 when(engineElement.kind).thenReturn(engine.ElementKind.CLASS); | 98 @deprecated |
| 99 when(engineElement.nameOffset).thenReturn(1); | 99 abstract class _MyClass {}'''); |
| 100 when(engineElement.displayName).thenReturn('MyClass'); | 100 CompilationUnit unit = resolveLibraryUnit(source); |
| 101 when(engineElement.isAbstract).thenReturn(true); | 101 engine.ClassElement engineElement = findElementInUnit(unit, '_MyClass'); |
| 102 when(engineElement.isDeprecated).thenReturn(true); | |
| 103 when(engineElement.isPrivate).thenReturn(true); | |
| 104 // create notification Element | 102 // create notification Element |
| 105 Element element = new Element.fromEngine(engineElement); | 103 Element element = new Element.fromEngine(engineElement); |
| 106 expect(element.kind, ElementKind.CLASS); | 104 expect(element.kind, ElementKind.CLASS); |
| 107 expect(element.name, 'MyClass'); | 105 expect(element.name, '_MyClass'); |
| 108 expect(element.offset, 1); | 106 { |
| 109 expect(element.length, 'MyClass'.length); | 107 Location location = element.location; |
| 108 expect(location.file, '/test.dart'); |
| 109 expect(location.offset, 27); |
| 110 expect(location.length, '_MyClass'.length); |
| 111 expect(location.startLine, 2); |
| 112 expect(location.startColumn, 16); |
| 113 } |
| 110 expect(element.flags, Element.FLAG_ABSTRACT | Element.FLAG_DEPRECATED | | 114 expect(element.flags, Element.FLAG_ABSTRACT | Element.FLAG_DEPRECATED | |
| 111 Element.FLAG_PRIVATE); | 115 Element.FLAG_PRIVATE); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void test_fromElement_CONSTRUCTOR() { | 118 void test_fromElement_CONSTRUCTOR() { |
| 115 engine.ConstructorElement engineElement = new MockConstructorElement(); | 119 Source source = addSource('/test.dart', ''' |
| 116 when(engineElement.kind).thenReturn(engine.ElementKind.CONSTRUCTOR); | 120 class A { |
| 117 when(engineElement.nameOffset).thenReturn(1); | 121 const A.myConstructor(int a, [String b]); |
| 118 when(engineElement.displayName).thenReturn('myConstructor'); | 122 }'''); |
| 119 when(engineElement.isConst).thenReturn(true); | 123 CompilationUnit unit = resolveLibraryUnit(source); |
| 120 when(engineElement.isDeprecated).thenReturn(false); | 124 engine.ConstructorElement engineElement = findElementInUnit(unit, 'myConstru
ctor'); |
| 121 when(engineElement.isPrivate).thenReturn(false); | |
| 122 when(engineElement.isStatic).thenReturn(false); | |
| 123 when(engineElement.parameters).thenReturn([]); | |
| 124 { | |
| 125 engine.ParameterElement a = new MockParameterElement('int a'); | |
| 126 engine.ParameterElement b = new MockParameterElement('String b'); | |
| 127 when(b.kind).thenReturn(engine.ParameterKind.POSITIONAL); | |
| 128 when(engineElement.parameters).thenReturn([a, b]); | |
| 129 } | |
| 130 { | |
| 131 engine.DartType returnType = new MockDartType('Map<int, String>'); | |
| 132 when(engineElement.returnType).thenReturn(returnType); | |
| 133 } | |
| 134 // create notification Element | 125 // create notification Element |
| 135 Element element = new Element.fromEngine(engineElement); | 126 Element element = new Element.fromEngine(engineElement); |
| 136 expect(element.kind, ElementKind.CONSTRUCTOR); | 127 expect(element.kind, ElementKind.CONSTRUCTOR); |
| 137 expect(element.name, 'myConstructor'); | 128 expect(element.name, 'myConstructor'); |
| 138 expect(element.offset, 1); | 129 { |
| 139 expect(element.length, 'myConstructor'.length); | 130 Location location = element.location; |
| 131 expect(location.file, '/test.dart'); |
| 132 expect(location.offset, 20); |
| 133 expect(location.length, 'myConstructor'.length); |
| 134 expect(location.startLine, 2); |
| 135 expect(location.startColumn, 11); |
| 136 } |
| 140 expect(element.parameters, '(int a, [String b])'); | 137 expect(element.parameters, '(int a, [String b])'); |
| 141 expect(element.returnType, 'Map<int, String>'); | 138 expect(element.returnType, 'A'); |
| 142 expect(element.flags, Element.FLAG_CONST); | 139 expect(element.flags, Element.FLAG_CONST); |
| 143 } | 140 } |
| 144 | 141 |
| 145 void test_fromElement_FIELD() { | 142 void test_fromElement_FIELD() { |
| 146 engine.FieldElement engineElement = new MockFieldElement(); | 143 Source source = addSource('/test.dart', ''' |
| 147 when(engineElement.kind).thenReturn(engine.ElementKind.FIELD); | 144 class A { |
| 148 when(engineElement.nameOffset).thenReturn(1); | 145 static const myField = 42; |
| 149 when(engineElement.displayName).thenReturn('myField'); | 146 }'''); |
| 150 when(engineElement.isConst).thenReturn(true); | 147 CompilationUnit unit = resolveLibraryUnit(source); |
| 151 when(engineElement.isFinal).thenReturn(true); | 148 engine.FieldElement engineElement = findElementInUnit(unit, 'myField'); |
| 152 when(engineElement.isDeprecated).thenReturn(false); | |
| 153 when(engineElement.isPrivate).thenReturn(false); | |
| 154 when(engineElement.isStatic).thenReturn(true); | |
| 155 // create notification Element | 149 // create notification Element |
| 156 Element element = new Element.fromEngine(engineElement); | 150 Element element = new Element.fromEngine(engineElement); |
| 157 expect(element.kind, ElementKind.FIELD); | 151 expect(element.kind, ElementKind.FIELD); |
| 158 expect(element.name, 'myField'); | 152 expect(element.name, 'myField'); |
| 159 expect(element.offset, 1); | 153 { |
| 160 expect(element.length, 'myField'.length); | 154 Location location = element.location; |
| 155 expect(location.file, '/test.dart'); |
| 156 expect(location.offset, 25); |
| 157 expect(location.length, 'myField'.length); |
| 158 expect(location.startLine, 2); |
| 159 expect(location.startColumn, 16); |
| 160 } |
| 161 expect(element.parameters, isNull); | 161 expect(element.parameters, isNull); |
| 162 expect(element.returnType, isNull); | 162 expect(element.returnType, isNull); |
| 163 expect(element.flags, Element.FLAG_CONST | Element.FLAG_FINAL | | 163 expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC); |
| 164 Element.FLAG_STATIC); | |
| 165 } | 164 } |
| 166 | 165 |
| 167 void test_fromElement_GETTER() { | 166 void test_fromElement_GETTER() { |
| 168 engine.PropertyAccessorElement engineElement = | 167 Source source = addSource('/test.dart', ''' |
| 169 new MockPropertyAccessorElement(); | 168 class A { |
| 170 when(engineElement.kind).thenReturn(engine.ElementKind.GETTER); | 169 String myGetter => 42; |
| 171 when(engineElement.nameOffset).thenReturn(1); | 170 }'''); |
| 172 when(engineElement.displayName).thenReturn('myGetter'); | 171 CompilationUnit unit = resolveLibraryUnit(source); |
| 173 when(engineElement.isAbstract).thenReturn(false); | 172 engine.PropertyAccessorElement engineElement = findElementInUnit(unit, 'myGe
tter', engine.ElementKind.GETTER); |
| 174 when(engineElement.isDeprecated).thenReturn(true); | |
| 175 when(engineElement.isPrivate).thenReturn(false); | |
| 176 when(engineElement.isStatic).thenReturn(false); | |
| 177 when(engineElement.parameters).thenReturn([]); | |
| 178 { | |
| 179 engine.DartType returnType = new MockDartType('String'); | |
| 180 when(engineElement.returnType).thenReturn(returnType); | |
| 181 } | |
| 182 // create notification Element | 173 // create notification Element |
| 183 Element element = new Element.fromEngine(engineElement); | 174 Element element = new Element.fromEngine(engineElement); |
| 184 expect(element.kind, ElementKind.GETTER); | 175 expect(element.kind, ElementKind.GETTER); |
| 185 expect(element.name, 'myGetter'); | 176 expect(element.name, 'myGetter'); |
| 186 expect(element.offset, 1); | 177 { |
| 187 expect(element.length, 'myGetter'.length); | 178 Location location = element.location; |
| 179 expect(location.file, '/test.dart'); |
| 180 expect(location.offset, 19); |
| 181 expect(location.length, 'myGetter'.length); |
| 182 expect(location.startLine, 2); |
| 183 expect(location.startColumn, 10); |
| 184 } |
| 188 expect(element.parameters, '()'); | 185 expect(element.parameters, '()'); |
| 189 expect(element.returnType, 'String'); | 186 expect(element.returnType, 'String'); |
| 190 expect(element.flags, Element.FLAG_DEPRECATED); | 187 expect(element.flags, 0); |
| 191 } | 188 } |
| 192 | 189 |
| 193 void test_fromElement_METHOD() { | 190 void test_fromElement_METHOD() { |
| 194 engine.MethodElement engineElement = new MockMethodElement(); | 191 Source source = addSource('/test.dart', ''' |
| 195 when(engineElement.kind).thenReturn(engine.ElementKind.METHOD); | 192 class A { |
| 196 when(engineElement.nameOffset).thenReturn(1); | 193 static List<String> myMethod(int a, {String b}) { |
| 197 when(engineElement.displayName).thenReturn('myMethod'); | 194 return null; |
| 198 when(engineElement.isAbstract).thenReturn(false); | 195 } |
| 199 when(engineElement.isDeprecated).thenReturn(false); | 196 }'''); |
| 200 when(engineElement.isPrivate).thenReturn(false); | 197 CompilationUnit unit = resolveLibraryUnit(source); |
| 201 when(engineElement.isStatic).thenReturn(true); | 198 engine.MethodElement engineElement = findElementInUnit(unit, 'myMethod'); |
| 202 { | |
| 203 engine.ParameterElement a = new MockParameterElement('int a'); | |
| 204 engine.ParameterElement b = new MockParameterElement('String b'); | |
| 205 when(b.kind).thenReturn(engine.ParameterKind.NAMED); | |
| 206 when(engineElement.parameters).thenReturn([a, b]); | |
| 207 } | |
| 208 { | |
| 209 engine.DartType returnType = new MockDartType('List<String>'); | |
| 210 when(engineElement.returnType).thenReturn(returnType); | |
| 211 } | |
| 212 // create notification Element | 199 // create notification Element |
| 213 Element element = new Element.fromEngine(engineElement); | 200 Element element = new Element.fromEngine(engineElement); |
| 214 expect(element.kind, ElementKind.METHOD); | 201 expect(element.kind, ElementKind.METHOD); |
| 215 expect(element.name, 'myMethod'); | 202 expect(element.name, 'myMethod'); |
| 216 expect(element.offset, 1); | 203 { |
| 217 expect(element.length, 'myMethod'.length); | 204 Location location = element.location; |
| 205 expect(location.file, '/test.dart'); |
| 206 expect(location.offset, 32); |
| 207 expect(location.length, 'myGetter'.length); |
| 208 expect(location.startLine, 2); |
| 209 expect(location.startColumn, 23); |
| 210 } |
| 218 expect(element.parameters, '(int a, {String b})'); | 211 expect(element.parameters, '(int a, {String b})'); |
| 219 expect(element.returnType, 'List<String>'); | 212 expect(element.returnType, 'List<String>'); |
| 220 expect(element.flags, Element.FLAG_STATIC); | 213 expect(element.flags, Element.FLAG_STATIC); |
| 221 } | 214 } |
| 222 | 215 |
| 223 void test_fromJson() { | 216 void test_fromJson() { |
| 224 var flags = Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | | 217 var flags = Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | |
| 225 Element.FLAG_STATIC; | 218 Element.FLAG_STATIC; |
| 226 var json = { | 219 var json = { |
| 227 KIND: 'METHOD', | 220 KIND: 'METHOD', |
| 228 NAME: 'my name', | 221 NAME: 'my name', |
| 229 OFFSET: 1, | 222 LOCATION: { |
| 230 LENGTH: 2, | 223 FILE: '/project/file.dart', |
| 224 OFFSET: 1, |
| 225 LENGTH: 2, |
| 226 START_LINE: 3, |
| 227 START_COLUMN: 4, |
| 228 }, |
| 231 FLAGS: flags, | 229 FLAGS: flags, |
| 232 PARAMETERS: '(int a, String b)', | 230 PARAMETERS: '(int a, String b)', |
| 233 RETURN_TYPE: 'List<String>' | 231 RETURN_TYPE: 'List<String>' |
| 234 }; | 232 }; |
| 235 Element element = new Element.fromJson(json); | 233 Element element = new Element.fromJson(json); |
| 236 expect(element.kind, ElementKind.METHOD); | 234 expect(element.kind, ElementKind.METHOD); |
| 237 expect(element.name, 'my name'); | 235 expect(element.name, 'my name'); |
| 238 expect(element.offset, 1); | 236 { |
| 239 expect(element.length, 2); | 237 Location location = element.location; |
| 238 expect(location.file, '/project/file.dart'); |
| 239 expect(location.offset, 1); |
| 240 expect(location.length, 2); |
| 241 expect(location.startLine, 3); |
| 242 expect(location.startColumn, 4); |
| 243 } |
| 240 expect(element.flags, flags); | 244 expect(element.flags, flags); |
| 241 expect(element.isAbstract, isFalse); | 245 expect(element.isAbstract, isFalse); |
| 242 expect(element.isConst, isFalse); | 246 expect(element.isConst, isFalse); |
| 243 expect(element.isDeprecated, isTrue); | 247 expect(element.isDeprecated, isTrue); |
| 244 expect(element.isFinal, isFalse); | 248 expect(element.isFinal, isFalse); |
| 245 expect(element.isPrivate, isTrue); | 249 expect(element.isPrivate, isTrue); |
| 246 expect(element.isStatic, isTrue); | 250 expect(element.isStatic, isTrue); |
| 247 } | 251 } |
| 248 | 252 |
| 249 void test_toJson() { | 253 void test_toJson() { |
| 250 var json = { | 254 var json = { |
| 251 KIND: 'METHOD', | 255 KIND: 'METHOD', |
| 252 NAME: 'my name', | 256 NAME: 'my name', |
| 253 OFFSET: 1, | 257 LOCATION: { |
| 254 LENGTH: 2, | 258 FILE: '/project/file.dart', |
| 259 OFFSET: 1, |
| 260 LENGTH: 2, |
| 261 START_LINE: 3, |
| 262 START_COLUMN: 4, |
| 263 }, |
| 255 FLAGS: Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | | 264 FLAGS: Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | |
| 256 Element.FLAG_STATIC, | 265 Element.FLAG_STATIC, |
| 257 PARAMETERS: '(int a, String b)', | 266 PARAMETERS: '(int a, String b)', |
| 258 RETURN_TYPE: 'List<String>' | 267 RETURN_TYPE: 'List<String>' |
| 259 }; | 268 }; |
| 260 Element element = new Element.fromJson(json); | 269 Element element = new Element.fromJson(json); |
| 261 expect(element.toJson(), equals(json)); | 270 expect(element.toJson(), equals(json)); |
| 262 } | 271 } |
| 263 } | 272 } |
| OLD | NEW |