| 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 engine.all_the_rest_test; | 5 library analyzer.test.generated.all_the_rest_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; |
| 11 import 'package:analyzer/error/error.dart'; |
| 12 import 'package:analyzer/error/listener.dart'; |
| 13 import 'package:analyzer/file_system/file_system.dart'; |
| 14 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 7 import 'package:analyzer/file_system/physical_file_system.dart'; | 15 import 'package:analyzer/file_system/physical_file_system.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart' hide ConstantEvaluator; | 16 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 17 import 'package:analyzer/src/dart/ast/utilities.dart' hide ConstantEvaluator; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 18 import 'package:analyzer/src/dart/element/builder.dart'; |
| 19 import 'package:analyzer/src/dart/element/element.dart'; |
| 20 import 'package:analyzer/src/dart/sdk/sdk.dart' hide SdkLibrariesReader; |
| 21 import 'package:analyzer/src/error/codes.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 22 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/error.dart'; | |
| 13 import 'package:analyzer/src/generated/html.dart' as ht; | |
| 14 import 'package:analyzer/src/generated/java_core.dart'; | |
| 15 import 'package:analyzer/src/generated/java_engine.dart'; | |
| 16 import 'package:analyzer/src/generated/java_engine_io.dart'; | 23 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 17 import 'package:analyzer/src/generated/java_io.dart'; | 24 import 'package:analyzer/src/generated/java_io.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 25 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/scanner.dart'; | |
| 20 import 'package:analyzer/src/generated/sdk.dart'; | 26 import 'package:analyzer/src/generated/sdk.dart'; |
| 21 import 'package:analyzer/src/generated/sdk_io.dart'; | 27 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 22 import 'package:analyzer/src/generated/source.dart'; | 28 import 'package:analyzer/src/generated/source.dart'; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 29 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 30 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 31 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/html_factory.dart'; | |
| 27 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; | 32 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; |
| 28 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 33 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 29 import 'package:analyzer/src/generated/utilities_collection.dart'; | |
| 30 import 'package:analyzer/src/generated/utilities_dart.dart'; | 34 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 31 import 'package:analyzer/src/task/dart.dart'; | 35 import 'package:analyzer/src/source/source_resource.dart'; |
| 32 import 'package:path/path.dart'; | 36 import 'package:path/path.dart' hide equals; |
| 37 import 'package:source_span/source_span.dart'; |
| 38 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 33 import 'package:unittest/unittest.dart'; | 39 import 'package:unittest/unittest.dart'; |
| 34 | 40 |
| 35 import '../reflective_tests.dart'; | |
| 36 import '../utils.dart'; | 41 import '../utils.dart'; |
| 37 import 'engine_test.dart'; | |
| 38 import 'parser_test.dart'; | 42 import 'parser_test.dart'; |
| 39 import 'resolver_test.dart'; | 43 import 'resolver_test_case.dart'; |
| 40 import 'test_support.dart'; | 44 import 'test_support.dart'; |
| 41 | 45 |
| 42 main() { | 46 main() { |
| 43 initializeTestEnvironment(); | 47 initializeTestEnvironment(); |
| 44 runReflectiveTests(ConstantEvaluatorTest); | 48 defineReflectiveTests(ContentCacheTest); |
| 45 runReflectiveTests(ConstantFinderTest); | 49 // ignore: deprecated_member_use |
| 46 runReflectiveTests(ConstantValueComputerTest); | 50 defineReflectiveTests(CustomUriResolverTest); |
| 47 runReflectiveTests(ConstantVisitorTest); | 51 defineReflectiveTests(DartUriResolverTest); |
| 48 runReflectiveTests(ContentCacheTest); | 52 // ignore: deprecated_member_use |
| 49 runReflectiveTests(CustomUriResolverTest); | 53 defineReflectiveTests(DirectoryBasedDartSdkTest); |
| 50 runReflectiveTests(DartObjectImplTest); | 54 // ignore: deprecated_member_use |
| 51 runReflectiveTests(DartUriResolverTest); | 55 defineReflectiveTests(DirectoryBasedSourceContainerTest); |
| 52 runReflectiveTests(DeclaredVariablesTest); | 56 defineReflectiveTests(ElementBuilderTest); |
| 53 runReflectiveTests(DirectoryBasedDartSdkTest); | 57 defineReflectiveTests(ElementLocatorTest); |
| 54 runReflectiveTests(DirectoryBasedSourceContainerTest); | 58 defineReflectiveTests(EnumMemberBuilderTest); |
| 55 runReflectiveTests(ElementBuilderTest); | 59 defineReflectiveTests(ErrorReporterTest); |
| 56 runReflectiveTests(ElementLocatorTest); | 60 defineReflectiveTests(ErrorSeverityTest); |
| 57 runReflectiveTests(EnumMemberBuilderTest); | 61 defineReflectiveTests(ExitDetectorTest); |
| 58 runReflectiveTests(ErrorReporterTest); | 62 defineReflectiveTests(ExitDetectorTest2); |
| 59 runReflectiveTests(ErrorSeverityTest); | 63 defineReflectiveTests(FileBasedSourceTest); |
| 60 runReflectiveTests(ExitDetectorTest); | 64 defineReflectiveTests(ResolveRelativeUriTest); |
| 61 runReflectiveTests(ExitDetectorTest2); | 65 // ignore: deprecated_member_use |
| 62 runReflectiveTests(FileBasedSourceTest); | 66 defineReflectiveTests(SDKLibrariesReaderTest); |
| 63 runReflectiveTests(FileUriResolverTest); | 67 defineReflectiveTests(UriKindTest); |
| 64 if (!AnalysisEngine.instance.useTaskModel) { | |
| 65 runReflectiveTests(HtmlParserTest); | |
| 66 runReflectiveTests(HtmlTagInfoBuilderTest); | |
| 67 runReflectiveTests(HtmlUnitBuilderTest); | |
| 68 runReflectiveTests(HtmlWarningCodeTest); | |
| 69 } | |
| 70 runReflectiveTests(ReferenceFinderTest); | |
| 71 runReflectiveTests(SDKLibrariesReaderTest); | |
| 72 runReflectiveTests(ToSourceVisitorTest); | |
| 73 runReflectiveTests(UriKindTest); | |
| 74 runReflectiveTests(StringScannerTest); | |
| 75 } | |
| 76 | |
| 77 abstract class AbstractScannerTest { | |
| 78 ht.AbstractScanner newScanner(String input); | |
| 79 | |
| 80 void test_tokenize_attribute() { | |
| 81 _tokenize("<html bob=\"one two\">", <Object>[ | |
| 82 ht.TokenType.LT, | |
| 83 "html", | |
| 84 "bob", | |
| 85 ht.TokenType.EQ, | |
| 86 "\"one two\"", | |
| 87 ht.TokenType.GT | |
| 88 ]); | |
| 89 } | |
| 90 | |
| 91 void test_tokenize_comment() { | |
| 92 _tokenize("<!-- foo -->", <Object>["<!-- foo -->"]); | |
| 93 } | |
| 94 | |
| 95 void test_tokenize_comment_incomplete() { | |
| 96 _tokenize("<!-- foo", <Object>["<!-- foo"]); | |
| 97 } | |
| 98 | |
| 99 void test_tokenize_comment_with_gt() { | |
| 100 _tokenize("<!-- foo > -> -->", <Object>["<!-- foo > -> -->"]); | |
| 101 } | |
| 102 | |
| 103 void test_tokenize_declaration() { | |
| 104 _tokenize("<! foo ><html>", | |
| 105 <Object>["<! foo >", ht.TokenType.LT, "html", ht.TokenType.GT]); | |
| 106 } | |
| 107 | |
| 108 void test_tokenize_declaration_malformed() { | |
| 109 _tokenize("<! foo /><html>", | |
| 110 <Object>["<! foo />", ht.TokenType.LT, "html", ht.TokenType.GT]); | |
| 111 } | |
| 112 | |
| 113 void test_tokenize_directive_incomplete() { | |
| 114 _tokenize2("<? \nfoo", <Object>["<? \nfoo"], <int>[0, 4]); | |
| 115 } | |
| 116 | |
| 117 void test_tokenize_directive_xml() { | |
| 118 _tokenize("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>", | |
| 119 <Object>["<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"]); | |
| 120 } | |
| 121 | |
| 122 void test_tokenize_directives_incomplete_with_newline() { | |
| 123 _tokenize2("<! \nfoo", <Object>["<! \nfoo"], <int>[0, 4]); | |
| 124 } | |
| 125 | |
| 126 void test_tokenize_empty() { | |
| 127 _tokenize("", <Object>[]); | |
| 128 } | |
| 129 | |
| 130 void test_tokenize_lt() { | |
| 131 _tokenize("<", <Object>[ht.TokenType.LT]); | |
| 132 } | |
| 133 | |
| 134 void test_tokenize_script_embedded_tags() { | |
| 135 _tokenize("<script> <p></p></script>", <Object>[ | |
| 136 ht.TokenType.LT, | |
| 137 "script", | |
| 138 ht.TokenType.GT, | |
| 139 " <p></p>", | |
| 140 ht.TokenType.LT_SLASH, | |
| 141 "script", | |
| 142 ht.TokenType.GT | |
| 143 ]); | |
| 144 } | |
| 145 | |
| 146 void test_tokenize_script_embedded_tags2() { | |
| 147 _tokenize("<script> <p></p><</script>", <Object>[ | |
| 148 ht.TokenType.LT, | |
| 149 "script", | |
| 150 ht.TokenType.GT, | |
| 151 " <p></p><", | |
| 152 ht.TokenType.LT_SLASH, | |
| 153 "script", | |
| 154 ht.TokenType.GT | |
| 155 ]); | |
| 156 } | |
| 157 | |
| 158 void test_tokenize_script_embedded_tags3() { | |
| 159 _tokenize("<script> <p></p></</script>", <Object>[ | |
| 160 ht.TokenType.LT, | |
| 161 "script", | |
| 162 ht.TokenType.GT, | |
| 163 " <p></p></", | |
| 164 ht.TokenType.LT_SLASH, | |
| 165 "script", | |
| 166 ht.TokenType.GT | |
| 167 ]); | |
| 168 } | |
| 169 | |
| 170 void test_tokenize_script_partial() { | |
| 171 _tokenize("<script> <p> ", | |
| 172 <Object>[ht.TokenType.LT, "script", ht.TokenType.GT, " <p> "]); | |
| 173 } | |
| 174 | |
| 175 void test_tokenize_script_partial2() { | |
| 176 _tokenize("<script> <p> <", | |
| 177 <Object>[ht.TokenType.LT, "script", ht.TokenType.GT, " <p> <"]); | |
| 178 } | |
| 179 | |
| 180 void test_tokenize_script_partial3() { | |
| 181 _tokenize("<script> <p> </", | |
| 182 <Object>[ht.TokenType.LT, "script", ht.TokenType.GT, " <p> </"]); | |
| 183 } | |
| 184 | |
| 185 void test_tokenize_script_ref() { | |
| 186 _tokenize("<script source='some.dart'/> <p>", <Object>[ | |
| 187 ht.TokenType.LT, | |
| 188 "script", | |
| 189 "source", | |
| 190 ht.TokenType.EQ, | |
| 191 "'some.dart'", | |
| 192 ht.TokenType.SLASH_GT, | |
| 193 " ", | |
| 194 ht.TokenType.LT, | |
| 195 "p", | |
| 196 ht.TokenType.GT | |
| 197 ]); | |
| 198 } | |
| 199 | |
| 200 void test_tokenize_script_with_newline() { | |
| 201 _tokenize2("<script> <p>\n </script>", <Object>[ | |
| 202 ht.TokenType.LT, | |
| 203 "script", | |
| 204 ht.TokenType.GT, | |
| 205 " <p>\n ", | |
| 206 ht.TokenType.LT_SLASH, | |
| 207 "script", | |
| 208 ht.TokenType.GT | |
| 209 ], <int>[ | |
| 210 0, | |
| 211 13 | |
| 212 ]); | |
| 213 } | |
| 214 | |
| 215 void test_tokenize_spaces_and_newlines() { | |
| 216 ht.Token token = _tokenize2( | |
| 217 " < html \n bob = 'joe\n' >\n <\np > one \r\n two <!-- \rfoo --> </ p >
</ html > ", | |
| 218 <Object>[ | |
| 219 " ", | |
| 220 ht.TokenType.LT, | |
| 221 "html", | |
| 222 "bob", | |
| 223 ht.TokenType.EQ, | |
| 224 "'joe\n'", | |
| 225 ht.TokenType.GT, | |
| 226 "\n ", | |
| 227 ht.TokenType.LT, | |
| 228 "p", | |
| 229 ht.TokenType.GT, | |
| 230 " one \r\n two ", | |
| 231 "<!-- \rfoo -->", | |
| 232 " ", | |
| 233 ht.TokenType.LT_SLASH, | |
| 234 "p", | |
| 235 ht.TokenType.GT, | |
| 236 " ", | |
| 237 ht.TokenType.LT_SLASH, | |
| 238 "html", | |
| 239 ht.TokenType.GT, | |
| 240 " " | |
| 241 ], | |
| 242 <int>[ | |
| 243 0, | |
| 244 9, | |
| 245 21, | |
| 246 25, | |
| 247 28, | |
| 248 38, | |
| 249 49 | |
| 250 ]); | |
| 251 token = token.next; | |
| 252 expect(token.offset, 1); | |
| 253 token = token.next; | |
| 254 expect(token.offset, 3); | |
| 255 token = token.next; | |
| 256 expect(token.offset, 10); | |
| 257 } | |
| 258 | |
| 259 void test_tokenize_string() { | |
| 260 _tokenize("<p bob=\"foo\">", <Object>[ | |
| 261 ht.TokenType.LT, | |
| 262 "p", | |
| 263 "bob", | |
| 264 ht.TokenType.EQ, | |
| 265 "\"foo\"", | |
| 266 ht.TokenType.GT | |
| 267 ]); | |
| 268 } | |
| 269 | |
| 270 void test_tokenize_string_partial() { | |
| 271 _tokenize("<p bob=\"foo", | |
| 272 <Object>[ht.TokenType.LT, "p", "bob", ht.TokenType.EQ, "\"foo"]); | |
| 273 } | |
| 274 | |
| 275 void test_tokenize_string_single_quote() { | |
| 276 _tokenize("<p bob='foo'>", <Object>[ | |
| 277 ht.TokenType.LT, | |
| 278 "p", | |
| 279 "bob", | |
| 280 ht.TokenType.EQ, | |
| 281 "'foo'", | |
| 282 ht.TokenType.GT | |
| 283 ]); | |
| 284 } | |
| 285 | |
| 286 void test_tokenize_string_single_quote_partial() { | |
| 287 _tokenize("<p bob='foo", | |
| 288 <Object>[ht.TokenType.LT, "p", "bob", ht.TokenType.EQ, "'foo"]); | |
| 289 } | |
| 290 | |
| 291 void test_tokenize_tag_begin_end() { | |
| 292 _tokenize("<html></html>", <Object>[ | |
| 293 ht.TokenType.LT, | |
| 294 "html", | |
| 295 ht.TokenType.GT, | |
| 296 ht.TokenType.LT_SLASH, | |
| 297 "html", | |
| 298 ht.TokenType.GT | |
| 299 ]); | |
| 300 } | |
| 301 | |
| 302 void test_tokenize_tag_begin_only() { | |
| 303 ht.Token token = | |
| 304 _tokenize("<html>", <Object>[ht.TokenType.LT, "html", ht.TokenType.GT]); | |
| 305 token = token.next; | |
| 306 expect(token.offset, 1); | |
| 307 } | |
| 308 | |
| 309 void test_tokenize_tag_incomplete_with_special_characters() { | |
| 310 _tokenize("<br-a_b", <Object>[ht.TokenType.LT, "br-a_b"]); | |
| 311 } | |
| 312 | |
| 313 void test_tokenize_tag_self_contained() { | |
| 314 _tokenize("<br/>", <Object>[ht.TokenType.LT, "br", ht.TokenType.SLASH_GT]); | |
| 315 } | |
| 316 | |
| 317 void test_tokenize_tags_wellformed() { | |
| 318 _tokenize("<html><p>one two</p></html>", <Object>[ | |
| 319 ht.TokenType.LT, | |
| 320 "html", | |
| 321 ht.TokenType.GT, | |
| 322 ht.TokenType.LT, | |
| 323 "p", | |
| 324 ht.TokenType.GT, | |
| 325 "one two", | |
| 326 ht.TokenType.LT_SLASH, | |
| 327 "p", | |
| 328 ht.TokenType.GT, | |
| 329 ht.TokenType.LT_SLASH, | |
| 330 "html", | |
| 331 ht.TokenType.GT | |
| 332 ]); | |
| 333 } | |
| 334 | |
| 335 /** | |
| 336 * Given an object representing an expected token, answer the expected token t
ype. | |
| 337 * | |
| 338 * @param count the token count for error reporting | |
| 339 * @param expected the object representing an expected token | |
| 340 * @return the expected token type | |
| 341 */ | |
| 342 ht.TokenType _getExpectedTokenType(int count, Object expected) { | |
| 343 if (expected is ht.TokenType) { | |
| 344 return expected; | |
| 345 } | |
| 346 if (expected is String) { | |
| 347 String lexeme = expected; | |
| 348 if (lexeme.startsWith("\"") || lexeme.startsWith("'")) { | |
| 349 return ht.TokenType.STRING; | |
| 350 } | |
| 351 if (lexeme.startsWith("<!--")) { | |
| 352 return ht.TokenType.COMMENT; | |
| 353 } | |
| 354 if (lexeme.startsWith("<!")) { | |
| 355 return ht.TokenType.DECLARATION; | |
| 356 } | |
| 357 if (lexeme.startsWith("<?")) { | |
| 358 return ht.TokenType.DIRECTIVE; | |
| 359 } | |
| 360 if (_isTag(lexeme)) { | |
| 361 return ht.TokenType.TAG; | |
| 362 } | |
| 363 return ht.TokenType.TEXT; | |
| 364 } | |
| 365 fail( | |
| 366 "Unknown expected token $count: ${expected != null ? expected.runtimeTyp
e : "null"}"); | |
| 367 return null; | |
| 368 } | |
| 369 | |
| 370 bool _isTag(String lexeme) { | |
| 371 if (lexeme.length == 0 || !Character.isLetter(lexeme.codeUnitAt(0))) { | |
| 372 return false; | |
| 373 } | |
| 374 for (int index = 1; index < lexeme.length; index++) { | |
| 375 int ch = lexeme.codeUnitAt(index); | |
| 376 if (!Character.isLetterOrDigit(ch) && ch != 0x2D && ch != 0x5F) { | |
| 377 return false; | |
| 378 } | |
| 379 } | |
| 380 return true; | |
| 381 } | |
| 382 | |
| 383 ht.Token _tokenize(String input, List<Object> expectedTokens) => | |
| 384 _tokenize2(input, expectedTokens, <int>[0]); | |
| 385 ht.Token _tokenize2( | |
| 386 String input, List<Object> expectedTokens, List<int> expectedLineStarts) { | |
| 387 ht.AbstractScanner scanner = newScanner(input); | |
| 388 scanner.passThroughElements = <String>["script"]; | |
| 389 int count = 0; | |
| 390 ht.Token firstToken = scanner.tokenize(); | |
| 391 ht.Token token = firstToken; | |
| 392 ht.Token previousToken = token.previous; | |
| 393 expect(previousToken.type == ht.TokenType.EOF, isTrue); | |
| 394 expect(previousToken.previous, same(previousToken)); | |
| 395 expect(previousToken.offset, -1); | |
| 396 expect(previousToken.next, same(token)); | |
| 397 expect(token.offset, 0); | |
| 398 while (token.type != ht.TokenType.EOF) { | |
| 399 if (count == expectedTokens.length) { | |
| 400 fail("too many parsed tokens"); | |
| 401 } | |
| 402 Object expected = expectedTokens[count]; | |
| 403 ht.TokenType expectedTokenType = _getExpectedTokenType(count, expected); | |
| 404 expect(token.type, same(expectedTokenType), reason: "token $count"); | |
| 405 if (expectedTokenType.lexeme != null) { | |
| 406 expect(token.lexeme, expectedTokenType.lexeme, reason: "token $count"); | |
| 407 } else { | |
| 408 expect(token.lexeme, expected, reason: "token $count"); | |
| 409 } | |
| 410 count++; | |
| 411 previousToken = token; | |
| 412 token = token.next; | |
| 413 expect(token.previous, same(previousToken)); | |
| 414 } | |
| 415 expect(token.next, same(token)); | |
| 416 expect(token.offset, input.length); | |
| 417 if (count != expectedTokens.length) { | |
| 418 expect(false, isTrue, reason: "not enough parsed tokens"); | |
| 419 } | |
| 420 List<int> lineStarts = scanner.lineStarts; | |
| 421 bool success = expectedLineStarts.length == lineStarts.length; | |
| 422 if (success) { | |
| 423 for (int i = 0; i < lineStarts.length; i++) { | |
| 424 if (expectedLineStarts[i] != lineStarts[i]) { | |
| 425 success = false; | |
| 426 break; | |
| 427 } | |
| 428 } | |
| 429 } | |
| 430 if (!success) { | |
| 431 StringBuffer buffer = new StringBuffer(); | |
| 432 buffer.write("Expected line starts "); | |
| 433 for (int start in expectedLineStarts) { | |
| 434 buffer.write(start); | |
| 435 buffer.write(", "); | |
| 436 } | |
| 437 buffer.write(" but found "); | |
| 438 for (int start in lineStarts) { | |
| 439 buffer.write(start); | |
| 440 buffer.write(", "); | |
| 441 } | |
| 442 fail(buffer.toString()); | |
| 443 } | |
| 444 return firstToken; | |
| 445 } | |
| 446 } | 68 } |
| 447 | 69 |
| 448 /** | 70 /** |
| 449 * Implementation of [ConstantEvaluationValidator] used during unit tests; | 71 * Create a tiny mock SDK for use in URI resolution tests. |
| 450 * verifies that any nodes referenced during constant evaluation are present in | |
| 451 * the dependency graph. | |
| 452 */ | 72 */ |
| 453 class ConstantEvaluationValidator_ForTest | 73 DartSdk _createSdk() { |
| 454 implements ConstantEvaluationValidator { | 74 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 455 ConstantValueComputer computer; | 75 String sdkFolderName = |
| 456 | 76 resourceProvider.pathContext.separator == '/' ? '/sdk' : r'C:\sdk'; |
| 457 ConstantEvaluationTarget _nodeBeingEvaluated; | 77 Folder sdkFolder = resourceProvider.newFolder(sdkFolderName); |
| 458 | 78 expect(sdkFolder, isNotNull); |
| 459 @override | 79 resourceProvider.newFile( |
| 460 void beforeComputeValue(ConstantEvaluationTarget constant) { | 80 resourceProvider.pathContext.join(sdkFolderName, 'lib', '_internal', |
| 461 _nodeBeingEvaluated = constant; | 81 'sdk_library_metadata', 'lib', 'libraries.dart'), |
| 462 } | 82 ''' |
| 463 | 83 const Map<String, LibraryInfo> libraries = const { |
| 464 @override | 84 "core": const LibraryInfo("core/core.dart") |
| 465 void beforeGetConstantInitializers(ConstructorElement constructor) { | 85 }; |
| 466 // Make sure we properly recorded the dependency. | |
| 467 expect( | |
| 468 computer.referenceGraph.containsPath(_nodeBeingEvaluated, constructor), | |
| 469 isTrue); | |
| 470 } | |
| 471 | |
| 472 @override | |
| 473 void beforeGetEvaluationResult(ConstantEvaluationTarget constant) { | |
| 474 // Make sure we properly recorded the dependency. | |
| 475 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, constant), | |
| 476 isTrue); | |
| 477 } | |
| 478 | |
| 479 @override | |
| 480 void beforeGetFieldEvaluationResult(FieldElementImpl field) { | |
| 481 // Make sure we properly recorded the dependency. | |
| 482 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, field), | |
| 483 isTrue); | |
| 484 } | |
| 485 | |
| 486 @override | |
| 487 void beforeGetParameterDefault(ParameterElement parameter) { | |
| 488 // Make sure we properly recorded the dependency. | |
| 489 expect(computer.referenceGraph.containsPath(_nodeBeingEvaluated, parameter), | |
| 490 isTrue); | |
| 491 } | |
| 492 } | |
| 493 | |
| 494 @reflectiveTest | |
| 495 class ConstantEvaluatorTest extends ResolverTestCase { | |
| 496 void fail_constructor() { | |
| 497 EvaluationResult result = _getExpressionValue("?"); | |
| 498 expect(result.isValid, isTrue); | |
| 499 DartObject value = result.value; | |
| 500 expect(value, null); | |
| 501 } | |
| 502 | |
| 503 void fail_identifier_class() { | |
| 504 EvaluationResult result = _getExpressionValue("?"); | |
| 505 expect(result.isValid, isTrue); | |
| 506 DartObject value = result.value; | |
| 507 expect(value, null); | |
| 508 } | |
| 509 | |
| 510 void fail_identifier_function() { | |
| 511 EvaluationResult result = _getExpressionValue("?"); | |
| 512 expect(result.isValid, isTrue); | |
| 513 DartObject value = result.value; | |
| 514 expect(value, null); | |
| 515 } | |
| 516 | |
| 517 void fail_identifier_static() { | |
| 518 EvaluationResult result = _getExpressionValue("?"); | |
| 519 expect(result.isValid, isTrue); | |
| 520 DartObject value = result.value; | |
| 521 expect(value, null); | |
| 522 } | |
| 523 | |
| 524 void fail_identifier_staticMethod() { | |
| 525 EvaluationResult result = _getExpressionValue("?"); | |
| 526 expect(result.isValid, isTrue); | |
| 527 DartObject value = result.value; | |
| 528 expect(value, null); | |
| 529 } | |
| 530 | |
| 531 void fail_identifier_topLevel() { | |
| 532 EvaluationResult result = _getExpressionValue("?"); | |
| 533 expect(result.isValid, isTrue); | |
| 534 DartObject value = result.value; | |
| 535 expect(value, null); | |
| 536 } | |
| 537 | |
| 538 void fail_identifier_typeParameter() { | |
| 539 EvaluationResult result = _getExpressionValue("?"); | |
| 540 expect(result.isValid, isTrue); | |
| 541 DartObject value = result.value; | |
| 542 expect(value, null); | |
| 543 } | |
| 544 | |
| 545 void fail_prefixedIdentifier_invalid() { | |
| 546 EvaluationResult result = _getExpressionValue("?"); | |
| 547 expect(result.isValid, isTrue); | |
| 548 DartObject value = result.value; | |
| 549 expect(value, null); | |
| 550 } | |
| 551 | |
| 552 void fail_prefixedIdentifier_valid() { | |
| 553 EvaluationResult result = _getExpressionValue("?"); | |
| 554 expect(result.isValid, isTrue); | |
| 555 DartObject value = result.value; | |
| 556 expect(value, null); | |
| 557 } | |
| 558 | |
| 559 void fail_propertyAccess_invalid() { | |
| 560 EvaluationResult result = _getExpressionValue("?"); | |
| 561 expect(result.isValid, isTrue); | |
| 562 DartObject value = result.value; | |
| 563 expect(value, null); | |
| 564 } | |
| 565 | |
| 566 void fail_propertyAccess_valid() { | |
| 567 EvaluationResult result = _getExpressionValue("?"); | |
| 568 expect(result.isValid, isTrue); | |
| 569 DartObject value = result.value; | |
| 570 expect(value, null); | |
| 571 } | |
| 572 | |
| 573 void fail_simpleIdentifier_invalid() { | |
| 574 EvaluationResult result = _getExpressionValue("?"); | |
| 575 expect(result.isValid, isTrue); | |
| 576 DartObject value = result.value; | |
| 577 expect(value, null); | |
| 578 } | |
| 579 | |
| 580 void fail_simpleIdentifier_valid() { | |
| 581 EvaluationResult result = _getExpressionValue("?"); | |
| 582 expect(result.isValid, isTrue); | |
| 583 DartObject value = result.value; | |
| 584 expect(value, null); | |
| 585 } | |
| 586 | |
| 587 void test_bitAnd_int_int() { | |
| 588 _assertValue3(74 & 42, "74 & 42"); | |
| 589 } | |
| 590 | |
| 591 void test_bitNot() { | |
| 592 _assertValue3(~42, "~42"); | |
| 593 } | |
| 594 | |
| 595 void test_bitOr_int_int() { | |
| 596 _assertValue3(74 | 42, "74 | 42"); | |
| 597 } | |
| 598 | |
| 599 void test_bitXor_int_int() { | |
| 600 _assertValue3(74 ^ 42, "74 ^ 42"); | |
| 601 } | |
| 602 | |
| 603 void test_divide_double_double() { | |
| 604 _assertValue2(3.2 / 2.3, "3.2 / 2.3"); | |
| 605 } | |
| 606 | |
| 607 void test_divide_double_double_byZero() { | |
| 608 EvaluationResult result = _getExpressionValue("3.2 / 0.0"); | |
| 609 expect(result.isValid, isTrue); | |
| 610 DartObject value = result.value; | |
| 611 expect(value.type.name, "double"); | |
| 612 expect(value.toDoubleValue().isInfinite, isTrue); | |
| 613 } | |
| 614 | |
| 615 void test_divide_int_int() { | |
| 616 _assertValue2(1.5, "3 / 2"); | |
| 617 } | |
| 618 | |
| 619 void test_divide_int_int_byZero() { | |
| 620 EvaluationResult result = _getExpressionValue("3 / 0"); | |
| 621 expect(result.isValid, isTrue); | |
| 622 } | |
| 623 | |
| 624 void test_equal_boolean_boolean() { | |
| 625 _assertValue(false, "true == false"); | |
| 626 } | |
| 627 | |
| 628 void test_equal_int_int() { | |
| 629 _assertValue(false, "2 == 3"); | |
| 630 } | |
| 631 | |
| 632 void test_equal_invalidLeft() { | |
| 633 EvaluationResult result = _getExpressionValue("a == 3"); | |
| 634 expect(result.isValid, isFalse); | |
| 635 } | |
| 636 | |
| 637 void test_equal_invalidRight() { | |
| 638 EvaluationResult result = _getExpressionValue("2 == a"); | |
| 639 expect(result.isValid, isFalse); | |
| 640 } | |
| 641 | |
| 642 void test_equal_string_string() { | |
| 643 _assertValue(false, "'a' == 'b'"); | |
| 644 } | |
| 645 | |
| 646 void test_greaterThan_int_int() { | |
| 647 _assertValue(false, "2 > 3"); | |
| 648 } | |
| 649 | |
| 650 void test_greaterThanOrEqual_int_int() { | |
| 651 _assertValue(false, "2 >= 3"); | |
| 652 } | |
| 653 | |
| 654 void test_leftShift_int_int() { | |
| 655 _assertValue3(64, "16 << 2"); | |
| 656 } | |
| 657 | |
| 658 void test_lessThan_int_int() { | |
| 659 _assertValue(true, "2 < 3"); | |
| 660 } | |
| 661 | |
| 662 void test_lessThanOrEqual_int_int() { | |
| 663 _assertValue(true, "2 <= 3"); | |
| 664 } | |
| 665 | |
| 666 void test_literal_boolean_false() { | |
| 667 _assertValue(false, "false"); | |
| 668 } | |
| 669 | |
| 670 void test_literal_boolean_true() { | |
| 671 _assertValue(true, "true"); | |
| 672 } | |
| 673 | |
| 674 void test_literal_list() { | |
| 675 EvaluationResult result = _getExpressionValue("const ['a', 'b', 'c']"); | |
| 676 expect(result.isValid, isTrue); | |
| 677 } | |
| 678 | |
| 679 void test_literal_map() { | |
| 680 EvaluationResult result = | |
| 681 _getExpressionValue("const {'a' : 'm', 'b' : 'n', 'c' : 'o'}"); | |
| 682 expect(result.isValid, isTrue); | |
| 683 } | |
| 684 | |
| 685 void test_literal_null() { | |
| 686 EvaluationResult result = _getExpressionValue("null"); | |
| 687 expect(result.isValid, isTrue); | |
| 688 DartObject value = result.value; | |
| 689 expect(value.isNull, isTrue); | |
| 690 } | |
| 691 | |
| 692 void test_literal_number_double() { | |
| 693 _assertValue2(3.45, "3.45"); | |
| 694 } | |
| 695 | |
| 696 void test_literal_number_integer() { | |
| 697 _assertValue3(42, "42"); | |
| 698 } | |
| 699 | |
| 700 void test_literal_string_adjacent() { | |
| 701 _assertValue4("abcdef", "'abc' 'def'"); | |
| 702 } | |
| 703 | |
| 704 void test_literal_string_interpolation_invalid() { | |
| 705 EvaluationResult result = _getExpressionValue("'a\${f()}c'"); | |
| 706 expect(result.isValid, isFalse); | |
| 707 } | |
| 708 | |
| 709 void test_literal_string_interpolation_valid() { | |
| 710 _assertValue4("a3c", "'a\${3}c'"); | |
| 711 } | |
| 712 | |
| 713 void test_literal_string_simple() { | |
| 714 _assertValue4("abc", "'abc'"); | |
| 715 } | |
| 716 | |
| 717 void test_logicalAnd() { | |
| 718 _assertValue(false, "true && false"); | |
| 719 } | |
| 720 | |
| 721 void test_logicalNot() { | |
| 722 _assertValue(false, "!true"); | |
| 723 } | |
| 724 | |
| 725 void test_logicalOr() { | |
| 726 _assertValue(true, "true || false"); | |
| 727 } | |
| 728 | |
| 729 void test_minus_double_double() { | |
| 730 _assertValue2(3.2 - 2.3, "3.2 - 2.3"); | |
| 731 } | |
| 732 | |
| 733 void test_minus_int_int() { | |
| 734 _assertValue3(1, "3 - 2"); | |
| 735 } | |
| 736 | |
| 737 void test_negated_boolean() { | |
| 738 EvaluationResult result = _getExpressionValue("-true"); | |
| 739 expect(result.isValid, isFalse); | |
| 740 } | |
| 741 | |
| 742 void test_negated_double() { | |
| 743 _assertValue2(-42.3, "-42.3"); | |
| 744 } | |
| 745 | |
| 746 void test_negated_integer() { | |
| 747 _assertValue3(-42, "-42"); | |
| 748 } | |
| 749 | |
| 750 void test_notEqual_boolean_boolean() { | |
| 751 _assertValue(true, "true != false"); | |
| 752 } | |
| 753 | |
| 754 void test_notEqual_int_int() { | |
| 755 _assertValue(true, "2 != 3"); | |
| 756 } | |
| 757 | |
| 758 void test_notEqual_invalidLeft() { | |
| 759 EvaluationResult result = _getExpressionValue("a != 3"); | |
| 760 expect(result.isValid, isFalse); | |
| 761 } | |
| 762 | |
| 763 void test_notEqual_invalidRight() { | |
| 764 EvaluationResult result = _getExpressionValue("2 != a"); | |
| 765 expect(result.isValid, isFalse); | |
| 766 } | |
| 767 | |
| 768 void test_notEqual_string_string() { | |
| 769 _assertValue(true, "'a' != 'b'"); | |
| 770 } | |
| 771 | |
| 772 void test_parenthesizedExpression() { | |
| 773 _assertValue4("a", "('a')"); | |
| 774 } | |
| 775 | |
| 776 void test_plus_double_double() { | |
| 777 _assertValue2(2.3 + 3.2, "2.3 + 3.2"); | |
| 778 } | |
| 779 | |
| 780 void test_plus_int_int() { | |
| 781 _assertValue3(5, "2 + 3"); | |
| 782 } | |
| 783 | |
| 784 void test_plus_string_string() { | |
| 785 _assertValue4("ab", "'a' + 'b'"); | |
| 786 } | |
| 787 | |
| 788 void test_remainder_double_double() { | |
| 789 _assertValue2(3.2 % 2.3, "3.2 % 2.3"); | |
| 790 } | |
| 791 | |
| 792 void test_remainder_int_int() { | |
| 793 _assertValue3(2, "8 % 3"); | |
| 794 } | |
| 795 | |
| 796 void test_rightShift() { | |
| 797 _assertValue3(16, "64 >> 2"); | |
| 798 } | |
| 799 | |
| 800 void test_stringLength_complex() { | |
| 801 _assertValue3(6, "('qwe' + 'rty').length"); | |
| 802 } | |
| 803 | |
| 804 void test_stringLength_simple() { | |
| 805 _assertValue3(6, "'Dvorak'.length"); | |
| 806 } | |
| 807 | |
| 808 void test_times_double_double() { | |
| 809 _assertValue2(2.3 * 3.2, "2.3 * 3.2"); | |
| 810 } | |
| 811 | |
| 812 void test_times_int_int() { | |
| 813 _assertValue3(6, "2 * 3"); | |
| 814 } | |
| 815 | |
| 816 void test_truncatingDivide_double_double() { | |
| 817 _assertValue3(1, "3.2 ~/ 2.3"); | |
| 818 } | |
| 819 | |
| 820 void test_truncatingDivide_int_int() { | |
| 821 _assertValue3(3, "10 ~/ 3"); | |
| 822 } | |
| 823 | |
| 824 void _assertValue(bool expectedValue, String contents) { | |
| 825 EvaluationResult result = _getExpressionValue(contents); | |
| 826 DartObject value = result.value; | |
| 827 expect(value.type.name, "bool"); | |
| 828 expect(value.toBoolValue(), expectedValue); | |
| 829 } | |
| 830 | |
| 831 void _assertValue2(double expectedValue, String contents) { | |
| 832 EvaluationResult result = _getExpressionValue(contents); | |
| 833 expect(result.isValid, isTrue); | |
| 834 DartObject value = result.value; | |
| 835 expect(value.type.name, "double"); | |
| 836 expect(value.toDoubleValue(), expectedValue); | |
| 837 } | |
| 838 | |
| 839 void _assertValue3(int expectedValue, String contents) { | |
| 840 EvaluationResult result = _getExpressionValue(contents); | |
| 841 expect(result.isValid, isTrue); | |
| 842 DartObject value = result.value; | |
| 843 expect(value.type.name, "int"); | |
| 844 expect(value.toIntValue(), expectedValue); | |
| 845 } | |
| 846 | |
| 847 void _assertValue4(String expectedValue, String contents) { | |
| 848 EvaluationResult result = _getExpressionValue(contents); | |
| 849 DartObject value = result.value; | |
| 850 expect(value, isNotNull); | |
| 851 ParameterizedType type = value.type; | |
| 852 expect(type, isNotNull); | |
| 853 expect(type.name, "String"); | |
| 854 expect(value.toStringValue(), expectedValue); | |
| 855 } | |
| 856 | |
| 857 EvaluationResult _getExpressionValue(String contents) { | |
| 858 Source source = addSource("var x = $contents;"); | |
| 859 LibraryElement library = resolve2(source); | |
| 860 CompilationUnit unit = | |
| 861 analysisContext.resolveCompilationUnit(source, library); | |
| 862 expect(unit, isNotNull); | |
| 863 NodeList<CompilationUnitMember> declarations = unit.declarations; | |
| 864 expect(declarations, hasLength(1)); | |
| 865 CompilationUnitMember declaration = declarations[0]; | |
| 866 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableDeclaration, | |
| 867 TopLevelVariableDeclaration, declaration); | |
| 868 NodeList<VariableDeclaration> variables = | |
| 869 (declaration as TopLevelVariableDeclaration).variables.variables; | |
| 870 expect(variables, hasLength(1)); | |
| 871 ConstantEvaluator evaluator = new ConstantEvaluator( | |
| 872 source, analysisContext.typeProvider, | |
| 873 typeSystem: analysisContext.typeSystem); | |
| 874 return evaluator.evaluate(variables[0].initializer); | |
| 875 } | |
| 876 } | |
| 877 | |
| 878 @reflectiveTest | |
| 879 class ConstantFinderTest extends EngineTestCase { | |
| 880 AstNode _node; | |
| 881 TypeProvider _typeProvider; | |
| 882 AnalysisContext _context; | |
| 883 Source _source; | |
| 884 | |
| 885 void setUp() { | |
| 886 super.setUp(); | |
| 887 _typeProvider = new TestTypeProvider(); | |
| 888 _context = new TestAnalysisContext(); | |
| 889 _source = new TestSource(); | |
| 890 } | |
| 891 | |
| 892 /** | |
| 893 * Test an annotation that consists solely of an identifier (and hence | |
| 894 * represents a reference to a compile-time constant variable). | |
| 895 */ | |
| 896 void test_visitAnnotation_constantVariable() { | |
| 897 _node = AstFactory.annotation(AstFactory.identifier3('x')); | |
| 898 expect(_findAnnotations(), contains(_node)); | |
| 899 } | |
| 900 | |
| 901 /** | |
| 902 * Test an annotation that represents the invocation of a constant | |
| 903 * constructor. | |
| 904 */ | |
| 905 void test_visitAnnotation_invocation() { | |
| 906 _node = AstFactory.annotation2( | |
| 907 AstFactory.identifier3('A'), null, AstFactory.argumentList()); | |
| 908 expect(_findAnnotations(), contains(_node)); | |
| 909 } | |
| 910 | |
| 911 void test_visitConstructorDeclaration_const() { | |
| 912 ConstructorElement element = _setupConstructorDeclaration("A", true); | |
| 913 expect(_findConstants(), contains(element)); | |
| 914 } | |
| 915 | |
| 916 void test_visitConstructorDeclaration_nonConst() { | |
| 917 _setupConstructorDeclaration("A", false); | |
| 918 expect(_findConstants(), isEmpty); | |
| 919 } | |
| 920 | |
| 921 void test_visitVariableDeclaration_const() { | |
| 922 VariableElement element = _setupVariableDeclaration("v", true, true); | |
| 923 expect(_findConstants(), contains(element)); | |
| 924 } | |
| 925 | |
| 926 void test_visitVariableDeclaration_final_inClass() { | |
| 927 _setupFieldDeclaration('C', 'f', Keyword.FINAL); | |
| 928 expect(_findConstants(), isEmpty); | |
| 929 } | |
| 930 | |
| 931 void test_visitVariableDeclaration_final_inClassWithConstConstructor() { | |
| 932 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | |
| 933 hasConstConstructor: true); | |
| 934 expect(_findConstants(), contains(field.element)); | |
| 935 } | |
| 936 | |
| 937 void test_visitVariableDeclaration_final_outsideClass() { | |
| 938 _setupVariableDeclaration('v', false, true, isFinal: true); | |
| 939 expect(_findConstants(), isEmpty); | |
| 940 } | |
| 941 | |
| 942 void test_visitVariableDeclaration_noInitializer() { | |
| 943 _setupVariableDeclaration("v", true, false); | |
| 944 expect(_findConstants(), isEmpty); | |
| 945 } | |
| 946 | |
| 947 void test_visitVariableDeclaration_nonConst() { | |
| 948 _setupVariableDeclaration("v", false, true); | |
| 949 expect(_findConstants(), isEmpty); | |
| 950 } | |
| 951 | |
| 952 void test_visitVariableDeclaration_static_const_inClass() { | |
| 953 VariableDeclaration field = | |
| 954 _setupFieldDeclaration('C', 'f', Keyword.CONST, isStatic: true); | |
| 955 expect(_findConstants(), contains(field.element)); | |
| 956 } | |
| 957 | |
| 958 void test_visitVariableDeclaration_static_const_inClassWithConstConstructor()
{ | |
| 959 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.CONST, | |
| 960 isStatic: true, hasConstConstructor: true); | |
| 961 expect(_findConstants(), contains(field.element)); | |
| 962 } | |
| 963 | |
| 964 void test_visitVariableDeclaration_static_final_inClassWithConstConstructor()
{ | |
| 965 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | |
| 966 isStatic: true, hasConstConstructor: true); | |
| 967 expect(_findConstants(), isNot(contains(field.element))); | |
| 968 } | |
| 969 | |
| 970 void test_visitVariableDeclaration_uninitialized_final_inClassWithConstConstru
ctor() { | |
| 971 VariableDeclaration field = _setupFieldDeclaration('C', 'f', Keyword.FINAL, | |
| 972 isInitialized: false, hasConstConstructor: true); | |
| 973 expect(_findConstants(), isNot(contains(field.element))); | |
| 974 } | |
| 975 | |
| 976 void test_visitVariableDeclaration_uninitialized_static_const_inClass() { | |
| 977 _setupFieldDeclaration('C', 'f', Keyword.CONST, | |
| 978 isStatic: true, isInitialized: false); | |
| 979 expect(_findConstants(), isEmpty); | |
| 980 } | |
| 981 | |
| 982 List<Annotation> _findAnnotations() { | |
| 983 Set<Annotation> annotations = new Set<Annotation>(); | |
| 984 for (ConstantEvaluationTarget target in _findConstants()) { | |
| 985 if (target is ConstantEvaluationTarget_Annotation) { | |
| 986 expect(target.context, same(_context)); | |
| 987 expect(target.source, same(_source)); | |
| 988 annotations.add(target.annotation); | |
| 989 } | |
| 990 } | |
| 991 return new List<Annotation>.from(annotations); | |
| 992 } | |
| 993 | |
| 994 Set<ConstantEvaluationTarget> _findConstants() { | |
| 995 ConstantFinder finder = new ConstantFinder(_context, _source, _source); | |
| 996 _node.accept(finder); | |
| 997 Set<ConstantEvaluationTarget> constants = finder.constantsToCompute; | |
| 998 expect(constants, isNotNull); | |
| 999 return constants; | |
| 1000 } | |
| 1001 | |
| 1002 ConstructorElement _setupConstructorDeclaration(String name, bool isConst) { | |
| 1003 Keyword constKeyword = isConst ? Keyword.CONST : null; | |
| 1004 ConstructorDeclaration constructorDeclaration = AstFactory | |
| 1005 .constructorDeclaration2( | |
| 1006 constKeyword, | |
| 1007 null, | |
| 1008 null, | |
| 1009 name, | |
| 1010 AstFactory.formalParameterList(), | |
| 1011 null, | |
| 1012 AstFactory.blockFunctionBody2()); | |
| 1013 ClassElement classElement = ElementFactory.classElement2(name); | |
| 1014 ConstructorElement element = | |
| 1015 ElementFactory.constructorElement(classElement, name, isConst); | |
| 1016 constructorDeclaration.element = element; | |
| 1017 _node = constructorDeclaration; | |
| 1018 return element; | |
| 1019 } | |
| 1020 | |
| 1021 VariableDeclaration _setupFieldDeclaration( | |
| 1022 String className, String fieldName, Keyword keyword, | |
| 1023 {bool isInitialized: true, | |
| 1024 bool isStatic: false, | |
| 1025 bool hasConstConstructor: false}) { | |
| 1026 VariableDeclaration variableDeclaration = isInitialized | |
| 1027 ? AstFactory.variableDeclaration2(fieldName, AstFactory.integer(0)) | |
| 1028 : AstFactory.variableDeclaration(fieldName); | |
| 1029 VariableElement fieldElement = ElementFactory.fieldElement( | |
| 1030 fieldName, | |
| 1031 isStatic, | |
| 1032 keyword == Keyword.FINAL, | |
| 1033 keyword == Keyword.CONST, | |
| 1034 _typeProvider.intType); | |
| 1035 variableDeclaration.name.staticElement = fieldElement; | |
| 1036 FieldDeclaration fieldDeclaration = AstFactory.fieldDeclaration2( | |
| 1037 isStatic, keyword, <VariableDeclaration>[variableDeclaration]); | |
| 1038 ClassDeclaration classDeclaration = | |
| 1039 AstFactory.classDeclaration(null, className, null, null, null, null); | |
| 1040 classDeclaration.members.add(fieldDeclaration); | |
| 1041 _node = classDeclaration; | |
| 1042 ClassElementImpl classElement = ElementFactory.classElement2(className); | |
| 1043 classElement.fields = <FieldElement>[fieldElement]; | |
| 1044 classDeclaration.name.staticElement = classElement; | |
| 1045 if (hasConstConstructor) { | |
| 1046 ConstructorDeclaration constructorDeclaration = AstFactory | |
| 1047 .constructorDeclaration2( | |
| 1048 Keyword.CONST, | |
| 1049 null, | |
| 1050 AstFactory.identifier3(className), | |
| 1051 null, | |
| 1052 AstFactory.formalParameterList(), | |
| 1053 null, | |
| 1054 AstFactory.blockFunctionBody2()); | |
| 1055 classDeclaration.members.add(constructorDeclaration); | |
| 1056 ConstructorElement constructorElement = | |
| 1057 ElementFactory.constructorElement(classElement, '', true); | |
| 1058 constructorDeclaration.element = constructorElement; | |
| 1059 classElement.constructors = <ConstructorElement>[constructorElement]; | |
| 1060 } else { | |
| 1061 classElement.constructors = ConstructorElement.EMPTY_LIST; | |
| 1062 } | |
| 1063 return variableDeclaration; | |
| 1064 } | |
| 1065 | |
| 1066 VariableElement _setupVariableDeclaration( | |
| 1067 String name, bool isConst, bool isInitialized, | |
| 1068 {isFinal: false}) { | |
| 1069 VariableDeclaration variableDeclaration = isInitialized | |
| 1070 ? AstFactory.variableDeclaration2(name, AstFactory.integer(0)) | |
| 1071 : AstFactory.variableDeclaration(name); | |
| 1072 SimpleIdentifier identifier = variableDeclaration.name; | |
| 1073 VariableElement element = ElementFactory.localVariableElement(identifier); | |
| 1074 identifier.staticElement = element; | |
| 1075 Keyword keyword = isConst ? Keyword.CONST : isFinal ? Keyword.FINAL : null; | |
| 1076 AstFactory.variableDeclarationList2(keyword, [variableDeclaration]); | |
| 1077 _node = variableDeclaration; | |
| 1078 return element; | |
| 1079 } | |
| 1080 } | |
| 1081 | |
| 1082 @reflectiveTest | |
| 1083 class ConstantValueComputerTest extends ResolverTestCase { | |
| 1084 void test_annotation_constConstructor() { | |
| 1085 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1086 class A { | |
| 1087 final int i; | |
| 1088 const A(this.i); | |
| 1089 } | |
| 1090 | |
| 1091 class C { | |
| 1092 @A(5) | |
| 1093 f() {} | |
| 1094 } | |
| 1095 '''); | 86 '''); |
| 1096 EvaluationResultImpl result = | 87 resourceProvider.newFile( |
| 1097 _evaluateAnnotation(compilationUnit, "C", "f"); | 88 resourceProvider.pathContext |
| 1098 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A'); | 89 .join(sdkFolderName, 'lib', 'core', 'core.dart'), |
| 1099 _assertIntField(annotationFields, 'i', 5); | 90 ''' |
| 1100 } | 91 library dart.core; |
| 1101 | |
| 1102 void test_annotation_constConstructor_named() { | |
| 1103 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1104 class A { | |
| 1105 final int i; | |
| 1106 const A.named(this.i); | |
| 1107 } | |
| 1108 | |
| 1109 class C { | |
| 1110 @A.named(5) | |
| 1111 f() {} | |
| 1112 } | |
| 1113 '''); | 92 '''); |
| 1114 EvaluationResultImpl result = | 93 return new FolderBasedDartSdk(resourceProvider, sdkFolder); |
| 1115 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1116 Map<String, DartObjectImpl> annotationFields = _assertType(result, 'A'); | |
| 1117 _assertIntField(annotationFields, 'i', 5); | |
| 1118 } | |
| 1119 | |
| 1120 void test_annotation_constConstructor_noArgs() { | |
| 1121 // Failing to pass arguments to an annotation which is a constant | |
| 1122 // constructor is illegal, but shouldn't crash analysis. | |
| 1123 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1124 class A { | |
| 1125 final int i; | |
| 1126 const A(this.i); | |
| 1127 } | |
| 1128 | |
| 1129 class C { | |
| 1130 @A | |
| 1131 f() {} | |
| 1132 } | |
| 1133 '''); | |
| 1134 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1135 } | |
| 1136 | |
| 1137 void test_annotation_constConstructor_noArgs_named() { | |
| 1138 // Failing to pass arguments to an annotation which is a constant | |
| 1139 // constructor is illegal, but shouldn't crash analysis. | |
| 1140 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1141 class A { | |
| 1142 final int i; | |
| 1143 const A.named(this.i); | |
| 1144 } | |
| 1145 | |
| 1146 class C { | |
| 1147 @A.named | |
| 1148 f() {} | |
| 1149 } | |
| 1150 '''); | |
| 1151 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1152 } | |
| 1153 | |
| 1154 void test_annotation_nonConstConstructor() { | |
| 1155 // Calling a non-const constructor from an annotation that is illegal, but | |
| 1156 // shouldn't crash analysis. | |
| 1157 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1158 class A { | |
| 1159 final int i; | |
| 1160 A(this.i); | |
| 1161 } | |
| 1162 | |
| 1163 class C { | |
| 1164 @A(5) | |
| 1165 f() {} | |
| 1166 } | |
| 1167 '''); | |
| 1168 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1169 } | |
| 1170 | |
| 1171 void test_annotation_staticConst() { | |
| 1172 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1173 class C { | |
| 1174 static const int i = 5; | |
| 1175 | |
| 1176 @i | |
| 1177 f() {} | |
| 1178 } | |
| 1179 '''); | |
| 1180 EvaluationResultImpl result = | |
| 1181 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1182 expect(_assertValidInt(result), 5); | |
| 1183 } | |
| 1184 | |
| 1185 void test_annotation_staticConst_args() { | |
| 1186 // Applying arguments to an annotation that is a static const is | |
| 1187 // illegal, but shouldn't crash analysis. | |
| 1188 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1189 class C { | |
| 1190 static const int i = 5; | |
| 1191 | |
| 1192 @i(1) | |
| 1193 f() {} | |
| 1194 } | |
| 1195 '''); | |
| 1196 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1197 } | |
| 1198 | |
| 1199 void test_annotation_staticConst_otherClass() { | |
| 1200 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1201 class A { | |
| 1202 static const int i = 5; | |
| 1203 } | |
| 1204 | |
| 1205 class C { | |
| 1206 @A.i | |
| 1207 f() {} | |
| 1208 } | |
| 1209 '''); | |
| 1210 EvaluationResultImpl result = | |
| 1211 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1212 expect(_assertValidInt(result), 5); | |
| 1213 } | |
| 1214 | |
| 1215 void test_annotation_staticConst_otherClass_args() { | |
| 1216 // Applying arguments to an annotation that is a static const is | |
| 1217 // illegal, but shouldn't crash analysis. | |
| 1218 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1219 class A { | |
| 1220 static const int i = 5; | |
| 1221 } | |
| 1222 | |
| 1223 class C { | |
| 1224 @A.i(1) | |
| 1225 f() {} | |
| 1226 } | |
| 1227 '''); | |
| 1228 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1229 } | |
| 1230 | |
| 1231 void test_annotation_toplevelVariable() { | |
| 1232 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1233 const int i = 5; | |
| 1234 class C { | |
| 1235 @i | |
| 1236 f() {} | |
| 1237 } | |
| 1238 '''); | |
| 1239 EvaluationResultImpl result = | |
| 1240 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1241 expect(_assertValidInt(result), 5); | |
| 1242 } | |
| 1243 | |
| 1244 void test_annotation_toplevelVariable_args() { | |
| 1245 // Applying arguments to an annotation that is a toplevel variable is | |
| 1246 // illegal, but shouldn't crash analysis. | |
| 1247 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1248 const int i = 5; | |
| 1249 class C { | |
| 1250 @i(1) | |
| 1251 f() {} | |
| 1252 } | |
| 1253 '''); | |
| 1254 _evaluateAnnotation(compilationUnit, "C", "f"); | |
| 1255 } | |
| 1256 | |
| 1257 void test_computeValues_cycle() { | |
| 1258 TestLogger logger = new TestLogger(); | |
| 1259 AnalysisEngine.instance.logger = logger; | |
| 1260 Source librarySource = addSource(r''' | |
| 1261 const int a = c; | |
| 1262 const int b = a; | |
| 1263 const int c = b;'''); | |
| 1264 LibraryElement libraryElement = resolve2(librarySource); | |
| 1265 CompilationUnit unit = | |
| 1266 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | |
| 1267 analysisContext.computeErrors(librarySource); | |
| 1268 expect(unit, isNotNull); | |
| 1269 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1270 computer.add(unit, librarySource, librarySource); | |
| 1271 computer.computeValues(); | |
| 1272 NodeList<CompilationUnitMember> members = unit.declarations; | |
| 1273 expect(members, hasLength(3)); | |
| 1274 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); | |
| 1275 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); | |
| 1276 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); | |
| 1277 } | |
| 1278 | |
| 1279 void test_computeValues_dependentVariables() { | |
| 1280 Source librarySource = addSource(r''' | |
| 1281 const int b = a; | |
| 1282 const int a = 0;'''); | |
| 1283 LibraryElement libraryElement = resolve2(librarySource); | |
| 1284 CompilationUnit unit = | |
| 1285 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | |
| 1286 expect(unit, isNotNull); | |
| 1287 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1288 computer.add(unit, librarySource, librarySource); | |
| 1289 computer.computeValues(); | |
| 1290 NodeList<CompilationUnitMember> members = unit.declarations; | |
| 1291 expect(members, hasLength(2)); | |
| 1292 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | |
| 1293 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); | |
| 1294 } | |
| 1295 | |
| 1296 void test_computeValues_empty() { | |
| 1297 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1298 computer.computeValues(); | |
| 1299 } | |
| 1300 | |
| 1301 void test_computeValues_multipleSources() { | |
| 1302 Source librarySource = addNamedSource( | |
| 1303 "/lib.dart", | |
| 1304 r''' | |
| 1305 library lib; | |
| 1306 part 'part.dart'; | |
| 1307 const int c = b; | |
| 1308 const int a = 0;'''); | |
| 1309 Source partSource = addNamedSource( | |
| 1310 "/part.dart", | |
| 1311 r''' | |
| 1312 part of lib; | |
| 1313 const int b = a; | |
| 1314 const int d = c;'''); | |
| 1315 LibraryElement libraryElement = resolve2(librarySource); | |
| 1316 CompilationUnit libraryUnit = | |
| 1317 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | |
| 1318 expect(libraryUnit, isNotNull); | |
| 1319 CompilationUnit partUnit = | |
| 1320 analysisContext.resolveCompilationUnit(partSource, libraryElement); | |
| 1321 expect(partUnit, isNotNull); | |
| 1322 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1323 computer.add(libraryUnit, librarySource, librarySource); | |
| 1324 computer.add(partUnit, partSource, librarySource); | |
| 1325 computer.computeValues(); | |
| 1326 NodeList<CompilationUnitMember> libraryMembers = libraryUnit.declarations; | |
| 1327 expect(libraryMembers, hasLength(2)); | |
| 1328 _validate( | |
| 1329 true, (libraryMembers[0] as TopLevelVariableDeclaration).variables); | |
| 1330 _validate( | |
| 1331 true, (libraryMembers[1] as TopLevelVariableDeclaration).variables); | |
| 1332 NodeList<CompilationUnitMember> partMembers = libraryUnit.declarations; | |
| 1333 expect(partMembers, hasLength(2)); | |
| 1334 _validate(true, (partMembers[0] as TopLevelVariableDeclaration).variables); | |
| 1335 _validate(true, (partMembers[1] as TopLevelVariableDeclaration).variables); | |
| 1336 } | |
| 1337 | |
| 1338 void test_computeValues_singleVariable() { | |
| 1339 Source librarySource = addSource("const int a = 0;"); | |
| 1340 LibraryElement libraryElement = resolve2(librarySource); | |
| 1341 CompilationUnit unit = | |
| 1342 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | |
| 1343 expect(unit, isNotNull); | |
| 1344 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1345 computer.add(unit, librarySource, librarySource); | |
| 1346 computer.computeValues(); | |
| 1347 NodeList<CompilationUnitMember> members = unit.declarations; | |
| 1348 expect(members, hasLength(1)); | |
| 1349 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | |
| 1350 } | |
| 1351 | |
| 1352 void test_computeValues_value_depends_on_enum() { | |
| 1353 Source librarySource = addSource(''' | |
| 1354 enum E { id0, id1 } | |
| 1355 const E e = E.id0; | |
| 1356 '''); | |
| 1357 LibraryElement libraryElement = resolve2(librarySource); | |
| 1358 CompilationUnit unit = | |
| 1359 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | |
| 1360 expect(unit, isNotNull); | |
| 1361 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 1362 computer.add(unit, librarySource, librarySource); | |
| 1363 computer.computeValues(); | |
| 1364 TopLevelVariableDeclaration declaration = unit.declarations | |
| 1365 .firstWhere((member) => member is TopLevelVariableDeclaration); | |
| 1366 _validate(true, declaration.variables); | |
| 1367 } | |
| 1368 | |
| 1369 void test_dependencyOnConstructor() { | |
| 1370 // x depends on "const A()" | |
| 1371 _assertProperDependencies(r''' | |
| 1372 class A { | |
| 1373 const A(); | |
| 1374 } | |
| 1375 const x = const A();'''); | |
| 1376 } | |
| 1377 | |
| 1378 void test_dependencyOnConstructorArgument() { | |
| 1379 // "const A(x)" depends on x | |
| 1380 _assertProperDependencies(r''' | |
| 1381 class A { | |
| 1382 const A(this.next); | |
| 1383 final A next; | |
| 1384 } | |
| 1385 const A x = const A(null); | |
| 1386 const A y = const A(x);'''); | |
| 1387 } | |
| 1388 | |
| 1389 void test_dependencyOnConstructorArgument_unresolvedConstructor() { | |
| 1390 // "const A.a(x)" depends on x even if the constructor A.a can't be found. | |
| 1391 _assertProperDependencies( | |
| 1392 r''' | |
| 1393 class A { | |
| 1394 } | |
| 1395 const int x = 1; | |
| 1396 const A y = const A.a(x);''', | |
| 1397 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]); | |
| 1398 } | |
| 1399 | |
| 1400 void test_dependencyOnConstructorInitializer() { | |
| 1401 // "const A()" depends on x | |
| 1402 _assertProperDependencies(r''' | |
| 1403 const int x = 1; | |
| 1404 class A { | |
| 1405 const A() : v = x; | |
| 1406 final int v; | |
| 1407 }'''); | |
| 1408 } | |
| 1409 | |
| 1410 void test_dependencyOnExplicitSuperConstructor() { | |
| 1411 // b depends on B() depends on A() | |
| 1412 _assertProperDependencies(r''' | |
| 1413 class A { | |
| 1414 const A(this.x); | |
| 1415 final int x; | |
| 1416 } | |
| 1417 class B extends A { | |
| 1418 const B() : super(5); | |
| 1419 } | |
| 1420 const B b = const B();'''); | |
| 1421 } | |
| 1422 | |
| 1423 void test_dependencyOnExplicitSuperConstructorParameters() { | |
| 1424 // b depends on B() depends on i | |
| 1425 _assertProperDependencies(r''' | |
| 1426 class A { | |
| 1427 const A(this.x); | |
| 1428 final int x; | |
| 1429 } | |
| 1430 class B extends A { | |
| 1431 const B() : super(i); | |
| 1432 } | |
| 1433 const B b = const B(); | |
| 1434 const int i = 5;'''); | |
| 1435 } | |
| 1436 | |
| 1437 void test_dependencyOnFactoryRedirect() { | |
| 1438 // a depends on A.foo() depends on A.bar() | |
| 1439 _assertProperDependencies(r''' | |
| 1440 const A a = const A.foo(); | |
| 1441 class A { | |
| 1442 factory const A.foo() = A.bar; | |
| 1443 const A.bar(); | |
| 1444 }'''); | |
| 1445 } | |
| 1446 | |
| 1447 void test_dependencyOnFactoryRedirectWithTypeParams() { | |
| 1448 _assertProperDependencies(r''' | |
| 1449 class A { | |
| 1450 const factory A(var a) = B<int>; | |
| 1451 } | |
| 1452 | |
| 1453 class B<T> implements A { | |
| 1454 final T x; | |
| 1455 const B(this.x); | |
| 1456 } | |
| 1457 | |
| 1458 const A a = const A(10);'''); | |
| 1459 } | |
| 1460 | |
| 1461 void test_dependencyOnImplicitSuperConstructor() { | |
| 1462 // b depends on B() depends on A() | |
| 1463 _assertProperDependencies(r''' | |
| 1464 class A { | |
| 1465 const A() : x = 5; | |
| 1466 final int x; | |
| 1467 } | |
| 1468 class B extends A { | |
| 1469 const B(); | |
| 1470 } | |
| 1471 const B b = const B();'''); | |
| 1472 } | |
| 1473 | |
| 1474 void test_dependencyOnInitializedFinal() { | |
| 1475 // a depends on A() depends on A.x | |
| 1476 _assertProperDependencies(''' | |
| 1477 class A { | |
| 1478 const A(); | |
| 1479 final int x = 1; | |
| 1480 } | |
| 1481 const A a = const A(); | |
| 1482 '''); | |
| 1483 } | |
| 1484 | |
| 1485 void test_dependencyOnInitializedNonStaticConst() { | |
| 1486 // Even though non-static consts are not allowed by the language, we need | |
| 1487 // to handle them for error recovery purposes. | |
| 1488 // a depends on A() depends on A.x | |
| 1489 _assertProperDependencies( | |
| 1490 ''' | |
| 1491 class A { | |
| 1492 const A(); | |
| 1493 const int x = 1; | |
| 1494 } | |
| 1495 const A a = const A(); | |
| 1496 ''', | |
| 1497 [CompileTimeErrorCode.CONST_INSTANCE_FIELD]); | |
| 1498 } | |
| 1499 | |
| 1500 void test_dependencyOnNonFactoryRedirect() { | |
| 1501 // a depends on A.foo() depends on A.bar() | |
| 1502 _assertProperDependencies(r''' | |
| 1503 const A a = const A.foo(); | |
| 1504 class A { | |
| 1505 const A.foo() : this.bar(); | |
| 1506 const A.bar(); | |
| 1507 }'''); | |
| 1508 } | |
| 1509 | |
| 1510 void test_dependencyOnNonFactoryRedirect_arg() { | |
| 1511 // a depends on A.foo() depends on b | |
| 1512 _assertProperDependencies(r''' | |
| 1513 const A a = const A.foo(); | |
| 1514 const int b = 1; | |
| 1515 class A { | |
| 1516 const A.foo() : this.bar(b); | |
| 1517 const A.bar(x) : y = x; | |
| 1518 final int y; | |
| 1519 }'''); | |
| 1520 } | |
| 1521 | |
| 1522 void test_dependencyOnNonFactoryRedirect_defaultValue() { | |
| 1523 // a depends on A.foo() depends on A.bar() depends on b | |
| 1524 _assertProperDependencies(r''' | |
| 1525 const A a = const A.foo(); | |
| 1526 const int b = 1; | |
| 1527 class A { | |
| 1528 const A.foo() : this.bar(); | |
| 1529 const A.bar([x = b]) : y = x; | |
| 1530 final int y; | |
| 1531 }'''); | |
| 1532 } | |
| 1533 | |
| 1534 void test_dependencyOnNonFactoryRedirect_toMissing() { | |
| 1535 // a depends on A.foo() which depends on nothing, since A.bar() is | |
| 1536 // missing. | |
| 1537 _assertProperDependencies( | |
| 1538 r''' | |
| 1539 const A a = const A.foo(); | |
| 1540 class A { | |
| 1541 const A.foo() : this.bar(); | |
| 1542 }''', | |
| 1543 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); | |
| 1544 } | |
| 1545 | |
| 1546 void test_dependencyOnNonFactoryRedirect_toNonConst() { | |
| 1547 // a depends on A.foo() which depends on nothing, since A.bar() is | |
| 1548 // non-const. | |
| 1549 _assertProperDependencies(r''' | |
| 1550 const A a = const A.foo(); | |
| 1551 class A { | |
| 1552 const A.foo() : this.bar(); | |
| 1553 A.bar(); | |
| 1554 }'''); | |
| 1555 } | |
| 1556 | |
| 1557 void test_dependencyOnNonFactoryRedirect_unnamed() { | |
| 1558 // a depends on A.foo() depends on A() | |
| 1559 _assertProperDependencies(r''' | |
| 1560 const A a = const A.foo(); | |
| 1561 class A { | |
| 1562 const A.foo() : this(); | |
| 1563 const A(); | |
| 1564 }'''); | |
| 1565 } | |
| 1566 | |
| 1567 void test_dependencyOnOptionalParameterDefault() { | |
| 1568 // a depends on A() depends on B() | |
| 1569 _assertProperDependencies(r''' | |
| 1570 class A { | |
| 1571 const A([x = const B()]) : b = x; | |
| 1572 final B b; | |
| 1573 } | |
| 1574 class B { | |
| 1575 const B(); | |
| 1576 } | |
| 1577 const A a = const A();'''); | |
| 1578 } | |
| 1579 | |
| 1580 void test_dependencyOnVariable() { | |
| 1581 // x depends on y | |
| 1582 _assertProperDependencies(r''' | |
| 1583 const x = y + 1; | |
| 1584 const y = 2;'''); | |
| 1585 } | |
| 1586 | |
| 1587 void test_final_initialized_at_declaration() { | |
| 1588 CompilationUnit compilationUnit = resolveSource(''' | |
| 1589 class A { | |
| 1590 final int i = 123; | |
| 1591 const A(); | |
| 1592 } | |
| 1593 | |
| 1594 const A a = const A(); | |
| 1595 '''); | |
| 1596 EvaluationResultImpl result = | |
| 1597 _evaluateTopLevelVariable(compilationUnit, 'a'); | |
| 1598 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1599 expect(fields, hasLength(1)); | |
| 1600 _assertIntField(fields, "i", 123); | |
| 1601 } | |
| 1602 | |
| 1603 void test_fromEnvironment_bool_default_false() { | |
| 1604 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); | |
| 1605 } | |
| 1606 | |
| 1607 void test_fromEnvironment_bool_default_overridden() { | |
| 1608 expect( | |
| 1609 _assertValidBool(_check_fromEnvironment_bool("false", "true")), false); | |
| 1610 } | |
| 1611 | |
| 1612 void test_fromEnvironment_bool_default_parseError() { | |
| 1613 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", "true")), | |
| 1614 true); | |
| 1615 } | |
| 1616 | |
| 1617 void test_fromEnvironment_bool_default_true() { | |
| 1618 expect(_assertValidBool(_check_fromEnvironment_bool(null, "true")), true); | |
| 1619 } | |
| 1620 | |
| 1621 void test_fromEnvironment_bool_false() { | |
| 1622 expect(_assertValidBool(_check_fromEnvironment_bool("false", null)), false); | |
| 1623 } | |
| 1624 | |
| 1625 void test_fromEnvironment_bool_parseError() { | |
| 1626 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", null)), | |
| 1627 false); | |
| 1628 } | |
| 1629 | |
| 1630 void test_fromEnvironment_bool_true() { | |
| 1631 expect(_assertValidBool(_check_fromEnvironment_bool("true", null)), true); | |
| 1632 } | |
| 1633 | |
| 1634 void test_fromEnvironment_bool_undeclared() { | |
| 1635 _assertValidUnknown(_check_fromEnvironment_bool(null, null)); | |
| 1636 } | |
| 1637 | |
| 1638 void test_fromEnvironment_int_default_overridden() { | |
| 1639 expect(_assertValidInt(_check_fromEnvironment_int("234", "123")), 234); | |
| 1640 } | |
| 1641 | |
| 1642 void test_fromEnvironment_int_default_parseError() { | |
| 1643 expect( | |
| 1644 _assertValidInt(_check_fromEnvironment_int("parseError", "123")), 123); | |
| 1645 } | |
| 1646 | |
| 1647 void test_fromEnvironment_int_default_undeclared() { | |
| 1648 expect(_assertValidInt(_check_fromEnvironment_int(null, "123")), 123); | |
| 1649 } | |
| 1650 | |
| 1651 void test_fromEnvironment_int_ok() { | |
| 1652 expect(_assertValidInt(_check_fromEnvironment_int("234", null)), 234); | |
| 1653 } | |
| 1654 | |
| 1655 void test_fromEnvironment_int_parseError() { | |
| 1656 _assertValidNull(_check_fromEnvironment_int("parseError", null)); | |
| 1657 } | |
| 1658 | |
| 1659 void test_fromEnvironment_int_parseError_nullDefault() { | |
| 1660 _assertValidNull(_check_fromEnvironment_int("parseError", "null")); | |
| 1661 } | |
| 1662 | |
| 1663 void test_fromEnvironment_int_undeclared() { | |
| 1664 _assertValidUnknown(_check_fromEnvironment_int(null, null)); | |
| 1665 } | |
| 1666 | |
| 1667 void test_fromEnvironment_int_undeclared_nullDefault() { | |
| 1668 _assertValidNull(_check_fromEnvironment_int(null, "null")); | |
| 1669 } | |
| 1670 | |
| 1671 void test_fromEnvironment_string_default_overridden() { | |
| 1672 expect(_assertValidString(_check_fromEnvironment_string("abc", "'def'")), | |
| 1673 "abc"); | |
| 1674 } | |
| 1675 | |
| 1676 void test_fromEnvironment_string_default_undeclared() { | |
| 1677 expect(_assertValidString(_check_fromEnvironment_string(null, "'def'")), | |
| 1678 "def"); | |
| 1679 } | |
| 1680 | |
| 1681 void test_fromEnvironment_string_empty() { | |
| 1682 expect(_assertValidString(_check_fromEnvironment_string("", null)), ""); | |
| 1683 } | |
| 1684 | |
| 1685 void test_fromEnvironment_string_ok() { | |
| 1686 expect( | |
| 1687 _assertValidString(_check_fromEnvironment_string("abc", null)), "abc"); | |
| 1688 } | |
| 1689 | |
| 1690 void test_fromEnvironment_string_undeclared() { | |
| 1691 _assertValidUnknown(_check_fromEnvironment_string(null, null)); | |
| 1692 } | |
| 1693 | |
| 1694 void test_fromEnvironment_string_undeclared_nullDefault() { | |
| 1695 _assertValidNull(_check_fromEnvironment_string(null, "null")); | |
| 1696 } | |
| 1697 | |
| 1698 void test_instanceCreationExpression_computedField() { | |
| 1699 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1700 const foo = const A(4, 5); | |
| 1701 class A { | |
| 1702 const A(int i, int j) : k = 2 * i + j; | |
| 1703 final int k; | |
| 1704 }'''); | |
| 1705 EvaluationResultImpl result = | |
| 1706 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1707 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1708 expect(fields, hasLength(1)); | |
| 1709 _assertIntField(fields, "k", 13); | |
| 1710 } | |
| 1711 | |
| 1712 void test_instanceCreationExpression_computedField_namedOptionalWithDefault()
{ | |
| 1713 _checkInstanceCreationOptionalParams(false, true, true); | |
| 1714 } | |
| 1715 | |
| 1716 void test_instanceCreationExpression_computedField_namedOptionalWithoutDefault
() { | |
| 1717 _checkInstanceCreationOptionalParams(false, true, false); | |
| 1718 } | |
| 1719 | |
| 1720 void test_instanceCreationExpression_computedField_unnamedOptionalWithDefault(
) { | |
| 1721 _checkInstanceCreationOptionalParams(false, false, true); | |
| 1722 } | |
| 1723 | |
| 1724 void test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefau
lt() { | |
| 1725 _checkInstanceCreationOptionalParams(false, false, false); | |
| 1726 } | |
| 1727 | |
| 1728 void test_instanceCreationExpression_computedField_usesConstConstructor() { | |
| 1729 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1730 const foo = const A(3); | |
| 1731 class A { | |
| 1732 const A(int i) : b = const B(4); | |
| 1733 final int b; | |
| 1734 } | |
| 1735 class B { | |
| 1736 const B(this.k); | |
| 1737 final int k; | |
| 1738 }'''); | |
| 1739 EvaluationResultImpl result = | |
| 1740 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1741 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A"); | |
| 1742 expect(fieldsOfA, hasLength(1)); | |
| 1743 Map<String, DartObjectImpl> fieldsOfB = | |
| 1744 _assertFieldType(fieldsOfA, "b", "B"); | |
| 1745 expect(fieldsOfB, hasLength(1)); | |
| 1746 _assertIntField(fieldsOfB, "k", 4); | |
| 1747 } | |
| 1748 | |
| 1749 void test_instanceCreationExpression_computedField_usesStaticConst() { | |
| 1750 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1751 const foo = const A(3); | |
| 1752 class A { | |
| 1753 const A(int i) : k = i + B.bar; | |
| 1754 final int k; | |
| 1755 } | |
| 1756 class B { | |
| 1757 static const bar = 4; | |
| 1758 }'''); | |
| 1759 EvaluationResultImpl result = | |
| 1760 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1761 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1762 expect(fields, hasLength(1)); | |
| 1763 _assertIntField(fields, "k", 7); | |
| 1764 } | |
| 1765 | |
| 1766 void test_instanceCreationExpression_computedField_usesToplevelConst() { | |
| 1767 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1768 const foo = const A(3); | |
| 1769 const bar = 4; | |
| 1770 class A { | |
| 1771 const A(int i) : k = i + bar; | |
| 1772 final int k; | |
| 1773 }'''); | |
| 1774 EvaluationResultImpl result = | |
| 1775 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1776 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1777 expect(fields, hasLength(1)); | |
| 1778 _assertIntField(fields, "k", 7); | |
| 1779 } | |
| 1780 | |
| 1781 void test_instanceCreationExpression_explicitSuper() { | |
| 1782 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1783 const foo = const B(4, 5); | |
| 1784 class A { | |
| 1785 const A(this.x); | |
| 1786 final int x; | |
| 1787 } | |
| 1788 class B extends A { | |
| 1789 const B(int x, this.y) : super(x * 2); | |
| 1790 final int y; | |
| 1791 }'''); | |
| 1792 EvaluationResultImpl result = | |
| 1793 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1794 Map<String, DartObjectImpl> fields = _assertType(result, "B"); | |
| 1795 expect(fields, hasLength(2)); | |
| 1796 _assertIntField(fields, "y", 5); | |
| 1797 Map<String, DartObjectImpl> superclassFields = | |
| 1798 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); | |
| 1799 expect(superclassFields, hasLength(1)); | |
| 1800 _assertIntField(superclassFields, "x", 8); | |
| 1801 } | |
| 1802 | |
| 1803 void test_instanceCreationExpression_fieldFormalParameter() { | |
| 1804 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1805 const foo = const A(42); | |
| 1806 class A { | |
| 1807 int x; | |
| 1808 const A(this.x) | |
| 1809 }'''); | |
| 1810 EvaluationResultImpl result = | |
| 1811 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1812 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 1813 expect(fields, hasLength(1)); | |
| 1814 _assertIntField(fields, "x", 42); | |
| 1815 } | |
| 1816 | |
| 1817 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDef
ault() { | |
| 1818 _checkInstanceCreationOptionalParams(true, true, true); | |
| 1819 } | |
| 1820 | |
| 1821 void test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithout
Default() { | |
| 1822 _checkInstanceCreationOptionalParams(true, true, false); | |
| 1823 } | |
| 1824 | |
| 1825 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithD
efault() { | |
| 1826 _checkInstanceCreationOptionalParams(true, false, true); | |
| 1827 } | |
| 1828 | |
| 1829 void test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWitho
utDefault() { | |
| 1830 _checkInstanceCreationOptionalParams(true, false, false); | |
| 1831 } | |
| 1832 | |
| 1833 void test_instanceCreationExpression_implicitSuper() { | |
| 1834 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1835 const foo = const B(4); | |
| 1836 class A { | |
| 1837 const A() : x = 3; | |
| 1838 final int x; | |
| 1839 } | |
| 1840 class B extends A { | |
| 1841 const B(this.y); | |
| 1842 final int y; | |
| 1843 }'''); | |
| 1844 EvaluationResultImpl result = | |
| 1845 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 1846 Map<String, DartObjectImpl> fields = _assertType(result, "B"); | |
| 1847 expect(fields, hasLength(2)); | |
| 1848 _assertIntField(fields, "y", 4); | |
| 1849 Map<String, DartObjectImpl> superclassFields = | |
| 1850 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); | |
| 1851 expect(superclassFields, hasLength(1)); | |
| 1852 _assertIntField(superclassFields, "x", 3); | |
| 1853 } | |
| 1854 | |
| 1855 void test_instanceCreationExpression_nonFactoryRedirect() { | |
| 1856 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1857 const foo = const A.a1(); | |
| 1858 class A { | |
| 1859 const A.a1() : this.a2(); | |
| 1860 const A.a2() : x = 5; | |
| 1861 final int x; | |
| 1862 }'''); | |
| 1863 Map<String, DartObjectImpl> aFields = | |
| 1864 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1865 _assertIntField(aFields, 'x', 5); | |
| 1866 } | |
| 1867 | |
| 1868 void test_instanceCreationExpression_nonFactoryRedirect_arg() { | |
| 1869 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1870 const foo = const A.a1(1); | |
| 1871 class A { | |
| 1872 const A.a1(x) : this.a2(x + 100); | |
| 1873 const A.a2(x) : y = x + 10; | |
| 1874 final int y; | |
| 1875 }'''); | |
| 1876 Map<String, DartObjectImpl> aFields = | |
| 1877 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1878 _assertIntField(aFields, 'y', 111); | |
| 1879 } | |
| 1880 | |
| 1881 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { | |
| 1882 // It is an error to have a cycle in non-factory redirects; however, we | |
| 1883 // need to make sure that even if the error occurs, attempting to evaluate | |
| 1884 // the constant will terminate. | |
| 1885 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1886 const foo = const A(); | |
| 1887 class A { | |
| 1888 const A() : this.b(); | |
| 1889 const A.b() : this(); | |
| 1890 }'''); | |
| 1891 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); | |
| 1892 } | |
| 1893 | |
| 1894 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { | |
| 1895 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1896 const foo = const A.a1(); | |
| 1897 class A { | |
| 1898 const A.a1() : this.a2(); | |
| 1899 const A.a2([x = 100]) : y = x + 10; | |
| 1900 final int y; | |
| 1901 }'''); | |
| 1902 Map<String, DartObjectImpl> aFields = | |
| 1903 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1904 _assertIntField(aFields, 'y', 110); | |
| 1905 } | |
| 1906 | |
| 1907 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { | |
| 1908 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1909 const foo = const A.a1(); | |
| 1910 class A { | |
| 1911 const A.a1() : this.a2(); | |
| 1912 }'''); | |
| 1913 // We don't care what value foo evaluates to (since there is a compile | |
| 1914 // error), but we shouldn't crash, and we should figure | |
| 1915 // out that it evaluates to an instance of class A. | |
| 1916 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1917 } | |
| 1918 | |
| 1919 void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() { | |
| 1920 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1921 const foo = const A.a1(); | |
| 1922 class A { | |
| 1923 const A.a1() : this.a2(); | |
| 1924 A.a2(); | |
| 1925 }'''); | |
| 1926 // We don't care what value foo evaluates to (since there is a compile | |
| 1927 // error), but we shouldn't crash, and we should figure | |
| 1928 // out that it evaluates to an instance of class A. | |
| 1929 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1930 } | |
| 1931 | |
| 1932 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { | |
| 1933 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1934 const foo = const A.a1(); | |
| 1935 class A { | |
| 1936 const A.a1() : this(); | |
| 1937 const A() : x = 5; | |
| 1938 final int x; | |
| 1939 }'''); | |
| 1940 Map<String, DartObjectImpl> aFields = | |
| 1941 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "A"); | |
| 1942 _assertIntField(aFields, 'x', 5); | |
| 1943 } | |
| 1944 | |
| 1945 void test_instanceCreationExpression_redirect() { | |
| 1946 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1947 const foo = const A(); | |
| 1948 class A { | |
| 1949 const factory A() = B; | |
| 1950 } | |
| 1951 class B implements A { | |
| 1952 const B(); | |
| 1953 }'''); | |
| 1954 _assertType(_evaluateTopLevelVariable(compilationUnit, "foo"), "B"); | |
| 1955 } | |
| 1956 | |
| 1957 void test_instanceCreationExpression_redirect_cycle() { | |
| 1958 // It is an error to have a cycle in factory redirects; however, we need | |
| 1959 // to make sure that even if the error occurs, attempting to evaluate the | |
| 1960 // constant will terminate. | |
| 1961 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1962 const foo = const A(); | |
| 1963 class A { | |
| 1964 const factory A() = A.b; | |
| 1965 const factory A.b() = A; | |
| 1966 }'''); | |
| 1967 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); | |
| 1968 } | |
| 1969 | |
| 1970 void test_instanceCreationExpression_redirect_extern() { | |
| 1971 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1972 const foo = const A(); | |
| 1973 class A { | |
| 1974 external const factory A(); | |
| 1975 }'''); | |
| 1976 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); | |
| 1977 } | |
| 1978 | |
| 1979 void test_instanceCreationExpression_redirect_nonConst() { | |
| 1980 // It is an error for a const factory constructor redirect to a non-const | |
| 1981 // constructor; however, we need to make sure that even if the error | |
| 1982 // attempting to evaluate the constant won't cause a crash. | |
| 1983 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1984 const foo = const A(); | |
| 1985 class A { | |
| 1986 const factory A() = A.b; | |
| 1987 A.b(); | |
| 1988 }'''); | |
| 1989 _assertValidUnknown(_evaluateTopLevelVariable(compilationUnit, "foo")); | |
| 1990 } | |
| 1991 | |
| 1992 void test_instanceCreationExpression_redirectWithTypeParams() { | |
| 1993 CompilationUnit compilationUnit = resolveSource(r''' | |
| 1994 class A { | |
| 1995 const factory A(var a) = B<int>; | |
| 1996 } | |
| 1997 | |
| 1998 class B<T> implements A { | |
| 1999 final T x; | |
| 2000 const B(this.x); | |
| 2001 } | |
| 2002 | |
| 2003 const A a = const A(10);'''); | |
| 2004 EvaluationResultImpl result = | |
| 2005 _evaluateTopLevelVariable(compilationUnit, "a"); | |
| 2006 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); | |
| 2007 expect(fields, hasLength(1)); | |
| 2008 _assertIntField(fields, "x", 10); | |
| 2009 } | |
| 2010 | |
| 2011 void test_instanceCreationExpression_redirectWithTypeSubstitution() { | |
| 2012 // To evaluate the redirection of A<int>, | |
| 2013 // A's template argument (T=int) must be substituted | |
| 2014 // into B's template argument (B<U> where U=T) to get B<int>. | |
| 2015 CompilationUnit compilationUnit = resolveSource(r''' | |
| 2016 class A<T> { | |
| 2017 const factory A(var a) = B<T>; | |
| 2018 } | |
| 2019 | |
| 2020 class B<U> implements A { | |
| 2021 final U x; | |
| 2022 const B(this.x); | |
| 2023 } | |
| 2024 | |
| 2025 const A<int> a = const A<int>(10);'''); | |
| 2026 EvaluationResultImpl result = | |
| 2027 _evaluateTopLevelVariable(compilationUnit, "a"); | |
| 2028 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); | |
| 2029 expect(fields, hasLength(1)); | |
| 2030 _assertIntField(fields, "x", 10); | |
| 2031 } | |
| 2032 | |
| 2033 void test_instanceCreationExpression_symbol() { | |
| 2034 CompilationUnit compilationUnit = | |
| 2035 resolveSource("const foo = const Symbol('a');"); | |
| 2036 EvaluationResultImpl evaluationResult = | |
| 2037 _evaluateTopLevelVariable(compilationUnit, "foo"); | |
| 2038 expect(evaluationResult.value, isNotNull); | |
| 2039 DartObjectImpl value = evaluationResult.value; | |
| 2040 expect(value.type, typeProvider.symbolType); | |
| 2041 expect(value.value, "a"); | |
| 2042 } | |
| 2043 | |
| 2044 void test_instanceCreationExpression_withSupertypeParams_explicit() { | |
| 2045 _checkInstanceCreation_withSupertypeParams(true); | |
| 2046 } | |
| 2047 | |
| 2048 void test_instanceCreationExpression_withSupertypeParams_implicit() { | |
| 2049 _checkInstanceCreation_withSupertypeParams(false); | |
| 2050 } | |
| 2051 | |
| 2052 void test_instanceCreationExpression_withTypeParams() { | |
| 2053 CompilationUnit compilationUnit = resolveSource(r''' | |
| 2054 class C<E> { | |
| 2055 const C(); | |
| 2056 } | |
| 2057 const c_int = const C<int>(); | |
| 2058 const c_num = const C<num>();'''); | |
| 2059 EvaluationResultImpl c_int = | |
| 2060 _evaluateTopLevelVariable(compilationUnit, "c_int"); | |
| 2061 _assertType(c_int, "C<int>"); | |
| 2062 DartObjectImpl c_int_value = c_int.value; | |
| 2063 EvaluationResultImpl c_num = | |
| 2064 _evaluateTopLevelVariable(compilationUnit, "c_num"); | |
| 2065 _assertType(c_num, "C<num>"); | |
| 2066 DartObjectImpl c_num_value = c_num.value; | |
| 2067 expect(c_int_value == c_num_value, isFalse); | |
| 2068 } | |
| 2069 | |
| 2070 void test_isValidSymbol() { | |
| 2071 expect(ConstantEvaluationEngine.isValidPublicSymbol(""), isTrue); | |
| 2072 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo"), isTrue); | |
| 2073 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar"), isTrue); | |
| 2074 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$"), isTrue); | |
| 2075 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo\$bar"), isTrue); | |
| 2076 expect(ConstantEvaluationEngine.isValidPublicSymbol("iff"), isTrue); | |
| 2077 expect(ConstantEvaluationEngine.isValidPublicSymbol("gif"), isTrue); | |
| 2078 expect(ConstantEvaluationEngine.isValidPublicSymbol("if\$"), isTrue); | |
| 2079 expect(ConstantEvaluationEngine.isValidPublicSymbol("\$if"), isTrue); | |
| 2080 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo="), isTrue); | |
| 2081 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.bar="), isTrue); | |
| 2082 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.+"), isTrue); | |
| 2083 expect(ConstantEvaluationEngine.isValidPublicSymbol("void"), isTrue); | |
| 2084 expect(ConstantEvaluationEngine.isValidPublicSymbol("_foo"), isFalse); | |
| 2085 expect(ConstantEvaluationEngine.isValidPublicSymbol("_foo.bar"), isFalse); | |
| 2086 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo._bar"), isFalse); | |
| 2087 expect(ConstantEvaluationEngine.isValidPublicSymbol("if"), isFalse); | |
| 2088 expect(ConstantEvaluationEngine.isValidPublicSymbol("if.foo"), isFalse); | |
| 2089 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.if"), isFalse); | |
| 2090 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo=.bar"), isFalse); | |
| 2091 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo."), isFalse); | |
| 2092 expect(ConstantEvaluationEngine.isValidPublicSymbol("+.foo"), isFalse); | |
| 2093 expect(ConstantEvaluationEngine.isValidPublicSymbol("void.foo"), isFalse); | |
| 2094 expect(ConstantEvaluationEngine.isValidPublicSymbol("foo.void"), isFalse); | |
| 2095 } | |
| 2096 | |
| 2097 void test_length_of_improperly_typed_string_expression() { | |
| 2098 // Since type annotations are ignored in unchecked mode, the improper | |
| 2099 // types on s1 and s2 shouldn't prevent us from evaluating i to | |
| 2100 // 'alpha'.length. | |
| 2101 CompilationUnit compilationUnit = resolveSource(''' | |
| 2102 const int s1 = 'alpha'; | |
| 2103 const int s2 = 'beta'; | |
| 2104 const int i = (true ? s1 : s2).length; | |
| 2105 '''); | |
| 2106 ConstTopLevelVariableElementImpl element = | |
| 2107 findTopLevelDeclaration(compilationUnit, 'i').element; | |
| 2108 EvaluationResultImpl result = element.evaluationResult; | |
| 2109 expect(_assertValidInt(result), 5); | |
| 2110 } | |
| 2111 | |
| 2112 void test_length_of_improperly_typed_string_identifier() { | |
| 2113 // Since type annotations are ignored in unchecked mode, the improper type | |
| 2114 // on s shouldn't prevent us from evaluating i to 'alpha'.length. | |
| 2115 CompilationUnit compilationUnit = resolveSource(''' | |
| 2116 const int s = 'alpha'; | |
| 2117 const int i = s.length; | |
| 2118 '''); | |
| 2119 ConstTopLevelVariableElementImpl element = | |
| 2120 findTopLevelDeclaration(compilationUnit, 'i').element; | |
| 2121 EvaluationResultImpl result = element.evaluationResult; | |
| 2122 expect(_assertValidInt(result), 5); | |
| 2123 } | |
| 2124 | |
| 2125 void test_non_static_const_initialized_at_declaration() { | |
| 2126 // Even though non-static consts are not allowed by the language, we need | |
| 2127 // to handle them for error recovery purposes. | |
| 2128 CompilationUnit compilationUnit = resolveSource(''' | |
| 2129 class A { | |
| 2130 const int i = 123; | |
| 2131 const A(); | |
| 2132 } | |
| 2133 | |
| 2134 const A a = const A(); | |
| 2135 '''); | |
| 2136 EvaluationResultImpl result = | |
| 2137 _evaluateTopLevelVariable(compilationUnit, 'a'); | |
| 2138 Map<String, DartObjectImpl> fields = _assertType(result, "A"); | |
| 2139 expect(fields, hasLength(1)); | |
| 2140 _assertIntField(fields, "i", 123); | |
| 2141 } | |
| 2142 | |
| 2143 void test_symbolLiteral_void() { | |
| 2144 CompilationUnit compilationUnit = | |
| 2145 resolveSource("const voidSymbol = #void;"); | |
| 2146 VariableDeclaration voidSymbol = | |
| 2147 findTopLevelDeclaration(compilationUnit, "voidSymbol"); | |
| 2148 EvaluationResultImpl voidSymbolResult = | |
| 2149 (voidSymbol.element as VariableElementImpl).evaluationResult; | |
| 2150 DartObjectImpl value = voidSymbolResult.value; | |
| 2151 expect(value.type, typeProvider.symbolType); | |
| 2152 expect(value.value, "void"); | |
| 2153 } | |
| 2154 | |
| 2155 Map<String, DartObjectImpl> _assertFieldType( | |
| 2156 Map<String, DartObjectImpl> fields, | |
| 2157 String fieldName, | |
| 2158 String expectedType) { | |
| 2159 DartObjectImpl field = fields[fieldName]; | |
| 2160 expect(field.type.displayName, expectedType); | |
| 2161 return field.fields; | |
| 2162 } | |
| 2163 | |
| 2164 void _assertIntField( | |
| 2165 Map<String, DartObjectImpl> fields, String fieldName, int expectedValue) { | |
| 2166 DartObjectImpl field = fields[fieldName]; | |
| 2167 expect(field.type.name, "int"); | |
| 2168 expect(field.toIntValue(), expectedValue); | |
| 2169 } | |
| 2170 | |
| 2171 void _assertNullField(Map<String, DartObjectImpl> fields, String fieldName) { | |
| 2172 DartObjectImpl field = fields[fieldName]; | |
| 2173 expect(field.isNull, isTrue); | |
| 2174 } | |
| 2175 | |
| 2176 void _assertProperDependencies(String sourceText, | |
| 2177 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) { | |
| 2178 Source source = addSource(sourceText); | |
| 2179 LibraryElement element = resolve2(source); | |
| 2180 CompilationUnit unit = | |
| 2181 analysisContext.resolveCompilationUnit(source, element); | |
| 2182 expect(unit, isNotNull); | |
| 2183 ConstantValueComputer computer = _makeConstantValueComputer(); | |
| 2184 computer.add(unit, source, source); | |
| 2185 computer.computeValues(); | |
| 2186 assertErrors(source, expectedErrorCodes); | |
| 2187 } | |
| 2188 | |
| 2189 Map<String, DartObjectImpl> _assertType( | |
| 2190 EvaluationResultImpl result, String typeName) { | |
| 2191 expect(result.value, isNotNull); | |
| 2192 DartObjectImpl value = result.value; | |
| 2193 expect(value.type.displayName, typeName); | |
| 2194 return value.fields; | |
| 2195 } | |
| 2196 | |
| 2197 bool _assertValidBool(EvaluationResultImpl result) { | |
| 2198 expect(result.value, isNotNull); | |
| 2199 DartObjectImpl value = result.value; | |
| 2200 expect(value.type, typeProvider.boolType); | |
| 2201 bool boolValue = value.toBoolValue(); | |
| 2202 expect(boolValue, isNotNull); | |
| 2203 return boolValue; | |
| 2204 } | |
| 2205 | |
| 2206 int _assertValidInt(EvaluationResultImpl result) { | |
| 2207 expect(result.value, isNotNull); | |
| 2208 DartObjectImpl value = result.value; | |
| 2209 expect(value.type, typeProvider.intType); | |
| 2210 return value.toIntValue(); | |
| 2211 } | |
| 2212 | |
| 2213 void _assertValidNull(EvaluationResultImpl result) { | |
| 2214 expect(result.value, isNotNull); | |
| 2215 DartObjectImpl value = result.value; | |
| 2216 expect(value.type, typeProvider.nullType); | |
| 2217 } | |
| 2218 | |
| 2219 String _assertValidString(EvaluationResultImpl result) { | |
| 2220 expect(result.value, isNotNull); | |
| 2221 DartObjectImpl value = result.value; | |
| 2222 expect(value.type, typeProvider.stringType); | |
| 2223 return value.stringValue; | |
| 2224 } | |
| 2225 | |
| 2226 void _assertValidUnknown(EvaluationResultImpl result) { | |
| 2227 expect(result.value, isNotNull); | |
| 2228 DartObjectImpl value = result.value; | |
| 2229 expect(value.isUnknown, isTrue); | |
| 2230 } | |
| 2231 | |
| 2232 EvaluationResultImpl _check_fromEnvironment_bool( | |
| 2233 String valueInEnvironment, String defaultExpr) { | |
| 2234 String envVarName = "x"; | |
| 2235 String varName = "foo"; | |
| 2236 if (valueInEnvironment != null) { | |
| 2237 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | |
| 2238 } | |
| 2239 String defaultArg = | |
| 2240 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | |
| 2241 CompilationUnit compilationUnit = resolveSource( | |
| 2242 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);"
); | |
| 2243 return _evaluateTopLevelVariable(compilationUnit, varName); | |
| 2244 } | |
| 2245 | |
| 2246 EvaluationResultImpl _check_fromEnvironment_int( | |
| 2247 String valueInEnvironment, String defaultExpr) { | |
| 2248 String envVarName = "x"; | |
| 2249 String varName = "foo"; | |
| 2250 if (valueInEnvironment != null) { | |
| 2251 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | |
| 2252 } | |
| 2253 String defaultArg = | |
| 2254 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | |
| 2255 CompilationUnit compilationUnit = resolveSource( | |
| 2256 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);")
; | |
| 2257 return _evaluateTopLevelVariable(compilationUnit, varName); | |
| 2258 } | |
| 2259 | |
| 2260 EvaluationResultImpl _check_fromEnvironment_string( | |
| 2261 String valueInEnvironment, String defaultExpr) { | |
| 2262 String envVarName = "x"; | |
| 2263 String varName = "foo"; | |
| 2264 if (valueInEnvironment != null) { | |
| 2265 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | |
| 2266 } | |
| 2267 String defaultArg = | |
| 2268 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | |
| 2269 CompilationUnit compilationUnit = resolveSource( | |
| 2270 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg)
;"); | |
| 2271 return _evaluateTopLevelVariable(compilationUnit, varName); | |
| 2272 } | |
| 2273 | |
| 2274 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { | |
| 2275 String superCall = isExplicit ? " : super()" : ""; | |
| 2276 CompilationUnit compilationUnit = resolveSource(""" | |
| 2277 class A<T> { | |
| 2278 const A(); | |
| 2279 } | |
| 2280 class B<T, U> extends A<T> { | |
| 2281 const B()$superCall; | |
| 2282 } | |
| 2283 class C<T, U> extends A<U> { | |
| 2284 const C()$superCall; | |
| 2285 } | |
| 2286 const b_int_num = const B<int, num>(); | |
| 2287 const c_int_num = const C<int, num>();"""); | |
| 2288 EvaluationResultImpl b_int_num = | |
| 2289 _evaluateTopLevelVariable(compilationUnit, "b_int_num"); | |
| 2290 Map<String, DartObjectImpl> b_int_num_fields = | |
| 2291 _assertType(b_int_num, "B<int, num>"); | |
| 2292 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); | |
| 2293 EvaluationResultImpl c_int_num = | |
| 2294 _evaluateTopLevelVariable(compilationUnit, "c_int_num"); | |
| 2295 Map<String, DartObjectImpl> c_int_num_fields = | |
| 2296 _assertType(c_int_num, "C<int, num>"); | |
| 2297 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); | |
| 2298 } | |
| 2299 | |
| 2300 void _checkInstanceCreationOptionalParams( | |
| 2301 bool isFieldFormal, bool isNamed, bool hasDefault) { | |
| 2302 String fieldName = "j"; | |
| 2303 String paramName = isFieldFormal ? fieldName : "i"; | |
| 2304 String formalParam = | |
| 2305 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : ""
}"; | |
| 2306 CompilationUnit compilationUnit = resolveSource(""" | |
| 2307 const x = const A(); | |
| 2308 const y = const A(${isNamed ? '$paramName: ' : ''}10); | |
| 2309 class A { | |
| 2310 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? ""
: " : $fieldName = $paramName"}; | |
| 2311 final int $fieldName; | |
| 2312 }"""); | |
| 2313 EvaluationResultImpl x = _evaluateTopLevelVariable(compilationUnit, "x"); | |
| 2314 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); | |
| 2315 expect(fieldsOfX, hasLength(1)); | |
| 2316 if (hasDefault) { | |
| 2317 _assertIntField(fieldsOfX, fieldName, 3); | |
| 2318 } else { | |
| 2319 _assertNullField(fieldsOfX, fieldName); | |
| 2320 } | |
| 2321 EvaluationResultImpl y = _evaluateTopLevelVariable(compilationUnit, "y"); | |
| 2322 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); | |
| 2323 expect(fieldsOfY, hasLength(1)); | |
| 2324 _assertIntField(fieldsOfY, fieldName, 10); | |
| 2325 } | |
| 2326 | |
| 2327 /** | |
| 2328 * Search [compilationUnit] for a class named [className], containing a | |
| 2329 * method [methodName], with exactly one annotation. Return the constant | |
| 2330 * value of the annotation. | |
| 2331 */ | |
| 2332 EvaluationResultImpl _evaluateAnnotation( | |
| 2333 CompilationUnit compilationUnit, String className, String memberName) { | |
| 2334 for (CompilationUnitMember member in compilationUnit.declarations) { | |
| 2335 if (member is ClassDeclaration && member.name.name == className) { | |
| 2336 for (ClassMember classMember in member.members) { | |
| 2337 if (classMember is MethodDeclaration && | |
| 2338 classMember.name.name == memberName) { | |
| 2339 expect(classMember.metadata, hasLength(1)); | |
| 2340 ElementAnnotationImpl elementAnnotation = | |
| 2341 classMember.metadata[0].elementAnnotation; | |
| 2342 return elementAnnotation.evaluationResult; | |
| 2343 } | |
| 2344 } | |
| 2345 } | |
| 2346 } | |
| 2347 fail('Class member not found'); | |
| 2348 return null; | |
| 2349 } | |
| 2350 | |
| 2351 EvaluationResultImpl _evaluateTopLevelVariable( | |
| 2352 CompilationUnit compilationUnit, String name) { | |
| 2353 VariableDeclaration varDecl = | |
| 2354 findTopLevelDeclaration(compilationUnit, name); | |
| 2355 ConstTopLevelVariableElementImpl varElement = varDecl.element; | |
| 2356 return varElement.evaluationResult; | |
| 2357 } | |
| 2358 | |
| 2359 ConstantValueComputer _makeConstantValueComputer() { | |
| 2360 ConstantEvaluationValidator_ForTest validator = | |
| 2361 new ConstantEvaluationValidator_ForTest(); | |
| 2362 validator.computer = new ConstantValueComputer( | |
| 2363 analysisContext2, | |
| 2364 analysisContext2.typeProvider, | |
| 2365 analysisContext2.declaredVariables, | |
| 2366 validator, | |
| 2367 analysisContext2.typeSystem); | |
| 2368 return validator.computer; | |
| 2369 } | |
| 2370 | |
| 2371 void _validate(bool shouldBeValid, VariableDeclarationList declarationList) { | |
| 2372 for (VariableDeclaration declaration in declarationList.variables) { | |
| 2373 VariableElementImpl element = declaration.element as VariableElementImpl; | |
| 2374 expect(element, isNotNull); | |
| 2375 EvaluationResultImpl result = element.evaluationResult; | |
| 2376 if (shouldBeValid) { | |
| 2377 expect(result.value, isNotNull); | |
| 2378 } else { | |
| 2379 expect(result.value, isNull); | |
| 2380 } | |
| 2381 } | |
| 2382 } | |
| 2383 } | |
| 2384 | |
| 2385 @reflectiveTest | |
| 2386 class ConstantVisitorTest extends ResolverTestCase { | |
| 2387 void test_visitConditionalExpression_false() { | |
| 2388 Expression thenExpression = AstFactory.integer(1); | |
| 2389 Expression elseExpression = AstFactory.integer(0); | |
| 2390 ConditionalExpression expression = AstFactory.conditionalExpression( | |
| 2391 AstFactory.booleanLiteral(false), thenExpression, elseExpression); | |
| 2392 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2393 ErrorReporter errorReporter = | |
| 2394 new ErrorReporter(errorListener, _dummySource()); | |
| 2395 _assertValue( | |
| 2396 0, | |
| 2397 expression.accept(new ConstantVisitor( | |
| 2398 new ConstantEvaluationEngine( | |
| 2399 new TestTypeProvider(), new DeclaredVariables(), | |
| 2400 typeSystem: new TypeSystemImpl()), | |
| 2401 errorReporter))); | |
| 2402 errorListener.assertNoErrors(); | |
| 2403 } | |
| 2404 | |
| 2405 void test_visitConditionalExpression_nonBooleanCondition() { | |
| 2406 Expression thenExpression = AstFactory.integer(1); | |
| 2407 Expression elseExpression = AstFactory.integer(0); | |
| 2408 NullLiteral conditionExpression = AstFactory.nullLiteral(); | |
| 2409 ConditionalExpression expression = AstFactory.conditionalExpression( | |
| 2410 conditionExpression, thenExpression, elseExpression); | |
| 2411 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2412 ErrorReporter errorReporter = | |
| 2413 new ErrorReporter(errorListener, _dummySource()); | |
| 2414 DartObjectImpl result = expression.accept(new ConstantVisitor( | |
| 2415 new ConstantEvaluationEngine( | |
| 2416 new TestTypeProvider(), new DeclaredVariables(), | |
| 2417 typeSystem: new TypeSystemImpl()), | |
| 2418 errorReporter)); | |
| 2419 expect(result, isNull); | |
| 2420 errorListener | |
| 2421 .assertErrorsWithCodes([CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL]); | |
| 2422 } | |
| 2423 | |
| 2424 void test_visitConditionalExpression_nonConstantElse() { | |
| 2425 Expression thenExpression = AstFactory.integer(1); | |
| 2426 Expression elseExpression = AstFactory.identifier3("x"); | |
| 2427 ConditionalExpression expression = AstFactory.conditionalExpression( | |
| 2428 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | |
| 2429 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2430 ErrorReporter errorReporter = | |
| 2431 new ErrorReporter(errorListener, _dummySource()); | |
| 2432 DartObjectImpl result = expression.accept(new ConstantVisitor( | |
| 2433 new ConstantEvaluationEngine( | |
| 2434 new TestTypeProvider(), new DeclaredVariables(), | |
| 2435 typeSystem: new TypeSystemImpl()), | |
| 2436 errorReporter)); | |
| 2437 expect(result, isNull); | |
| 2438 errorListener | |
| 2439 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | |
| 2440 } | |
| 2441 | |
| 2442 void test_visitConditionalExpression_nonConstantThen() { | |
| 2443 Expression thenExpression = AstFactory.identifier3("x"); | |
| 2444 Expression elseExpression = AstFactory.integer(0); | |
| 2445 ConditionalExpression expression = AstFactory.conditionalExpression( | |
| 2446 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | |
| 2447 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2448 ErrorReporter errorReporter = | |
| 2449 new ErrorReporter(errorListener, _dummySource()); | |
| 2450 DartObjectImpl result = expression.accept(new ConstantVisitor( | |
| 2451 new ConstantEvaluationEngine( | |
| 2452 new TestTypeProvider(), new DeclaredVariables(), | |
| 2453 typeSystem: new TypeSystemImpl()), | |
| 2454 errorReporter)); | |
| 2455 expect(result, isNull); | |
| 2456 errorListener | |
| 2457 .assertErrorsWithCodes([CompileTimeErrorCode.INVALID_CONSTANT]); | |
| 2458 } | |
| 2459 | |
| 2460 void test_visitConditionalExpression_true() { | |
| 2461 Expression thenExpression = AstFactory.integer(1); | |
| 2462 Expression elseExpression = AstFactory.integer(0); | |
| 2463 ConditionalExpression expression = AstFactory.conditionalExpression( | |
| 2464 AstFactory.booleanLiteral(true), thenExpression, elseExpression); | |
| 2465 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2466 ErrorReporter errorReporter = | |
| 2467 new ErrorReporter(errorListener, _dummySource()); | |
| 2468 _assertValue( | |
| 2469 1, | |
| 2470 expression.accept(new ConstantVisitor( | |
| 2471 new ConstantEvaluationEngine( | |
| 2472 new TestTypeProvider(), new DeclaredVariables(), | |
| 2473 typeSystem: new TypeSystemImpl()), | |
| 2474 errorReporter))); | |
| 2475 errorListener.assertNoErrors(); | |
| 2476 } | |
| 2477 | |
| 2478 void test_visitSimpleIdentifier_className() { | |
| 2479 CompilationUnit compilationUnit = resolveSource(''' | |
| 2480 const a = C; | |
| 2481 class C {} | |
| 2482 '''); | |
| 2483 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); | |
| 2484 expect(result.type, typeProvider.typeType); | |
| 2485 ClassElement element = result.value; | |
| 2486 expect(element.name, 'C'); | |
| 2487 } | |
| 2488 | |
| 2489 void test_visitSimpleIdentifier_dynamic() { | |
| 2490 CompilationUnit compilationUnit = resolveSource(''' | |
| 2491 const a = dynamic; | |
| 2492 '''); | |
| 2493 DartObjectImpl result = _evaluateConstant(compilationUnit, 'a', null); | |
| 2494 expect(result.type, typeProvider.typeType); | |
| 2495 expect(result.value, typeProvider.dynamicType.element); | |
| 2496 } | |
| 2497 | |
| 2498 void test_visitSimpleIdentifier_inEnvironment() { | |
| 2499 CompilationUnit compilationUnit = resolveSource(r''' | |
| 2500 const a = b; | |
| 2501 const b = 3;'''); | |
| 2502 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); | |
| 2503 DartObjectImpl six = | |
| 2504 new DartObjectImpl(typeProvider.intType, new IntState(6)); | |
| 2505 environment["b"] = six; | |
| 2506 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment)); | |
| 2507 } | |
| 2508 | |
| 2509 void test_visitSimpleIdentifier_notInEnvironment() { | |
| 2510 CompilationUnit compilationUnit = resolveSource(r''' | |
| 2511 const a = b; | |
| 2512 const b = 3;'''); | |
| 2513 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); | |
| 2514 DartObjectImpl six = | |
| 2515 new DartObjectImpl(typeProvider.intType, new IntState(6)); | |
| 2516 environment["c"] = six; | |
| 2517 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment)); | |
| 2518 } | |
| 2519 | |
| 2520 void test_visitSimpleIdentifier_withoutEnvironment() { | |
| 2521 CompilationUnit compilationUnit = resolveSource(r''' | |
| 2522 const a = b; | |
| 2523 const b = 3;'''); | |
| 2524 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); | |
| 2525 } | |
| 2526 | |
| 2527 void _assertValue(int expectedValue, DartObjectImpl result) { | |
| 2528 expect(result, isNotNull); | |
| 2529 expect(result.type.name, "int"); | |
| 2530 expect(result.toIntValue(), expectedValue); | |
| 2531 } | |
| 2532 | |
| 2533 NonExistingSource _dummySource() { | |
| 2534 String path = '/test.dart'; | |
| 2535 return new NonExistingSource(path, toUri(path), UriKind.FILE_URI); | |
| 2536 } | |
| 2537 | |
| 2538 DartObjectImpl _evaluateConstant(CompilationUnit compilationUnit, String name, | |
| 2539 Map<String, DartObjectImpl> lexicalEnvironment) { | |
| 2540 Source source = compilationUnit.element.source; | |
| 2541 Expression expression = | |
| 2542 findTopLevelConstantExpression(compilationUnit, name); | |
| 2543 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 2544 ErrorReporter errorReporter = new ErrorReporter(errorListener, source); | |
| 2545 DartObjectImpl result = expression.accept(new ConstantVisitor( | |
| 2546 new ConstantEvaluationEngine(typeProvider, new DeclaredVariables(), | |
| 2547 typeSystem: typeSystem), | |
| 2548 errorReporter, | |
| 2549 lexicalEnvironment: lexicalEnvironment)); | |
| 2550 errorListener.assertNoErrors(); | |
| 2551 return result; | |
| 2552 } | |
| 2553 } | 94 } |
| 2554 | 95 |
| 2555 @reflectiveTest | 96 @reflectiveTest |
| 2556 class ContentCacheTest { | 97 class ContentCacheTest { |
| 2557 void test_setContents() { | 98 void test_setContents() { |
| 2558 Source source = new TestSource(); | 99 Source source = new TestSource(); |
| 2559 ContentCache cache = new ContentCache(); | 100 ContentCache cache = new ContentCache(); |
| 2560 expect(cache.getContents(source), isNull); | 101 expect(cache.getContents(source), isNull); |
| 2561 expect(cache.getModificationStamp(source), isNull); | 102 expect(cache.getModificationStamp(source), isNull); |
| 2562 String contents = "library lib;"; | 103 String contents = "library lib;"; |
| 2563 expect(cache.setContents(source, contents), isNull); | 104 expect(cache.setContents(source, contents), isNull); |
| 2564 expect(cache.getContents(source), contents); | 105 expect(cache.getContents(source), contents); |
| 2565 expect(cache.getModificationStamp(source), isNotNull); | 106 expect(cache.getModificationStamp(source), isNotNull); |
| 2566 expect(cache.setContents(source, contents), contents); | 107 expect(cache.setContents(source, contents), contents); |
| 2567 expect(cache.setContents(source, null), contents); | 108 expect(cache.setContents(source, null), contents); |
| 2568 expect(cache.getContents(source), isNull); | 109 expect(cache.getContents(source), isNull); |
| 2569 expect(cache.getModificationStamp(source), isNull); | 110 expect(cache.getModificationStamp(source), isNull); |
| 2570 expect(cache.setContents(source, null), isNull); | 111 expect(cache.setContents(source, null), isNull); |
| 2571 } | 112 } |
| 2572 } | 113 } |
| 2573 | 114 |
| 115 @deprecated |
| 2574 @reflectiveTest | 116 @reflectiveTest |
| 2575 class CustomUriResolverTest { | 117 class CustomUriResolverTest { |
| 2576 void test_creation() { | 118 void test_creation() { |
| 2577 expect(new CustomUriResolver({}), isNotNull); | 119 expect(new CustomUriResolver({}), isNotNull); |
| 2578 } | 120 } |
| 2579 | 121 |
| 2580 void test_resolve_unknown_uri() { | 122 void test_resolve_unknown_uri() { |
| 2581 UriResolver resolver = | 123 UriResolver resolver = new CustomUriResolver({ |
| 2582 new CustomUriResolver({'custom:library': '/path/to/library.dart',}); | 124 'custom:library': '/path/to/library.dart', |
| 2583 Source result = | 125 }); |
| 2584 resolver.resolveAbsolute(parseUriWithException("custom:non_library")); | 126 Source result = resolver.resolveAbsolute(Uri.parse("custom:non_library")); |
| 2585 expect(result, isNull); | 127 expect(result, isNull); |
| 2586 } | 128 } |
| 2587 | 129 |
| 2588 void test_resolve_uri() { | 130 void test_resolve_uri() { |
| 2589 String path = | 131 String path = |
| 2590 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath(); | 132 FileUtilities2.createFile("/path/to/library.dart").getAbsolutePath(); |
| 2591 UriResolver resolver = new CustomUriResolver({'custom:library': path,}); | 133 UriResolver resolver = new CustomUriResolver({ |
| 2592 Source result = | 134 'custom:library': path, |
| 2593 resolver.resolveAbsolute(parseUriWithException("custom:library")); | 135 }); |
| 136 Source result = resolver.resolveAbsolute(Uri.parse("custom:library")); |
| 2594 expect(result, isNotNull); | 137 expect(result, isNotNull); |
| 2595 expect(result.fullName, path); | 138 expect(result.fullName, path); |
| 2596 } | 139 } |
| 2597 } | 140 } |
| 2598 | 141 |
| 2599 @reflectiveTest | 142 @reflectiveTest |
| 2600 class DartObjectImplTest extends EngineTestCase { | |
| 2601 TypeProvider _typeProvider = new TestTypeProvider(); | |
| 2602 | |
| 2603 void test_add_knownDouble_knownDouble() { | |
| 2604 _assertAdd(_doubleValue(3.0), _doubleValue(1.0), _doubleValue(2.0)); | |
| 2605 } | |
| 2606 | |
| 2607 void test_add_knownDouble_knownInt() { | |
| 2608 _assertAdd(_doubleValue(3.0), _doubleValue(1.0), _intValue(2)); | |
| 2609 } | |
| 2610 | |
| 2611 void test_add_knownDouble_unknownDouble() { | |
| 2612 _assertAdd(_doubleValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 2613 } | |
| 2614 | |
| 2615 void test_add_knownDouble_unknownInt() { | |
| 2616 _assertAdd(_doubleValue(null), _doubleValue(1.0), _intValue(null)); | |
| 2617 } | |
| 2618 | |
| 2619 void test_add_knownInt_knownInt() { | |
| 2620 _assertAdd(_intValue(3), _intValue(1), _intValue(2)); | |
| 2621 } | |
| 2622 | |
| 2623 void test_add_knownInt_knownString() { | |
| 2624 _assertAdd(null, _intValue(1), _stringValue("2")); | |
| 2625 } | |
| 2626 | |
| 2627 void test_add_knownInt_unknownDouble() { | |
| 2628 _assertAdd(_doubleValue(null), _intValue(1), _doubleValue(null)); | |
| 2629 } | |
| 2630 | |
| 2631 void test_add_knownInt_unknownInt() { | |
| 2632 _assertAdd(_intValue(null), _intValue(1), _intValue(null)); | |
| 2633 } | |
| 2634 | |
| 2635 void test_add_knownString_knownInt() { | |
| 2636 _assertAdd(null, _stringValue("1"), _intValue(2)); | |
| 2637 } | |
| 2638 | |
| 2639 void test_add_knownString_knownString() { | |
| 2640 _assertAdd(_stringValue("ab"), _stringValue("a"), _stringValue("b")); | |
| 2641 } | |
| 2642 | |
| 2643 void test_add_knownString_unknownString() { | |
| 2644 _assertAdd(_stringValue(null), _stringValue("a"), _stringValue(null)); | |
| 2645 } | |
| 2646 | |
| 2647 void test_add_unknownDouble_knownDouble() { | |
| 2648 _assertAdd(_doubleValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 2649 } | |
| 2650 | |
| 2651 void test_add_unknownDouble_knownInt() { | |
| 2652 _assertAdd(_doubleValue(null), _doubleValue(null), _intValue(2)); | |
| 2653 } | |
| 2654 | |
| 2655 void test_add_unknownInt_knownDouble() { | |
| 2656 _assertAdd(_doubleValue(null), _intValue(null), _doubleValue(2.0)); | |
| 2657 } | |
| 2658 | |
| 2659 void test_add_unknownInt_knownInt() { | |
| 2660 _assertAdd(_intValue(null), _intValue(null), _intValue(2)); | |
| 2661 } | |
| 2662 | |
| 2663 void test_add_unknownString_knownString() { | |
| 2664 _assertAdd(_stringValue(null), _stringValue(null), _stringValue("b")); | |
| 2665 } | |
| 2666 | |
| 2667 void test_add_unknownString_unknownString() { | |
| 2668 _assertAdd(_stringValue(null), _stringValue(null), _stringValue(null)); | |
| 2669 } | |
| 2670 | |
| 2671 void test_bitAnd_knownInt_knownInt() { | |
| 2672 _assertBitAnd(_intValue(2), _intValue(6), _intValue(3)); | |
| 2673 } | |
| 2674 | |
| 2675 void test_bitAnd_knownInt_knownString() { | |
| 2676 _assertBitAnd(null, _intValue(6), _stringValue("3")); | |
| 2677 } | |
| 2678 | |
| 2679 void test_bitAnd_knownInt_unknownInt() { | |
| 2680 _assertBitAnd(_intValue(null), _intValue(6), _intValue(null)); | |
| 2681 } | |
| 2682 | |
| 2683 void test_bitAnd_knownString_knownInt() { | |
| 2684 _assertBitAnd(null, _stringValue("6"), _intValue(3)); | |
| 2685 } | |
| 2686 | |
| 2687 void test_bitAnd_unknownInt_knownInt() { | |
| 2688 _assertBitAnd(_intValue(null), _intValue(null), _intValue(3)); | |
| 2689 } | |
| 2690 | |
| 2691 void test_bitAnd_unknownInt_unknownInt() { | |
| 2692 _assertBitAnd(_intValue(null), _intValue(null), _intValue(null)); | |
| 2693 } | |
| 2694 | |
| 2695 void test_bitNot_knownInt() { | |
| 2696 _assertBitNot(_intValue(-4), _intValue(3)); | |
| 2697 } | |
| 2698 | |
| 2699 void test_bitNot_knownString() { | |
| 2700 _assertBitNot(null, _stringValue("6")); | |
| 2701 } | |
| 2702 | |
| 2703 void test_bitNot_unknownInt() { | |
| 2704 _assertBitNot(_intValue(null), _intValue(null)); | |
| 2705 } | |
| 2706 | |
| 2707 void test_bitOr_knownInt_knownInt() { | |
| 2708 _assertBitOr(_intValue(7), _intValue(6), _intValue(3)); | |
| 2709 } | |
| 2710 | |
| 2711 void test_bitOr_knownInt_knownString() { | |
| 2712 _assertBitOr(null, _intValue(6), _stringValue("3")); | |
| 2713 } | |
| 2714 | |
| 2715 void test_bitOr_knownInt_unknownInt() { | |
| 2716 _assertBitOr(_intValue(null), _intValue(6), _intValue(null)); | |
| 2717 } | |
| 2718 | |
| 2719 void test_bitOr_knownString_knownInt() { | |
| 2720 _assertBitOr(null, _stringValue("6"), _intValue(3)); | |
| 2721 } | |
| 2722 | |
| 2723 void test_bitOr_unknownInt_knownInt() { | |
| 2724 _assertBitOr(_intValue(null), _intValue(null), _intValue(3)); | |
| 2725 } | |
| 2726 | |
| 2727 void test_bitOr_unknownInt_unknownInt() { | |
| 2728 _assertBitOr(_intValue(null), _intValue(null), _intValue(null)); | |
| 2729 } | |
| 2730 | |
| 2731 void test_bitXor_knownInt_knownInt() { | |
| 2732 _assertBitXor(_intValue(5), _intValue(6), _intValue(3)); | |
| 2733 } | |
| 2734 | |
| 2735 void test_bitXor_knownInt_knownString() { | |
| 2736 _assertBitXor(null, _intValue(6), _stringValue("3")); | |
| 2737 } | |
| 2738 | |
| 2739 void test_bitXor_knownInt_unknownInt() { | |
| 2740 _assertBitXor(_intValue(null), _intValue(6), _intValue(null)); | |
| 2741 } | |
| 2742 | |
| 2743 void test_bitXor_knownString_knownInt() { | |
| 2744 _assertBitXor(null, _stringValue("6"), _intValue(3)); | |
| 2745 } | |
| 2746 | |
| 2747 void test_bitXor_unknownInt_knownInt() { | |
| 2748 _assertBitXor(_intValue(null), _intValue(null), _intValue(3)); | |
| 2749 } | |
| 2750 | |
| 2751 void test_bitXor_unknownInt_unknownInt() { | |
| 2752 _assertBitXor(_intValue(null), _intValue(null), _intValue(null)); | |
| 2753 } | |
| 2754 | |
| 2755 void test_concatenate_knownInt_knownString() { | |
| 2756 _assertConcatenate(null, _intValue(2), _stringValue("def")); | |
| 2757 } | |
| 2758 | |
| 2759 void test_concatenate_knownString_knownInt() { | |
| 2760 _assertConcatenate(null, _stringValue("abc"), _intValue(3)); | |
| 2761 } | |
| 2762 | |
| 2763 void test_concatenate_knownString_knownString() { | |
| 2764 _assertConcatenate( | |
| 2765 _stringValue("abcdef"), _stringValue("abc"), _stringValue("def")); | |
| 2766 } | |
| 2767 | |
| 2768 void test_concatenate_knownString_unknownString() { | |
| 2769 _assertConcatenate( | |
| 2770 _stringValue(null), _stringValue("abc"), _stringValue(null)); | |
| 2771 } | |
| 2772 | |
| 2773 void test_concatenate_unknownString_knownString() { | |
| 2774 _assertConcatenate( | |
| 2775 _stringValue(null), _stringValue(null), _stringValue("def")); | |
| 2776 } | |
| 2777 | |
| 2778 void test_divide_knownDouble_knownDouble() { | |
| 2779 _assertDivide(_doubleValue(3.0), _doubleValue(6.0), _doubleValue(2.0)); | |
| 2780 } | |
| 2781 | |
| 2782 void test_divide_knownDouble_knownInt() { | |
| 2783 _assertDivide(_doubleValue(3.0), _doubleValue(6.0), _intValue(2)); | |
| 2784 } | |
| 2785 | |
| 2786 void test_divide_knownDouble_unknownDouble() { | |
| 2787 _assertDivide(_doubleValue(null), _doubleValue(6.0), _doubleValue(null)); | |
| 2788 } | |
| 2789 | |
| 2790 void test_divide_knownDouble_unknownInt() { | |
| 2791 _assertDivide(_doubleValue(null), _doubleValue(6.0), _intValue(null)); | |
| 2792 } | |
| 2793 | |
| 2794 void test_divide_knownInt_knownInt() { | |
| 2795 _assertDivide(_doubleValue(3.0), _intValue(6), _intValue(2)); | |
| 2796 } | |
| 2797 | |
| 2798 void test_divide_knownInt_knownString() { | |
| 2799 _assertDivide(null, _intValue(6), _stringValue("2")); | |
| 2800 } | |
| 2801 | |
| 2802 void test_divide_knownInt_unknownDouble() { | |
| 2803 _assertDivide(_doubleValue(null), _intValue(6), _doubleValue(null)); | |
| 2804 } | |
| 2805 | |
| 2806 void test_divide_knownInt_unknownInt() { | |
| 2807 _assertDivide(_doubleValue(null), _intValue(6), _intValue(null)); | |
| 2808 } | |
| 2809 | |
| 2810 void test_divide_knownString_knownInt() { | |
| 2811 _assertDivide(null, _stringValue("6"), _intValue(2)); | |
| 2812 } | |
| 2813 | |
| 2814 void test_divide_unknownDouble_knownDouble() { | |
| 2815 _assertDivide(_doubleValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 2816 } | |
| 2817 | |
| 2818 void test_divide_unknownDouble_knownInt() { | |
| 2819 _assertDivide(_doubleValue(null), _doubleValue(null), _intValue(2)); | |
| 2820 } | |
| 2821 | |
| 2822 void test_divide_unknownInt_knownDouble() { | |
| 2823 _assertDivide(_doubleValue(null), _intValue(null), _doubleValue(2.0)); | |
| 2824 } | |
| 2825 | |
| 2826 void test_divide_unknownInt_knownInt() { | |
| 2827 _assertDivide(_doubleValue(null), _intValue(null), _intValue(2)); | |
| 2828 } | |
| 2829 | |
| 2830 void test_equalEqual_bool_false() { | |
| 2831 _assertEqualEqual(_boolValue(false), _boolValue(false), _boolValue(true)); | |
| 2832 } | |
| 2833 | |
| 2834 void test_equalEqual_bool_true() { | |
| 2835 _assertEqualEqual(_boolValue(true), _boolValue(true), _boolValue(true)); | |
| 2836 } | |
| 2837 | |
| 2838 void test_equalEqual_bool_unknown() { | |
| 2839 _assertEqualEqual(_boolValue(null), _boolValue(null), _boolValue(false)); | |
| 2840 } | |
| 2841 | |
| 2842 void test_equalEqual_double_false() { | |
| 2843 _assertEqualEqual(_boolValue(false), _doubleValue(2.0), _doubleValue(4.0)); | |
| 2844 } | |
| 2845 | |
| 2846 void test_equalEqual_double_true() { | |
| 2847 _assertEqualEqual(_boolValue(true), _doubleValue(2.0), _doubleValue(2.0)); | |
| 2848 } | |
| 2849 | |
| 2850 void test_equalEqual_double_unknown() { | |
| 2851 _assertEqualEqual(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 2852 } | |
| 2853 | |
| 2854 void test_equalEqual_int_false() { | |
| 2855 _assertEqualEqual(_boolValue(false), _intValue(-5), _intValue(5)); | |
| 2856 } | |
| 2857 | |
| 2858 void test_equalEqual_int_true() { | |
| 2859 _assertEqualEqual(_boolValue(true), _intValue(5), _intValue(5)); | |
| 2860 } | |
| 2861 | |
| 2862 void test_equalEqual_int_unknown() { | |
| 2863 _assertEqualEqual(_boolValue(null), _intValue(null), _intValue(3)); | |
| 2864 } | |
| 2865 | |
| 2866 void test_equalEqual_list_empty() { | |
| 2867 _assertEqualEqual(null, _listValue(), _listValue()); | |
| 2868 } | |
| 2869 | |
| 2870 void test_equalEqual_list_false() { | |
| 2871 _assertEqualEqual(null, _listValue(), _listValue()); | |
| 2872 } | |
| 2873 | |
| 2874 void test_equalEqual_map_empty() { | |
| 2875 _assertEqualEqual(null, _mapValue(), _mapValue()); | |
| 2876 } | |
| 2877 | |
| 2878 void test_equalEqual_map_false() { | |
| 2879 _assertEqualEqual(null, _mapValue(), _mapValue()); | |
| 2880 } | |
| 2881 | |
| 2882 void test_equalEqual_null() { | |
| 2883 _assertEqualEqual(_boolValue(true), _nullValue(), _nullValue()); | |
| 2884 } | |
| 2885 | |
| 2886 void test_equalEqual_string_false() { | |
| 2887 _assertEqualEqual( | |
| 2888 _boolValue(false), _stringValue("abc"), _stringValue("def")); | |
| 2889 } | |
| 2890 | |
| 2891 void test_equalEqual_string_true() { | |
| 2892 _assertEqualEqual( | |
| 2893 _boolValue(true), _stringValue("abc"), _stringValue("abc")); | |
| 2894 } | |
| 2895 | |
| 2896 void test_equalEqual_string_unknown() { | |
| 2897 _assertEqualEqual( | |
| 2898 _boolValue(null), _stringValue(null), _stringValue("def")); | |
| 2899 } | |
| 2900 | |
| 2901 void test_equals_list_false_differentSizes() { | |
| 2902 expect( | |
| 2903 _listValue([_boolValue(true)]) == | |
| 2904 _listValue([_boolValue(true), _boolValue(false)]), | |
| 2905 isFalse); | |
| 2906 } | |
| 2907 | |
| 2908 void test_equals_list_false_sameSize() { | |
| 2909 expect(_listValue([_boolValue(true)]) == _listValue([_boolValue(false)]), | |
| 2910 isFalse); | |
| 2911 } | |
| 2912 | |
| 2913 void test_equals_list_true_empty() { | |
| 2914 expect(_listValue(), _listValue()); | |
| 2915 } | |
| 2916 | |
| 2917 void test_equals_list_true_nonEmpty() { | |
| 2918 expect(_listValue([_boolValue(true)]), _listValue([_boolValue(true)])); | |
| 2919 } | |
| 2920 | |
| 2921 void test_equals_map_true_empty() { | |
| 2922 expect(_mapValue(), _mapValue()); | |
| 2923 } | |
| 2924 | |
| 2925 void test_equals_symbol_false() { | |
| 2926 expect(_symbolValue("a") == _symbolValue("b"), isFalse); | |
| 2927 } | |
| 2928 | |
| 2929 void test_equals_symbol_true() { | |
| 2930 expect(_symbolValue("a"), _symbolValue("a")); | |
| 2931 } | |
| 2932 | |
| 2933 void test_getValue_bool_false() { | |
| 2934 expect(_boolValue(false).value, false); | |
| 2935 } | |
| 2936 | |
| 2937 void test_getValue_bool_true() { | |
| 2938 expect(_boolValue(true).value, true); | |
| 2939 } | |
| 2940 | |
| 2941 void test_getValue_bool_unknown() { | |
| 2942 expect(_boolValue(null).value, isNull); | |
| 2943 } | |
| 2944 | |
| 2945 void test_getValue_double_known() { | |
| 2946 double value = 2.3; | |
| 2947 expect(_doubleValue(value).value, value); | |
| 2948 } | |
| 2949 | |
| 2950 void test_getValue_double_unknown() { | |
| 2951 expect(_doubleValue(null).value, isNull); | |
| 2952 } | |
| 2953 | |
| 2954 void test_getValue_int_known() { | |
| 2955 int value = 23; | |
| 2956 expect(_intValue(value).value, value); | |
| 2957 } | |
| 2958 | |
| 2959 void test_getValue_int_unknown() { | |
| 2960 expect(_intValue(null).value, isNull); | |
| 2961 } | |
| 2962 | |
| 2963 void test_getValue_list_empty() { | |
| 2964 Object result = _listValue().value; | |
| 2965 _assertInstanceOfObjectArray(result); | |
| 2966 List<Object> array = result as List<Object>; | |
| 2967 expect(array, hasLength(0)); | |
| 2968 } | |
| 2969 | |
| 2970 void test_getValue_list_valid() { | |
| 2971 Object result = _listValue([_intValue(23)]).value; | |
| 2972 _assertInstanceOfObjectArray(result); | |
| 2973 List<Object> array = result as List<Object>; | |
| 2974 expect(array, hasLength(1)); | |
| 2975 } | |
| 2976 | |
| 2977 void test_getValue_map_empty() { | |
| 2978 Object result = _mapValue().value; | |
| 2979 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result); | |
| 2980 Map map = result as Map; | |
| 2981 expect(map, hasLength(0)); | |
| 2982 } | |
| 2983 | |
| 2984 void test_getValue_map_valid() { | |
| 2985 Object result = | |
| 2986 _mapValue([_stringValue("key"), _stringValue("value")]).value; | |
| 2987 EngineTestCase.assertInstanceOf((obj) => obj is Map, Map, result); | |
| 2988 Map map = result as Map; | |
| 2989 expect(map, hasLength(1)); | |
| 2990 } | |
| 2991 | |
| 2992 void test_getValue_null() { | |
| 2993 expect(_nullValue().value, isNull); | |
| 2994 } | |
| 2995 | |
| 2996 void test_getValue_string_known() { | |
| 2997 String value = "twenty-three"; | |
| 2998 expect(_stringValue(value).value, value); | |
| 2999 } | |
| 3000 | |
| 3001 void test_getValue_string_unknown() { | |
| 3002 expect(_stringValue(null).value, isNull); | |
| 3003 } | |
| 3004 | |
| 3005 void test_greaterThan_knownDouble_knownDouble_false() { | |
| 3006 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _doubleValue(2.0)); | |
| 3007 } | |
| 3008 | |
| 3009 void test_greaterThan_knownDouble_knownDouble_true() { | |
| 3010 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _doubleValue(1.0)); | |
| 3011 } | |
| 3012 | |
| 3013 void test_greaterThan_knownDouble_knownInt_false() { | |
| 3014 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _intValue(2)); | |
| 3015 } | |
| 3016 | |
| 3017 void test_greaterThan_knownDouble_knownInt_true() { | |
| 3018 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _intValue(1)); | |
| 3019 } | |
| 3020 | |
| 3021 void test_greaterThan_knownDouble_unknownDouble() { | |
| 3022 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3023 } | |
| 3024 | |
| 3025 void test_greaterThan_knownDouble_unknownInt() { | |
| 3026 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); | |
| 3027 } | |
| 3028 | |
| 3029 void test_greaterThan_knownInt_knownInt_false() { | |
| 3030 _assertGreaterThan(_boolValue(false), _intValue(1), _intValue(2)); | |
| 3031 } | |
| 3032 | |
| 3033 void test_greaterThan_knownInt_knownInt_true() { | |
| 3034 _assertGreaterThan(_boolValue(true), _intValue(2), _intValue(1)); | |
| 3035 } | |
| 3036 | |
| 3037 void test_greaterThan_knownInt_knownString() { | |
| 3038 _assertGreaterThan(null, _intValue(1), _stringValue("2")); | |
| 3039 } | |
| 3040 | |
| 3041 void test_greaterThan_knownInt_unknownDouble() { | |
| 3042 _assertGreaterThan(_boolValue(null), _intValue(1), _doubleValue(null)); | |
| 3043 } | |
| 3044 | |
| 3045 void test_greaterThan_knownInt_unknownInt() { | |
| 3046 _assertGreaterThan(_boolValue(null), _intValue(1), _intValue(null)); | |
| 3047 } | |
| 3048 | |
| 3049 void test_greaterThan_knownString_knownInt() { | |
| 3050 _assertGreaterThan(null, _stringValue("1"), _intValue(2)); | |
| 3051 } | |
| 3052 | |
| 3053 void test_greaterThan_unknownDouble_knownDouble() { | |
| 3054 _assertGreaterThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3055 } | |
| 3056 | |
| 3057 void test_greaterThan_unknownDouble_knownInt() { | |
| 3058 _assertGreaterThan(_boolValue(null), _doubleValue(null), _intValue(2)); | |
| 3059 } | |
| 3060 | |
| 3061 void test_greaterThan_unknownInt_knownDouble() { | |
| 3062 _assertGreaterThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3063 } | |
| 3064 | |
| 3065 void test_greaterThan_unknownInt_knownInt() { | |
| 3066 _assertGreaterThan(_boolValue(null), _intValue(null), _intValue(2)); | |
| 3067 } | |
| 3068 | |
| 3069 void test_greaterThanOrEqual_knownDouble_knownDouble_false() { | |
| 3070 _assertGreaterThanOrEqual( | |
| 3071 _boolValue(false), _doubleValue(1.0), _doubleValue(2.0)); | |
| 3072 } | |
| 3073 | |
| 3074 void test_greaterThanOrEqual_knownDouble_knownDouble_true() { | |
| 3075 _assertGreaterThanOrEqual( | |
| 3076 _boolValue(true), _doubleValue(2.0), _doubleValue(1.0)); | |
| 3077 } | |
| 3078 | |
| 3079 void test_greaterThanOrEqual_knownDouble_knownInt_false() { | |
| 3080 _assertGreaterThanOrEqual( | |
| 3081 _boolValue(false), _doubleValue(1.0), _intValue(2)); | |
| 3082 } | |
| 3083 | |
| 3084 void test_greaterThanOrEqual_knownDouble_knownInt_true() { | |
| 3085 _assertGreaterThanOrEqual( | |
| 3086 _boolValue(true), _doubleValue(2.0), _intValue(1)); | |
| 3087 } | |
| 3088 | |
| 3089 void test_greaterThanOrEqual_knownDouble_unknownDouble() { | |
| 3090 _assertGreaterThanOrEqual( | |
| 3091 _boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3092 } | |
| 3093 | |
| 3094 void test_greaterThanOrEqual_knownDouble_unknownInt() { | |
| 3095 _assertGreaterThanOrEqual( | |
| 3096 _boolValue(null), _doubleValue(1.0), _intValue(null)); | |
| 3097 } | |
| 3098 | |
| 3099 void test_greaterThanOrEqual_knownInt_knownInt_false() { | |
| 3100 _assertGreaterThanOrEqual(_boolValue(false), _intValue(1), _intValue(2)); | |
| 3101 } | |
| 3102 | |
| 3103 void test_greaterThanOrEqual_knownInt_knownInt_true() { | |
| 3104 _assertGreaterThanOrEqual(_boolValue(true), _intValue(2), _intValue(2)); | |
| 3105 } | |
| 3106 | |
| 3107 void test_greaterThanOrEqual_knownInt_knownString() { | |
| 3108 _assertGreaterThanOrEqual(null, _intValue(1), _stringValue("2")); | |
| 3109 } | |
| 3110 | |
| 3111 void test_greaterThanOrEqual_knownInt_unknownDouble() { | |
| 3112 _assertGreaterThanOrEqual( | |
| 3113 _boolValue(null), _intValue(1), _doubleValue(null)); | |
| 3114 } | |
| 3115 | |
| 3116 void test_greaterThanOrEqual_knownInt_unknownInt() { | |
| 3117 _assertGreaterThanOrEqual(_boolValue(null), _intValue(1), _intValue(null)); | |
| 3118 } | |
| 3119 | |
| 3120 void test_greaterThanOrEqual_knownString_knownInt() { | |
| 3121 _assertGreaterThanOrEqual(null, _stringValue("1"), _intValue(2)); | |
| 3122 } | |
| 3123 | |
| 3124 void test_greaterThanOrEqual_unknownDouble_knownDouble() { | |
| 3125 _assertGreaterThanOrEqual( | |
| 3126 _boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3127 } | |
| 3128 | |
| 3129 void test_greaterThanOrEqual_unknownDouble_knownInt() { | |
| 3130 _assertGreaterThanOrEqual( | |
| 3131 _boolValue(null), _doubleValue(null), _intValue(2)); | |
| 3132 } | |
| 3133 | |
| 3134 void test_greaterThanOrEqual_unknownInt_knownDouble() { | |
| 3135 _assertGreaterThanOrEqual( | |
| 3136 _boolValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3137 } | |
| 3138 | |
| 3139 void test_greaterThanOrEqual_unknownInt_knownInt() { | |
| 3140 _assertGreaterThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); | |
| 3141 } | |
| 3142 | |
| 3143 void test_hasKnownValue_bool_false() { | |
| 3144 expect(_boolValue(false).hasKnownValue, isTrue); | |
| 3145 } | |
| 3146 | |
| 3147 void test_hasKnownValue_bool_true() { | |
| 3148 expect(_boolValue(true).hasKnownValue, isTrue); | |
| 3149 } | |
| 3150 | |
| 3151 void test_hasKnownValue_bool_unknown() { | |
| 3152 expect(_boolValue(null).hasKnownValue, isFalse); | |
| 3153 } | |
| 3154 | |
| 3155 void test_hasKnownValue_double_known() { | |
| 3156 expect(_doubleValue(2.3).hasKnownValue, isTrue); | |
| 3157 } | |
| 3158 | |
| 3159 void test_hasKnownValue_double_unknown() { | |
| 3160 expect(_doubleValue(null).hasKnownValue, isFalse); | |
| 3161 } | |
| 3162 | |
| 3163 void test_hasKnownValue_dynamic() { | |
| 3164 expect(_dynamicValue().hasKnownValue, isTrue); | |
| 3165 } | |
| 3166 | |
| 3167 void test_hasKnownValue_int_known() { | |
| 3168 expect(_intValue(23).hasKnownValue, isTrue); | |
| 3169 } | |
| 3170 | |
| 3171 void test_hasKnownValue_int_unknown() { | |
| 3172 expect(_intValue(null).hasKnownValue, isFalse); | |
| 3173 } | |
| 3174 | |
| 3175 void test_hasKnownValue_list_empty() { | |
| 3176 expect(_listValue().hasKnownValue, isTrue); | |
| 3177 } | |
| 3178 | |
| 3179 void test_hasKnownValue_list_invalidElement() { | |
| 3180 expect(_listValue([_dynamicValue]).hasKnownValue, isTrue); | |
| 3181 } | |
| 3182 | |
| 3183 void test_hasKnownValue_list_valid() { | |
| 3184 expect(_listValue([_intValue(23)]).hasKnownValue, isTrue); | |
| 3185 } | |
| 3186 | |
| 3187 void test_hasKnownValue_map_empty() { | |
| 3188 expect(_mapValue().hasKnownValue, isTrue); | |
| 3189 } | |
| 3190 | |
| 3191 void test_hasKnownValue_map_invalidKey() { | |
| 3192 expect(_mapValue([_dynamicValue(), _stringValue("value")]).hasKnownValue, | |
| 3193 isTrue); | |
| 3194 } | |
| 3195 | |
| 3196 void test_hasKnownValue_map_invalidValue() { | |
| 3197 expect(_mapValue([_stringValue("key"), _dynamicValue()]).hasKnownValue, | |
| 3198 isTrue); | |
| 3199 } | |
| 3200 | |
| 3201 void test_hasKnownValue_map_valid() { | |
| 3202 expect( | |
| 3203 _mapValue([_stringValue("key"), _stringValue("value")]).hasKnownValue, | |
| 3204 isTrue); | |
| 3205 } | |
| 3206 | |
| 3207 void test_hasKnownValue_null() { | |
| 3208 expect(_nullValue().hasKnownValue, isTrue); | |
| 3209 } | |
| 3210 | |
| 3211 void test_hasKnownValue_num() { | |
| 3212 expect(_numValue().hasKnownValue, isFalse); | |
| 3213 } | |
| 3214 | |
| 3215 void test_hasKnownValue_string_known() { | |
| 3216 expect(_stringValue("twenty-three").hasKnownValue, isTrue); | |
| 3217 } | |
| 3218 | |
| 3219 void test_hasKnownValue_string_unknown() { | |
| 3220 expect(_stringValue(null).hasKnownValue, isFalse); | |
| 3221 } | |
| 3222 | |
| 3223 void test_identical_bool_false() { | |
| 3224 _assertIdentical(_boolValue(false), _boolValue(false), _boolValue(true)); | |
| 3225 } | |
| 3226 | |
| 3227 void test_identical_bool_true() { | |
| 3228 _assertIdentical(_boolValue(true), _boolValue(true), _boolValue(true)); | |
| 3229 } | |
| 3230 | |
| 3231 void test_identical_bool_unknown() { | |
| 3232 _assertIdentical(_boolValue(null), _boolValue(null), _boolValue(false)); | |
| 3233 } | |
| 3234 | |
| 3235 void test_identical_double_false() { | |
| 3236 _assertIdentical(_boolValue(false), _doubleValue(2.0), _doubleValue(4.0)); | |
| 3237 } | |
| 3238 | |
| 3239 void test_identical_double_true() { | |
| 3240 _assertIdentical(_boolValue(true), _doubleValue(2.0), _doubleValue(2.0)); | |
| 3241 } | |
| 3242 | |
| 3243 void test_identical_double_unknown() { | |
| 3244 _assertIdentical(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3245 } | |
| 3246 | |
| 3247 void test_identical_int_false() { | |
| 3248 _assertIdentical(_boolValue(false), _intValue(-5), _intValue(5)); | |
| 3249 } | |
| 3250 | |
| 3251 void test_identical_int_true() { | |
| 3252 _assertIdentical(_boolValue(true), _intValue(5), _intValue(5)); | |
| 3253 } | |
| 3254 | |
| 3255 void test_identical_int_unknown() { | |
| 3256 _assertIdentical(_boolValue(null), _intValue(null), _intValue(3)); | |
| 3257 } | |
| 3258 | |
| 3259 void test_identical_list_empty() { | |
| 3260 _assertIdentical(_boolValue(true), _listValue(), _listValue()); | |
| 3261 } | |
| 3262 | |
| 3263 void test_identical_list_false() { | |
| 3264 _assertIdentical( | |
| 3265 _boolValue(false), _listValue(), _listValue([_intValue(3)])); | |
| 3266 } | |
| 3267 | |
| 3268 void test_identical_map_empty() { | |
| 3269 _assertIdentical(_boolValue(true), _mapValue(), _mapValue()); | |
| 3270 } | |
| 3271 | |
| 3272 void test_identical_map_false() { | |
| 3273 _assertIdentical(_boolValue(false), _mapValue(), | |
| 3274 _mapValue([_intValue(1), _intValue(2)])); | |
| 3275 } | |
| 3276 | |
| 3277 void test_identical_null() { | |
| 3278 _assertIdentical(_boolValue(true), _nullValue(), _nullValue()); | |
| 3279 } | |
| 3280 | |
| 3281 void test_identical_string_false() { | |
| 3282 _assertIdentical( | |
| 3283 _boolValue(false), _stringValue("abc"), _stringValue("def")); | |
| 3284 } | |
| 3285 | |
| 3286 void test_identical_string_true() { | |
| 3287 _assertIdentical( | |
| 3288 _boolValue(true), _stringValue("abc"), _stringValue("abc")); | |
| 3289 } | |
| 3290 | |
| 3291 void test_identical_string_unknown() { | |
| 3292 _assertIdentical(_boolValue(null), _stringValue(null), _stringValue("def")); | |
| 3293 } | |
| 3294 | |
| 3295 void test_integerDivide_knownDouble_knownDouble() { | |
| 3296 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _doubleValue(2.0)); | |
| 3297 } | |
| 3298 | |
| 3299 void test_integerDivide_knownDouble_knownInt() { | |
| 3300 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _intValue(2)); | |
| 3301 } | |
| 3302 | |
| 3303 void test_integerDivide_knownDouble_unknownDouble() { | |
| 3304 _assertIntegerDivide( | |
| 3305 _intValue(null), _doubleValue(6.0), _doubleValue(null)); | |
| 3306 } | |
| 3307 | |
| 3308 void test_integerDivide_knownDouble_unknownInt() { | |
| 3309 _assertIntegerDivide(_intValue(null), _doubleValue(6.0), _intValue(null)); | |
| 3310 } | |
| 3311 | |
| 3312 void test_integerDivide_knownInt_knownInt() { | |
| 3313 _assertIntegerDivide(_intValue(3), _intValue(6), _intValue(2)); | |
| 3314 } | |
| 3315 | |
| 3316 void test_integerDivide_knownInt_knownString() { | |
| 3317 _assertIntegerDivide(null, _intValue(6), _stringValue("2")); | |
| 3318 } | |
| 3319 | |
| 3320 void test_integerDivide_knownInt_unknownDouble() { | |
| 3321 _assertIntegerDivide(_intValue(null), _intValue(6), _doubleValue(null)); | |
| 3322 } | |
| 3323 | |
| 3324 void test_integerDivide_knownInt_unknownInt() { | |
| 3325 _assertIntegerDivide(_intValue(null), _intValue(6), _intValue(null)); | |
| 3326 } | |
| 3327 | |
| 3328 void test_integerDivide_knownString_knownInt() { | |
| 3329 _assertIntegerDivide(null, _stringValue("6"), _intValue(2)); | |
| 3330 } | |
| 3331 | |
| 3332 void test_integerDivide_unknownDouble_knownDouble() { | |
| 3333 _assertIntegerDivide( | |
| 3334 _intValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3335 } | |
| 3336 | |
| 3337 void test_integerDivide_unknownDouble_knownInt() { | |
| 3338 _assertIntegerDivide(_intValue(null), _doubleValue(null), _intValue(2)); | |
| 3339 } | |
| 3340 | |
| 3341 void test_integerDivide_unknownInt_knownDouble() { | |
| 3342 _assertIntegerDivide(_intValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3343 } | |
| 3344 | |
| 3345 void test_integerDivide_unknownInt_knownInt() { | |
| 3346 _assertIntegerDivide(_intValue(null), _intValue(null), _intValue(2)); | |
| 3347 } | |
| 3348 | |
| 3349 void test_isBoolNumStringOrNull_bool_false() { | |
| 3350 expect(_boolValue(false).isBoolNumStringOrNull, isTrue); | |
| 3351 } | |
| 3352 | |
| 3353 void test_isBoolNumStringOrNull_bool_true() { | |
| 3354 expect(_boolValue(true).isBoolNumStringOrNull, isTrue); | |
| 3355 } | |
| 3356 | |
| 3357 void test_isBoolNumStringOrNull_bool_unknown() { | |
| 3358 expect(_boolValue(null).isBoolNumStringOrNull, isTrue); | |
| 3359 } | |
| 3360 | |
| 3361 void test_isBoolNumStringOrNull_double_known() { | |
| 3362 expect(_doubleValue(2.3).isBoolNumStringOrNull, isTrue); | |
| 3363 } | |
| 3364 | |
| 3365 void test_isBoolNumStringOrNull_double_unknown() { | |
| 3366 expect(_doubleValue(null).isBoolNumStringOrNull, isTrue); | |
| 3367 } | |
| 3368 | |
| 3369 void test_isBoolNumStringOrNull_dynamic() { | |
| 3370 expect(_dynamicValue().isBoolNumStringOrNull, isTrue); | |
| 3371 } | |
| 3372 | |
| 3373 void test_isBoolNumStringOrNull_int_known() { | |
| 3374 expect(_intValue(23).isBoolNumStringOrNull, isTrue); | |
| 3375 } | |
| 3376 | |
| 3377 void test_isBoolNumStringOrNull_int_unknown() { | |
| 3378 expect(_intValue(null).isBoolNumStringOrNull, isTrue); | |
| 3379 } | |
| 3380 | |
| 3381 void test_isBoolNumStringOrNull_list() { | |
| 3382 expect(_listValue().isBoolNumStringOrNull, isFalse); | |
| 3383 } | |
| 3384 | |
| 3385 void test_isBoolNumStringOrNull_null() { | |
| 3386 expect(_nullValue().isBoolNumStringOrNull, isTrue); | |
| 3387 } | |
| 3388 | |
| 3389 void test_isBoolNumStringOrNull_num() { | |
| 3390 expect(_numValue().isBoolNumStringOrNull, isTrue); | |
| 3391 } | |
| 3392 | |
| 3393 void test_isBoolNumStringOrNull_string_known() { | |
| 3394 expect(_stringValue("twenty-three").isBoolNumStringOrNull, isTrue); | |
| 3395 } | |
| 3396 | |
| 3397 void test_isBoolNumStringOrNull_string_unknown() { | |
| 3398 expect(_stringValue(null).isBoolNumStringOrNull, isTrue); | |
| 3399 } | |
| 3400 | |
| 3401 void test_lessThan_knownDouble_knownDouble_false() { | |
| 3402 _assertLessThan(_boolValue(false), _doubleValue(2.0), _doubleValue(1.0)); | |
| 3403 } | |
| 3404 | |
| 3405 void test_lessThan_knownDouble_knownDouble_true() { | |
| 3406 _assertLessThan(_boolValue(true), _doubleValue(1.0), _doubleValue(2.0)); | |
| 3407 } | |
| 3408 | |
| 3409 void test_lessThan_knownDouble_knownInt_false() { | |
| 3410 _assertLessThan(_boolValue(false), _doubleValue(2.0), _intValue(1)); | |
| 3411 } | |
| 3412 | |
| 3413 void test_lessThan_knownDouble_knownInt_true() { | |
| 3414 _assertLessThan(_boolValue(true), _doubleValue(1.0), _intValue(2)); | |
| 3415 } | |
| 3416 | |
| 3417 void test_lessThan_knownDouble_unknownDouble() { | |
| 3418 _assertLessThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3419 } | |
| 3420 | |
| 3421 void test_lessThan_knownDouble_unknownInt() { | |
| 3422 _assertLessThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); | |
| 3423 } | |
| 3424 | |
| 3425 void test_lessThan_knownInt_knownInt_false() { | |
| 3426 _assertLessThan(_boolValue(false), _intValue(2), _intValue(1)); | |
| 3427 } | |
| 3428 | |
| 3429 void test_lessThan_knownInt_knownInt_true() { | |
| 3430 _assertLessThan(_boolValue(true), _intValue(1), _intValue(2)); | |
| 3431 } | |
| 3432 | |
| 3433 void test_lessThan_knownInt_knownString() { | |
| 3434 _assertLessThan(null, _intValue(1), _stringValue("2")); | |
| 3435 } | |
| 3436 | |
| 3437 void test_lessThan_knownInt_unknownDouble() { | |
| 3438 _assertLessThan(_boolValue(null), _intValue(1), _doubleValue(null)); | |
| 3439 } | |
| 3440 | |
| 3441 void test_lessThan_knownInt_unknownInt() { | |
| 3442 _assertLessThan(_boolValue(null), _intValue(1), _intValue(null)); | |
| 3443 } | |
| 3444 | |
| 3445 void test_lessThan_knownString_knownInt() { | |
| 3446 _assertLessThan(null, _stringValue("1"), _intValue(2)); | |
| 3447 } | |
| 3448 | |
| 3449 void test_lessThan_unknownDouble_knownDouble() { | |
| 3450 _assertLessThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3451 } | |
| 3452 | |
| 3453 void test_lessThan_unknownDouble_knownInt() { | |
| 3454 _assertLessThan(_boolValue(null), _doubleValue(null), _intValue(2)); | |
| 3455 } | |
| 3456 | |
| 3457 void test_lessThan_unknownInt_knownDouble() { | |
| 3458 _assertLessThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3459 } | |
| 3460 | |
| 3461 void test_lessThan_unknownInt_knownInt() { | |
| 3462 _assertLessThan(_boolValue(null), _intValue(null), _intValue(2)); | |
| 3463 } | |
| 3464 | |
| 3465 void test_lessThanOrEqual_knownDouble_knownDouble_false() { | |
| 3466 _assertLessThanOrEqual( | |
| 3467 _boolValue(false), _doubleValue(2.0), _doubleValue(1.0)); | |
| 3468 } | |
| 3469 | |
| 3470 void test_lessThanOrEqual_knownDouble_knownDouble_true() { | |
| 3471 _assertLessThanOrEqual( | |
| 3472 _boolValue(true), _doubleValue(1.0), _doubleValue(2.0)); | |
| 3473 } | |
| 3474 | |
| 3475 void test_lessThanOrEqual_knownDouble_knownInt_false() { | |
| 3476 _assertLessThanOrEqual(_boolValue(false), _doubleValue(2.0), _intValue(1)); | |
| 3477 } | |
| 3478 | |
| 3479 void test_lessThanOrEqual_knownDouble_knownInt_true() { | |
| 3480 _assertLessThanOrEqual(_boolValue(true), _doubleValue(1.0), _intValue(2)); | |
| 3481 } | |
| 3482 | |
| 3483 void test_lessThanOrEqual_knownDouble_unknownDouble() { | |
| 3484 _assertLessThanOrEqual( | |
| 3485 _boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3486 } | |
| 3487 | |
| 3488 void test_lessThanOrEqual_knownDouble_unknownInt() { | |
| 3489 _assertLessThanOrEqual( | |
| 3490 _boolValue(null), _doubleValue(1.0), _intValue(null)); | |
| 3491 } | |
| 3492 | |
| 3493 void test_lessThanOrEqual_knownInt_knownInt_false() { | |
| 3494 _assertLessThanOrEqual(_boolValue(false), _intValue(2), _intValue(1)); | |
| 3495 } | |
| 3496 | |
| 3497 void test_lessThanOrEqual_knownInt_knownInt_true() { | |
| 3498 _assertLessThanOrEqual(_boolValue(true), _intValue(1), _intValue(2)); | |
| 3499 } | |
| 3500 | |
| 3501 void test_lessThanOrEqual_knownInt_knownString() { | |
| 3502 _assertLessThanOrEqual(null, _intValue(1), _stringValue("2")); | |
| 3503 } | |
| 3504 | |
| 3505 void test_lessThanOrEqual_knownInt_unknownDouble() { | |
| 3506 _assertLessThanOrEqual(_boolValue(null), _intValue(1), _doubleValue(null)); | |
| 3507 } | |
| 3508 | |
| 3509 void test_lessThanOrEqual_knownInt_unknownInt() { | |
| 3510 _assertLessThanOrEqual(_boolValue(null), _intValue(1), _intValue(null)); | |
| 3511 } | |
| 3512 | |
| 3513 void test_lessThanOrEqual_knownString_knownInt() { | |
| 3514 _assertLessThanOrEqual(null, _stringValue("1"), _intValue(2)); | |
| 3515 } | |
| 3516 | |
| 3517 void test_lessThanOrEqual_unknownDouble_knownDouble() { | |
| 3518 _assertLessThanOrEqual( | |
| 3519 _boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3520 } | |
| 3521 | |
| 3522 void test_lessThanOrEqual_unknownDouble_knownInt() { | |
| 3523 _assertLessThanOrEqual(_boolValue(null), _doubleValue(null), _intValue(2)); | |
| 3524 } | |
| 3525 | |
| 3526 void test_lessThanOrEqual_unknownInt_knownDouble() { | |
| 3527 _assertLessThanOrEqual( | |
| 3528 _boolValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3529 } | |
| 3530 | |
| 3531 void test_lessThanOrEqual_unknownInt_knownInt() { | |
| 3532 _assertLessThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); | |
| 3533 } | |
| 3534 | |
| 3535 void test_logicalAnd_false_false() { | |
| 3536 _assertLogicalAnd(_boolValue(false), _boolValue(false), _boolValue(false)); | |
| 3537 } | |
| 3538 | |
| 3539 void test_logicalAnd_false_null() { | |
| 3540 try { | |
| 3541 _assertLogicalAnd(_boolValue(false), _boolValue(false), _nullValue()); | |
| 3542 fail("Expected EvaluationException"); | |
| 3543 } on EvaluationException {} | |
| 3544 } | |
| 3545 | |
| 3546 void test_logicalAnd_false_string() { | |
| 3547 try { | |
| 3548 _assertLogicalAnd( | |
| 3549 _boolValue(false), _boolValue(false), _stringValue("false")); | |
| 3550 fail("Expected EvaluationException"); | |
| 3551 } on EvaluationException {} | |
| 3552 } | |
| 3553 | |
| 3554 void test_logicalAnd_false_true() { | |
| 3555 _assertLogicalAnd(_boolValue(false), _boolValue(false), _boolValue(true)); | |
| 3556 } | |
| 3557 | |
| 3558 void test_logicalAnd_null_false() { | |
| 3559 try { | |
| 3560 _assertLogicalAnd(_boolValue(false), _nullValue(), _boolValue(false)); | |
| 3561 fail("Expected EvaluationException"); | |
| 3562 } on EvaluationException {} | |
| 3563 } | |
| 3564 | |
| 3565 void test_logicalAnd_null_true() { | |
| 3566 try { | |
| 3567 _assertLogicalAnd(_boolValue(false), _nullValue(), _boolValue(true)); | |
| 3568 fail("Expected EvaluationException"); | |
| 3569 } on EvaluationException {} | |
| 3570 } | |
| 3571 | |
| 3572 void test_logicalAnd_string_false() { | |
| 3573 try { | |
| 3574 _assertLogicalAnd( | |
| 3575 _boolValue(false), _stringValue("true"), _boolValue(false)); | |
| 3576 fail("Expected EvaluationException"); | |
| 3577 } on EvaluationException {} | |
| 3578 } | |
| 3579 | |
| 3580 void test_logicalAnd_string_true() { | |
| 3581 try { | |
| 3582 _assertLogicalAnd( | |
| 3583 _boolValue(false), _stringValue("false"), _boolValue(true)); | |
| 3584 fail("Expected EvaluationException"); | |
| 3585 } on EvaluationException {} | |
| 3586 } | |
| 3587 | |
| 3588 void test_logicalAnd_true_false() { | |
| 3589 _assertLogicalAnd(_boolValue(false), _boolValue(true), _boolValue(false)); | |
| 3590 } | |
| 3591 | |
| 3592 void test_logicalAnd_true_null() { | |
| 3593 _assertLogicalAnd(null, _boolValue(true), _nullValue()); | |
| 3594 } | |
| 3595 | |
| 3596 void test_logicalAnd_true_string() { | |
| 3597 try { | |
| 3598 _assertLogicalAnd( | |
| 3599 _boolValue(false), _boolValue(true), _stringValue("true")); | |
| 3600 fail("Expected EvaluationException"); | |
| 3601 } on EvaluationException {} | |
| 3602 } | |
| 3603 | |
| 3604 void test_logicalAnd_true_true() { | |
| 3605 _assertLogicalAnd(_boolValue(true), _boolValue(true), _boolValue(true)); | |
| 3606 } | |
| 3607 | |
| 3608 void test_logicalNot_false() { | |
| 3609 _assertLogicalNot(_boolValue(true), _boolValue(false)); | |
| 3610 } | |
| 3611 | |
| 3612 void test_logicalNot_null() { | |
| 3613 _assertLogicalNot(null, _nullValue()); | |
| 3614 } | |
| 3615 | |
| 3616 void test_logicalNot_string() { | |
| 3617 try { | |
| 3618 _assertLogicalNot(_boolValue(true), _stringValue(null)); | |
| 3619 fail("Expected EvaluationException"); | |
| 3620 } on EvaluationException {} | |
| 3621 } | |
| 3622 | |
| 3623 void test_logicalNot_true() { | |
| 3624 _assertLogicalNot(_boolValue(false), _boolValue(true)); | |
| 3625 } | |
| 3626 | |
| 3627 void test_logicalNot_unknown() { | |
| 3628 _assertLogicalNot(_boolValue(null), _boolValue(null)); | |
| 3629 } | |
| 3630 | |
| 3631 void test_logicalOr_false_false() { | |
| 3632 _assertLogicalOr(_boolValue(false), _boolValue(false), _boolValue(false)); | |
| 3633 } | |
| 3634 | |
| 3635 void test_logicalOr_false_null() { | |
| 3636 _assertLogicalOr(null, _boolValue(false), _nullValue()); | |
| 3637 } | |
| 3638 | |
| 3639 void test_logicalOr_false_string() { | |
| 3640 try { | |
| 3641 _assertLogicalOr( | |
| 3642 _boolValue(false), _boolValue(false), _stringValue("false")); | |
| 3643 fail("Expected EvaluationException"); | |
| 3644 } on EvaluationException {} | |
| 3645 } | |
| 3646 | |
| 3647 void test_logicalOr_false_true() { | |
| 3648 _assertLogicalOr(_boolValue(true), _boolValue(false), _boolValue(true)); | |
| 3649 } | |
| 3650 | |
| 3651 void test_logicalOr_null_false() { | |
| 3652 try { | |
| 3653 _assertLogicalOr(_boolValue(false), _nullValue(), _boolValue(false)); | |
| 3654 fail("Expected EvaluationException"); | |
| 3655 } on EvaluationException {} | |
| 3656 } | |
| 3657 | |
| 3658 void test_logicalOr_null_true() { | |
| 3659 try { | |
| 3660 _assertLogicalOr(_boolValue(true), _nullValue(), _boolValue(true)); | |
| 3661 fail("Expected EvaluationException"); | |
| 3662 } on EvaluationException {} | |
| 3663 } | |
| 3664 | |
| 3665 void test_logicalOr_string_false() { | |
| 3666 try { | |
| 3667 _assertLogicalOr( | |
| 3668 _boolValue(false), _stringValue("true"), _boolValue(false)); | |
| 3669 fail("Expected EvaluationException"); | |
| 3670 } on EvaluationException {} | |
| 3671 } | |
| 3672 | |
| 3673 void test_logicalOr_string_true() { | |
| 3674 try { | |
| 3675 _assertLogicalOr( | |
| 3676 _boolValue(true), _stringValue("false"), _boolValue(true)); | |
| 3677 fail("Expected EvaluationException"); | |
| 3678 } on EvaluationException {} | |
| 3679 } | |
| 3680 | |
| 3681 void test_logicalOr_true_false() { | |
| 3682 _assertLogicalOr(_boolValue(true), _boolValue(true), _boolValue(false)); | |
| 3683 } | |
| 3684 | |
| 3685 void test_logicalOr_true_null() { | |
| 3686 try { | |
| 3687 _assertLogicalOr(_boolValue(true), _boolValue(true), _nullValue()); | |
| 3688 fail("Expected EvaluationException"); | |
| 3689 } on EvaluationException {} | |
| 3690 } | |
| 3691 | |
| 3692 void test_logicalOr_true_string() { | |
| 3693 try { | |
| 3694 _assertLogicalOr( | |
| 3695 _boolValue(true), _boolValue(true), _stringValue("true")); | |
| 3696 fail("Expected EvaluationException"); | |
| 3697 } on EvaluationException {} | |
| 3698 } | |
| 3699 | |
| 3700 void test_logicalOr_true_true() { | |
| 3701 _assertLogicalOr(_boolValue(true), _boolValue(true), _boolValue(true)); | |
| 3702 } | |
| 3703 | |
| 3704 void test_minus_knownDouble_knownDouble() { | |
| 3705 _assertMinus(_doubleValue(1.0), _doubleValue(4.0), _doubleValue(3.0)); | |
| 3706 } | |
| 3707 | |
| 3708 void test_minus_knownDouble_knownInt() { | |
| 3709 _assertMinus(_doubleValue(1.0), _doubleValue(4.0), _intValue(3)); | |
| 3710 } | |
| 3711 | |
| 3712 void test_minus_knownDouble_unknownDouble() { | |
| 3713 _assertMinus(_doubleValue(null), _doubleValue(4.0), _doubleValue(null)); | |
| 3714 } | |
| 3715 | |
| 3716 void test_minus_knownDouble_unknownInt() { | |
| 3717 _assertMinus(_doubleValue(null), _doubleValue(4.0), _intValue(null)); | |
| 3718 } | |
| 3719 | |
| 3720 void test_minus_knownInt_knownInt() { | |
| 3721 _assertMinus(_intValue(1), _intValue(4), _intValue(3)); | |
| 3722 } | |
| 3723 | |
| 3724 void test_minus_knownInt_knownString() { | |
| 3725 _assertMinus(null, _intValue(4), _stringValue("3")); | |
| 3726 } | |
| 3727 | |
| 3728 void test_minus_knownInt_unknownDouble() { | |
| 3729 _assertMinus(_doubleValue(null), _intValue(4), _doubleValue(null)); | |
| 3730 } | |
| 3731 | |
| 3732 void test_minus_knownInt_unknownInt() { | |
| 3733 _assertMinus(_intValue(null), _intValue(4), _intValue(null)); | |
| 3734 } | |
| 3735 | |
| 3736 void test_minus_knownString_knownInt() { | |
| 3737 _assertMinus(null, _stringValue("4"), _intValue(3)); | |
| 3738 } | |
| 3739 | |
| 3740 void test_minus_unknownDouble_knownDouble() { | |
| 3741 _assertMinus(_doubleValue(null), _doubleValue(null), _doubleValue(3.0)); | |
| 3742 } | |
| 3743 | |
| 3744 void test_minus_unknownDouble_knownInt() { | |
| 3745 _assertMinus(_doubleValue(null), _doubleValue(null), _intValue(3)); | |
| 3746 } | |
| 3747 | |
| 3748 void test_minus_unknownInt_knownDouble() { | |
| 3749 _assertMinus(_doubleValue(null), _intValue(null), _doubleValue(3.0)); | |
| 3750 } | |
| 3751 | |
| 3752 void test_minus_unknownInt_knownInt() { | |
| 3753 _assertMinus(_intValue(null), _intValue(null), _intValue(3)); | |
| 3754 } | |
| 3755 | |
| 3756 void test_negated_double_known() { | |
| 3757 _assertNegated(_doubleValue(2.0), _doubleValue(-2.0)); | |
| 3758 } | |
| 3759 | |
| 3760 void test_negated_double_unknown() { | |
| 3761 _assertNegated(_doubleValue(null), _doubleValue(null)); | |
| 3762 } | |
| 3763 | |
| 3764 void test_negated_int_known() { | |
| 3765 _assertNegated(_intValue(-3), _intValue(3)); | |
| 3766 } | |
| 3767 | |
| 3768 void test_negated_int_unknown() { | |
| 3769 _assertNegated(_intValue(null), _intValue(null)); | |
| 3770 } | |
| 3771 | |
| 3772 void test_negated_string() { | |
| 3773 _assertNegated(null, _stringValue(null)); | |
| 3774 } | |
| 3775 | |
| 3776 void test_notEqual_bool_false() { | |
| 3777 _assertNotEqual(_boolValue(false), _boolValue(true), _boolValue(true)); | |
| 3778 } | |
| 3779 | |
| 3780 void test_notEqual_bool_true() { | |
| 3781 _assertNotEqual(_boolValue(true), _boolValue(false), _boolValue(true)); | |
| 3782 } | |
| 3783 | |
| 3784 void test_notEqual_bool_unknown() { | |
| 3785 _assertNotEqual(_boolValue(null), _boolValue(null), _boolValue(false)); | |
| 3786 } | |
| 3787 | |
| 3788 void test_notEqual_double_false() { | |
| 3789 _assertNotEqual(_boolValue(false), _doubleValue(2.0), _doubleValue(2.0)); | |
| 3790 } | |
| 3791 | |
| 3792 void test_notEqual_double_true() { | |
| 3793 _assertNotEqual(_boolValue(true), _doubleValue(2.0), _doubleValue(4.0)); | |
| 3794 } | |
| 3795 | |
| 3796 void test_notEqual_double_unknown() { | |
| 3797 _assertNotEqual(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
| 3798 } | |
| 3799 | |
| 3800 void test_notEqual_int_false() { | |
| 3801 _assertNotEqual(_boolValue(false), _intValue(5), _intValue(5)); | |
| 3802 } | |
| 3803 | |
| 3804 void test_notEqual_int_true() { | |
| 3805 _assertNotEqual(_boolValue(true), _intValue(-5), _intValue(5)); | |
| 3806 } | |
| 3807 | |
| 3808 void test_notEqual_int_unknown() { | |
| 3809 _assertNotEqual(_boolValue(null), _intValue(null), _intValue(3)); | |
| 3810 } | |
| 3811 | |
| 3812 void test_notEqual_null() { | |
| 3813 _assertNotEqual(_boolValue(false), _nullValue(), _nullValue()); | |
| 3814 } | |
| 3815 | |
| 3816 void test_notEqual_string_false() { | |
| 3817 _assertNotEqual( | |
| 3818 _boolValue(false), _stringValue("abc"), _stringValue("abc")); | |
| 3819 } | |
| 3820 | |
| 3821 void test_notEqual_string_true() { | |
| 3822 _assertNotEqual(_boolValue(true), _stringValue("abc"), _stringValue("def")); | |
| 3823 } | |
| 3824 | |
| 3825 void test_notEqual_string_unknown() { | |
| 3826 _assertNotEqual(_boolValue(null), _stringValue(null), _stringValue("def")); | |
| 3827 } | |
| 3828 | |
| 3829 void test_performToString_bool_false() { | |
| 3830 _assertPerformToString(_stringValue("false"), _boolValue(false)); | |
| 3831 } | |
| 3832 | |
| 3833 void test_performToString_bool_true() { | |
| 3834 _assertPerformToString(_stringValue("true"), _boolValue(true)); | |
| 3835 } | |
| 3836 | |
| 3837 void test_performToString_bool_unknown() { | |
| 3838 _assertPerformToString(_stringValue(null), _boolValue(null)); | |
| 3839 } | |
| 3840 | |
| 3841 void test_performToString_double_known() { | |
| 3842 _assertPerformToString(_stringValue("2.0"), _doubleValue(2.0)); | |
| 3843 } | |
| 3844 | |
| 3845 void test_performToString_double_unknown() { | |
| 3846 _assertPerformToString(_stringValue(null), _doubleValue(null)); | |
| 3847 } | |
| 3848 | |
| 3849 void test_performToString_int_known() { | |
| 3850 _assertPerformToString(_stringValue("5"), _intValue(5)); | |
| 3851 } | |
| 3852 | |
| 3853 void test_performToString_int_unknown() { | |
| 3854 _assertPerformToString(_stringValue(null), _intValue(null)); | |
| 3855 } | |
| 3856 | |
| 3857 void test_performToString_null() { | |
| 3858 _assertPerformToString(_stringValue("null"), _nullValue()); | |
| 3859 } | |
| 3860 | |
| 3861 void test_performToString_string_known() { | |
| 3862 _assertPerformToString(_stringValue("abc"), _stringValue("abc")); | |
| 3863 } | |
| 3864 | |
| 3865 void test_performToString_string_unknown() { | |
| 3866 _assertPerformToString(_stringValue(null), _stringValue(null)); | |
| 3867 } | |
| 3868 | |
| 3869 void test_remainder_knownDouble_knownDouble() { | |
| 3870 _assertRemainder(_doubleValue(1.0), _doubleValue(7.0), _doubleValue(2.0)); | |
| 3871 } | |
| 3872 | |
| 3873 void test_remainder_knownDouble_knownInt() { | |
| 3874 _assertRemainder(_doubleValue(1.0), _doubleValue(7.0), _intValue(2)); | |
| 3875 } | |
| 3876 | |
| 3877 void test_remainder_knownDouble_unknownDouble() { | |
| 3878 _assertRemainder(_doubleValue(null), _doubleValue(7.0), _doubleValue(null)); | |
| 3879 } | |
| 3880 | |
| 3881 void test_remainder_knownDouble_unknownInt() { | |
| 3882 _assertRemainder(_doubleValue(null), _doubleValue(6.0), _intValue(null)); | |
| 3883 } | |
| 3884 | |
| 3885 void test_remainder_knownInt_knownInt() { | |
| 3886 _assertRemainder(_intValue(1), _intValue(7), _intValue(2)); | |
| 3887 } | |
| 3888 | |
| 3889 void test_remainder_knownInt_knownString() { | |
| 3890 _assertRemainder(null, _intValue(7), _stringValue("2")); | |
| 3891 } | |
| 3892 | |
| 3893 void test_remainder_knownInt_unknownDouble() { | |
| 3894 _assertRemainder(_doubleValue(null), _intValue(7), _doubleValue(null)); | |
| 3895 } | |
| 3896 | |
| 3897 void test_remainder_knownInt_unknownInt() { | |
| 3898 _assertRemainder(_intValue(null), _intValue(7), _intValue(null)); | |
| 3899 } | |
| 3900 | |
| 3901 void test_remainder_knownString_knownInt() { | |
| 3902 _assertRemainder(null, _stringValue("7"), _intValue(2)); | |
| 3903 } | |
| 3904 | |
| 3905 void test_remainder_unknownDouble_knownDouble() { | |
| 3906 _assertRemainder(_doubleValue(null), _doubleValue(null), _doubleValue(2.0)); | |
| 3907 } | |
| 3908 | |
| 3909 void test_remainder_unknownDouble_knownInt() { | |
| 3910 _assertRemainder(_doubleValue(null), _doubleValue(null), _intValue(2)); | |
| 3911 } | |
| 3912 | |
| 3913 void test_remainder_unknownInt_knownDouble() { | |
| 3914 _assertRemainder(_doubleValue(null), _intValue(null), _doubleValue(2.0)); | |
| 3915 } | |
| 3916 | |
| 3917 void test_remainder_unknownInt_knownInt() { | |
| 3918 _assertRemainder(_intValue(null), _intValue(null), _intValue(2)); | |
| 3919 } | |
| 3920 | |
| 3921 void test_shiftLeft_knownInt_knownInt() { | |
| 3922 _assertShiftLeft(_intValue(48), _intValue(6), _intValue(3)); | |
| 3923 } | |
| 3924 | |
| 3925 void test_shiftLeft_knownInt_knownString() { | |
| 3926 _assertShiftLeft(null, _intValue(6), _stringValue(null)); | |
| 3927 } | |
| 3928 | |
| 3929 void test_shiftLeft_knownInt_tooLarge() { | |
| 3930 _assertShiftLeft( | |
| 3931 _intValue(null), | |
| 3932 _intValue(6), | |
| 3933 new DartObjectImpl( | |
| 3934 _typeProvider.intType, new IntState(LONG_MAX_VALUE))); | |
| 3935 } | |
| 3936 | |
| 3937 void test_shiftLeft_knownInt_unknownInt() { | |
| 3938 _assertShiftLeft(_intValue(null), _intValue(6), _intValue(null)); | |
| 3939 } | |
| 3940 | |
| 3941 void test_shiftLeft_knownString_knownInt() { | |
| 3942 _assertShiftLeft(null, _stringValue(null), _intValue(3)); | |
| 3943 } | |
| 3944 | |
| 3945 void test_shiftLeft_unknownInt_knownInt() { | |
| 3946 _assertShiftLeft(_intValue(null), _intValue(null), _intValue(3)); | |
| 3947 } | |
| 3948 | |
| 3949 void test_shiftLeft_unknownInt_unknownInt() { | |
| 3950 _assertShiftLeft(_intValue(null), _intValue(null), _intValue(null)); | |
| 3951 } | |
| 3952 | |
| 3953 void test_shiftRight_knownInt_knownInt() { | |
| 3954 _assertShiftRight(_intValue(6), _intValue(48), _intValue(3)); | |
| 3955 } | |
| 3956 | |
| 3957 void test_shiftRight_knownInt_knownString() { | |
| 3958 _assertShiftRight(null, _intValue(48), _stringValue(null)); | |
| 3959 } | |
| 3960 | |
| 3961 void test_shiftRight_knownInt_tooLarge() { | |
| 3962 _assertShiftRight( | |
| 3963 _intValue(null), | |
| 3964 _intValue(48), | |
| 3965 new DartObjectImpl( | |
| 3966 _typeProvider.intType, new IntState(LONG_MAX_VALUE))); | |
| 3967 } | |
| 3968 | |
| 3969 void test_shiftRight_knownInt_unknownInt() { | |
| 3970 _assertShiftRight(_intValue(null), _intValue(48), _intValue(null)); | |
| 3971 } | |
| 3972 | |
| 3973 void test_shiftRight_knownString_knownInt() { | |
| 3974 _assertShiftRight(null, _stringValue(null), _intValue(3)); | |
| 3975 } | |
| 3976 | |
| 3977 void test_shiftRight_unknownInt_knownInt() { | |
| 3978 _assertShiftRight(_intValue(null), _intValue(null), _intValue(3)); | |
| 3979 } | |
| 3980 | |
| 3981 void test_shiftRight_unknownInt_unknownInt() { | |
| 3982 _assertShiftRight(_intValue(null), _intValue(null), _intValue(null)); | |
| 3983 } | |
| 3984 | |
| 3985 void test_stringLength_int() { | |
| 3986 try { | |
| 3987 _assertStringLength(_intValue(null), _intValue(0)); | |
| 3988 fail("Expected EvaluationException"); | |
| 3989 } on EvaluationException {} | |
| 3990 } | |
| 3991 | |
| 3992 void test_stringLength_knownString() { | |
| 3993 _assertStringLength(_intValue(3), _stringValue("abc")); | |
| 3994 } | |
| 3995 | |
| 3996 void test_stringLength_unknownString() { | |
| 3997 _assertStringLength(_intValue(null), _stringValue(null)); | |
| 3998 } | |
| 3999 | |
| 4000 void test_times_knownDouble_knownDouble() { | |
| 4001 _assertTimes(_doubleValue(6.0), _doubleValue(2.0), _doubleValue(3.0)); | |
| 4002 } | |
| 4003 | |
| 4004 void test_times_knownDouble_knownInt() { | |
| 4005 _assertTimes(_doubleValue(6.0), _doubleValue(2.0), _intValue(3)); | |
| 4006 } | |
| 4007 | |
| 4008 void test_times_knownDouble_unknownDouble() { | |
| 4009 _assertTimes(_doubleValue(null), _doubleValue(2.0), _doubleValue(null)); | |
| 4010 } | |
| 4011 | |
| 4012 void test_times_knownDouble_unknownInt() { | |
| 4013 _assertTimes(_doubleValue(null), _doubleValue(2.0), _intValue(null)); | |
| 4014 } | |
| 4015 | |
| 4016 void test_times_knownInt_knownInt() { | |
| 4017 _assertTimes(_intValue(6), _intValue(2), _intValue(3)); | |
| 4018 } | |
| 4019 | |
| 4020 void test_times_knownInt_knownString() { | |
| 4021 _assertTimes(null, _intValue(2), _stringValue("3")); | |
| 4022 } | |
| 4023 | |
| 4024 void test_times_knownInt_unknownDouble() { | |
| 4025 _assertTimes(_doubleValue(null), _intValue(2), _doubleValue(null)); | |
| 4026 } | |
| 4027 | |
| 4028 void test_times_knownInt_unknownInt() { | |
| 4029 _assertTimes(_intValue(null), _intValue(2), _intValue(null)); | |
| 4030 } | |
| 4031 | |
| 4032 void test_times_knownString_knownInt() { | |
| 4033 _assertTimes(null, _stringValue("2"), _intValue(3)); | |
| 4034 } | |
| 4035 | |
| 4036 void test_times_unknownDouble_knownDouble() { | |
| 4037 _assertTimes(_doubleValue(null), _doubleValue(null), _doubleValue(3.0)); | |
| 4038 } | |
| 4039 | |
| 4040 void test_times_unknownDouble_knownInt() { | |
| 4041 _assertTimes(_doubleValue(null), _doubleValue(null), _intValue(3)); | |
| 4042 } | |
| 4043 | |
| 4044 void test_times_unknownInt_knownDouble() { | |
| 4045 _assertTimes(_doubleValue(null), _intValue(null), _doubleValue(3.0)); | |
| 4046 } | |
| 4047 | |
| 4048 void test_times_unknownInt_knownInt() { | |
| 4049 _assertTimes(_intValue(null), _intValue(null), _intValue(3)); | |
| 4050 } | |
| 4051 | |
| 4052 /** | |
| 4053 * Assert that the result of adding the left and right operands is the expecte
d value, or that the | |
| 4054 * operation throws an exception if the expected value is `null`. | |
| 4055 * | |
| 4056 * @param expected the expected result of the operation | |
| 4057 * @param leftOperand the left operand to the operation | |
| 4058 * @param rightOperand the left operand to the operation | |
| 4059 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4060 */ | |
| 4061 void _assertAdd(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4062 DartObjectImpl rightOperand) { | |
| 4063 if (expected == null) { | |
| 4064 try { | |
| 4065 leftOperand.add(_typeProvider, rightOperand); | |
| 4066 fail("Expected an EvaluationException"); | |
| 4067 } on EvaluationException {} | |
| 4068 } else { | |
| 4069 DartObjectImpl result = leftOperand.add(_typeProvider, rightOperand); | |
| 4070 expect(result, isNotNull); | |
| 4071 expect(result, expected); | |
| 4072 } | |
| 4073 } | |
| 4074 | |
| 4075 /** | |
| 4076 * Assert that the result of bit-anding the left and right operands is the exp
ected value, or that | |
| 4077 * the operation throws an exception if the expected value is `null`. | |
| 4078 * | |
| 4079 * @param expected the expected result of the operation | |
| 4080 * @param leftOperand the left operand to the operation | |
| 4081 * @param rightOperand the left operand to the operation | |
| 4082 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4083 */ | |
| 4084 void _assertBitAnd(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4085 DartObjectImpl rightOperand) { | |
| 4086 if (expected == null) { | |
| 4087 try { | |
| 4088 leftOperand.bitAnd(_typeProvider, rightOperand); | |
| 4089 fail("Expected an EvaluationException"); | |
| 4090 } on EvaluationException {} | |
| 4091 } else { | |
| 4092 DartObjectImpl result = leftOperand.bitAnd(_typeProvider, rightOperand); | |
| 4093 expect(result, isNotNull); | |
| 4094 expect(result, expected); | |
| 4095 } | |
| 4096 } | |
| 4097 | |
| 4098 /** | |
| 4099 * Assert that the bit-not of the operand is the expected value, or that the o
peration throws an | |
| 4100 * exception if the expected value is `null`. | |
| 4101 * | |
| 4102 * @param expected the expected result of the operation | |
| 4103 * @param operand the operand to the operation | |
| 4104 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4105 */ | |
| 4106 void _assertBitNot(DartObjectImpl expected, DartObjectImpl operand) { | |
| 4107 if (expected == null) { | |
| 4108 try { | |
| 4109 operand.bitNot(_typeProvider); | |
| 4110 fail("Expected an EvaluationException"); | |
| 4111 } on EvaluationException {} | |
| 4112 } else { | |
| 4113 DartObjectImpl result = operand.bitNot(_typeProvider); | |
| 4114 expect(result, isNotNull); | |
| 4115 expect(result, expected); | |
| 4116 } | |
| 4117 } | |
| 4118 | |
| 4119 /** | |
| 4120 * Assert that the result of bit-oring the left and right operands is the expe
cted value, or that | |
| 4121 * the operation throws an exception if the expected value is `null`. | |
| 4122 * | |
| 4123 * @param expected the expected result of the operation | |
| 4124 * @param leftOperand the left operand to the operation | |
| 4125 * @param rightOperand the left operand to the operation | |
| 4126 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4127 */ | |
| 4128 void _assertBitOr(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4129 DartObjectImpl rightOperand) { | |
| 4130 if (expected == null) { | |
| 4131 try { | |
| 4132 leftOperand.bitOr(_typeProvider, rightOperand); | |
| 4133 fail("Expected an EvaluationException"); | |
| 4134 } on EvaluationException {} | |
| 4135 } else { | |
| 4136 DartObjectImpl result = leftOperand.bitOr(_typeProvider, rightOperand); | |
| 4137 expect(result, isNotNull); | |
| 4138 expect(result, expected); | |
| 4139 } | |
| 4140 } | |
| 4141 | |
| 4142 /** | |
| 4143 * Assert that the result of bit-xoring the left and right operands is the exp
ected value, or that | |
| 4144 * the operation throws an exception if the expected value is `null`. | |
| 4145 * | |
| 4146 * @param expected the expected result of the operation | |
| 4147 * @param leftOperand the left operand to the operation | |
| 4148 * @param rightOperand the left operand to the operation | |
| 4149 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4150 */ | |
| 4151 void _assertBitXor(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4152 DartObjectImpl rightOperand) { | |
| 4153 if (expected == null) { | |
| 4154 try { | |
| 4155 leftOperand.bitXor(_typeProvider, rightOperand); | |
| 4156 fail("Expected an EvaluationException"); | |
| 4157 } on EvaluationException {} | |
| 4158 } else { | |
| 4159 DartObjectImpl result = leftOperand.bitXor(_typeProvider, rightOperand); | |
| 4160 expect(result, isNotNull); | |
| 4161 expect(result, expected); | |
| 4162 } | |
| 4163 } | |
| 4164 | |
| 4165 /** | |
| 4166 * Assert that the result of concatenating the left and right operands is the
expected value, or | |
| 4167 * that the operation throws an exception if the expected value is `null`. | |
| 4168 * | |
| 4169 * @param expected the expected result of the operation | |
| 4170 * @param leftOperand the left operand to the operation | |
| 4171 * @param rightOperand the left operand to the operation | |
| 4172 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4173 */ | |
| 4174 void _assertConcatenate(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4175 DartObjectImpl rightOperand) { | |
| 4176 if (expected == null) { | |
| 4177 try { | |
| 4178 leftOperand.concatenate(_typeProvider, rightOperand); | |
| 4179 fail("Expected an EvaluationException"); | |
| 4180 } on EvaluationException {} | |
| 4181 } else { | |
| 4182 DartObjectImpl result = | |
| 4183 leftOperand.concatenate(_typeProvider, rightOperand); | |
| 4184 expect(result, isNotNull); | |
| 4185 expect(result, expected); | |
| 4186 } | |
| 4187 } | |
| 4188 | |
| 4189 /** | |
| 4190 * Assert that the result of dividing the left and right operands is the expec
ted value, or that | |
| 4191 * the operation throws an exception if the expected value is `null`. | |
| 4192 * | |
| 4193 * @param expected the expected result of the operation | |
| 4194 * @param leftOperand the left operand to the operation | |
| 4195 * @param rightOperand the left operand to the operation | |
| 4196 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4197 */ | |
| 4198 void _assertDivide(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4199 DartObjectImpl rightOperand) { | |
| 4200 if (expected == null) { | |
| 4201 try { | |
| 4202 leftOperand.divide(_typeProvider, rightOperand); | |
| 4203 fail("Expected an EvaluationException"); | |
| 4204 } on EvaluationException {} | |
| 4205 } else { | |
| 4206 DartObjectImpl result = leftOperand.divide(_typeProvider, rightOperand); | |
| 4207 expect(result, isNotNull); | |
| 4208 expect(result, expected); | |
| 4209 } | |
| 4210 } | |
| 4211 | |
| 4212 /** | |
| 4213 * Assert that the result of comparing the left and right operands for equalit
y is the expected | |
| 4214 * value, or that the operation throws an exception if the expected value is `
null`. | |
| 4215 * | |
| 4216 * @param expected the expected result of the operation | |
| 4217 * @param leftOperand the left operand to the operation | |
| 4218 * @param rightOperand the left operand to the operation | |
| 4219 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4220 */ | |
| 4221 void _assertEqualEqual(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4222 DartObjectImpl rightOperand) { | |
| 4223 if (expected == null) { | |
| 4224 try { | |
| 4225 leftOperand.equalEqual(_typeProvider, rightOperand); | |
| 4226 fail("Expected an EvaluationException"); | |
| 4227 } on EvaluationException {} | |
| 4228 } else { | |
| 4229 DartObjectImpl result = | |
| 4230 leftOperand.equalEqual(_typeProvider, rightOperand); | |
| 4231 expect(result, isNotNull); | |
| 4232 expect(result, expected); | |
| 4233 } | |
| 4234 } | |
| 4235 | |
| 4236 /** | |
| 4237 * Assert that the result of comparing the left and right operands is the expe
cted value, or that | |
| 4238 * the operation throws an exception if the expected value is `null`. | |
| 4239 * | |
| 4240 * @param expected the expected result of the operation | |
| 4241 * @param leftOperand the left operand to the operation | |
| 4242 * @param rightOperand the left operand to the operation | |
| 4243 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4244 */ | |
| 4245 void _assertGreaterThan(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4246 DartObjectImpl rightOperand) { | |
| 4247 if (expected == null) { | |
| 4248 try { | |
| 4249 leftOperand.greaterThan(_typeProvider, rightOperand); | |
| 4250 fail("Expected an EvaluationException"); | |
| 4251 } on EvaluationException {} | |
| 4252 } else { | |
| 4253 DartObjectImpl result = | |
| 4254 leftOperand.greaterThan(_typeProvider, rightOperand); | |
| 4255 expect(result, isNotNull); | |
| 4256 expect(result, expected); | |
| 4257 } | |
| 4258 } | |
| 4259 | |
| 4260 /** | |
| 4261 * Assert that the result of comparing the left and right operands is the expe
cted value, or that | |
| 4262 * the operation throws an exception if the expected value is `null`. | |
| 4263 * | |
| 4264 * @param expected the expected result of the operation | |
| 4265 * @param leftOperand the left operand to the operation | |
| 4266 * @param rightOperand the left operand to the operation | |
| 4267 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4268 */ | |
| 4269 void _assertGreaterThanOrEqual(DartObjectImpl expected, | |
| 4270 DartObjectImpl leftOperand, DartObjectImpl rightOperand) { | |
| 4271 if (expected == null) { | |
| 4272 try { | |
| 4273 leftOperand.greaterThanOrEqual(_typeProvider, rightOperand); | |
| 4274 fail("Expected an EvaluationException"); | |
| 4275 } on EvaluationException {} | |
| 4276 } else { | |
| 4277 DartObjectImpl result = | |
| 4278 leftOperand.greaterThanOrEqual(_typeProvider, rightOperand); | |
| 4279 expect(result, isNotNull); | |
| 4280 expect(result, expected); | |
| 4281 } | |
| 4282 } | |
| 4283 | |
| 4284 /** | |
| 4285 * Assert that the result of comparing the left and right operands using | |
| 4286 * identical() is the expected value. | |
| 4287 * | |
| 4288 * @param expected the expected result of the operation | |
| 4289 * @param leftOperand the left operand to the operation | |
| 4290 * @param rightOperand the left operand to the operation | |
| 4291 */ | |
| 4292 void _assertIdentical(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4293 DartObjectImpl rightOperand) { | |
| 4294 DartObjectImpl result = | |
| 4295 leftOperand.isIdentical(_typeProvider, rightOperand); | |
| 4296 expect(result, isNotNull); | |
| 4297 expect(result, expected); | |
| 4298 } | |
| 4299 | |
| 4300 void _assertInstanceOfObjectArray(Object result) { | |
| 4301 // TODO(scheglov) implement | |
| 4302 } | |
| 4303 | |
| 4304 /** | |
| 4305 * Assert that the result of dividing the left and right operands as integers
is the expected | |
| 4306 * value, or that the operation throws an exception if the expected value is `
null`. | |
| 4307 * | |
| 4308 * @param expected the expected result of the operation | |
| 4309 * @param leftOperand the left operand to the operation | |
| 4310 * @param rightOperand the left operand to the operation | |
| 4311 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4312 */ | |
| 4313 void _assertIntegerDivide(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4314 DartObjectImpl rightOperand) { | |
| 4315 if (expected == null) { | |
| 4316 try { | |
| 4317 leftOperand.integerDivide(_typeProvider, rightOperand); | |
| 4318 fail("Expected an EvaluationException"); | |
| 4319 } on EvaluationException {} | |
| 4320 } else { | |
| 4321 DartObjectImpl result = | |
| 4322 leftOperand.integerDivide(_typeProvider, rightOperand); | |
| 4323 expect(result, isNotNull); | |
| 4324 expect(result, expected); | |
| 4325 } | |
| 4326 } | |
| 4327 | |
| 4328 /** | |
| 4329 * Assert that the result of comparing the left and right operands is the expe
cted value, or that | |
| 4330 * the operation throws an exception if the expected value is `null`. | |
| 4331 * | |
| 4332 * @param expected the expected result of the operation | |
| 4333 * @param leftOperand the left operand to the operation | |
| 4334 * @param rightOperand the left operand to the operation | |
| 4335 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4336 */ | |
| 4337 void _assertLessThan(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4338 DartObjectImpl rightOperand) { | |
| 4339 if (expected == null) { | |
| 4340 try { | |
| 4341 leftOperand.lessThan(_typeProvider, rightOperand); | |
| 4342 fail("Expected an EvaluationException"); | |
| 4343 } on EvaluationException {} | |
| 4344 } else { | |
| 4345 DartObjectImpl result = leftOperand.lessThan(_typeProvider, rightOperand); | |
| 4346 expect(result, isNotNull); | |
| 4347 expect(result, expected); | |
| 4348 } | |
| 4349 } | |
| 4350 | |
| 4351 /** | |
| 4352 * Assert that the result of comparing the left and right operands is the expe
cted value, or that | |
| 4353 * the operation throws an exception if the expected value is `null`. | |
| 4354 * | |
| 4355 * @param expected the expected result of the operation | |
| 4356 * @param leftOperand the left operand to the operation | |
| 4357 * @param rightOperand the left operand to the operation | |
| 4358 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4359 */ | |
| 4360 void _assertLessThanOrEqual(DartObjectImpl expected, | |
| 4361 DartObjectImpl leftOperand, DartObjectImpl rightOperand) { | |
| 4362 if (expected == null) { | |
| 4363 try { | |
| 4364 leftOperand.lessThanOrEqual(_typeProvider, rightOperand); | |
| 4365 fail("Expected an EvaluationException"); | |
| 4366 } on EvaluationException {} | |
| 4367 } else { | |
| 4368 DartObjectImpl result = | |
| 4369 leftOperand.lessThanOrEqual(_typeProvider, rightOperand); | |
| 4370 expect(result, isNotNull); | |
| 4371 expect(result, expected); | |
| 4372 } | |
| 4373 } | |
| 4374 | |
| 4375 /** | |
| 4376 * Assert that the result of logical-anding the left and right operands is the
expected value, or | |
| 4377 * that the operation throws an exception if the expected value is `null`. | |
| 4378 * | |
| 4379 * @param expected the expected result of the operation | |
| 4380 * @param leftOperand the left operand to the operation | |
| 4381 * @param rightOperand the left operand to the operation | |
| 4382 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4383 */ | |
| 4384 void _assertLogicalAnd(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4385 DartObjectImpl rightOperand) { | |
| 4386 if (expected == null) { | |
| 4387 try { | |
| 4388 leftOperand.logicalAnd(_typeProvider, rightOperand); | |
| 4389 fail("Expected an EvaluationException"); | |
| 4390 } on EvaluationException {} | |
| 4391 } else { | |
| 4392 DartObjectImpl result = | |
| 4393 leftOperand.logicalAnd(_typeProvider, rightOperand); | |
| 4394 expect(result, isNotNull); | |
| 4395 expect(result, expected); | |
| 4396 } | |
| 4397 } | |
| 4398 | |
| 4399 /** | |
| 4400 * Assert that the logical-not of the operand is the expected value, or that t
he operation throws | |
| 4401 * an exception if the expected value is `null`. | |
| 4402 * | |
| 4403 * @param expected the expected result of the operation | |
| 4404 * @param operand the operand to the operation | |
| 4405 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4406 */ | |
| 4407 void _assertLogicalNot(DartObjectImpl expected, DartObjectImpl operand) { | |
| 4408 if (expected == null) { | |
| 4409 try { | |
| 4410 operand.logicalNot(_typeProvider); | |
| 4411 fail("Expected an EvaluationException"); | |
| 4412 } on EvaluationException {} | |
| 4413 } else { | |
| 4414 DartObjectImpl result = operand.logicalNot(_typeProvider); | |
| 4415 expect(result, isNotNull); | |
| 4416 expect(result, expected); | |
| 4417 } | |
| 4418 } | |
| 4419 | |
| 4420 /** | |
| 4421 * Assert that the result of logical-oring the left and right operands is the
expected value, or | |
| 4422 * that the operation throws an exception if the expected value is `null`. | |
| 4423 * | |
| 4424 * @param expected the expected result of the operation | |
| 4425 * @param leftOperand the left operand to the operation | |
| 4426 * @param rightOperand the left operand to the operation | |
| 4427 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4428 */ | |
| 4429 void _assertLogicalOr(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4430 DartObjectImpl rightOperand) { | |
| 4431 if (expected == null) { | |
| 4432 try { | |
| 4433 leftOperand.logicalOr(_typeProvider, rightOperand); | |
| 4434 fail("Expected an EvaluationException"); | |
| 4435 } on EvaluationException {} | |
| 4436 } else { | |
| 4437 DartObjectImpl result = | |
| 4438 leftOperand.logicalOr(_typeProvider, rightOperand); | |
| 4439 expect(result, isNotNull); | |
| 4440 expect(result, expected); | |
| 4441 } | |
| 4442 } | |
| 4443 | |
| 4444 /** | |
| 4445 * Assert that the result of subtracting the left and right operands is the ex
pected value, or | |
| 4446 * that the operation throws an exception if the expected value is `null`. | |
| 4447 * | |
| 4448 * @param expected the expected result of the operation | |
| 4449 * @param leftOperand the left operand to the operation | |
| 4450 * @param rightOperand the left operand to the operation | |
| 4451 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4452 */ | |
| 4453 void _assertMinus(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4454 DartObjectImpl rightOperand) { | |
| 4455 if (expected == null) { | |
| 4456 try { | |
| 4457 leftOperand.minus(_typeProvider, rightOperand); | |
| 4458 fail("Expected an EvaluationException"); | |
| 4459 } on EvaluationException {} | |
| 4460 } else { | |
| 4461 DartObjectImpl result = leftOperand.minus(_typeProvider, rightOperand); | |
| 4462 expect(result, isNotNull); | |
| 4463 expect(result, expected); | |
| 4464 } | |
| 4465 } | |
| 4466 | |
| 4467 /** | |
| 4468 * Assert that the negation of the operand is the expected value, or that the
operation throws an | |
| 4469 * exception if the expected value is `null`. | |
| 4470 * | |
| 4471 * @param expected the expected result of the operation | |
| 4472 * @param operand the operand to the operation | |
| 4473 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4474 */ | |
| 4475 void _assertNegated(DartObjectImpl expected, DartObjectImpl operand) { | |
| 4476 if (expected == null) { | |
| 4477 try { | |
| 4478 operand.negated(_typeProvider); | |
| 4479 fail("Expected an EvaluationException"); | |
| 4480 } on EvaluationException {} | |
| 4481 } else { | |
| 4482 DartObjectImpl result = operand.negated(_typeProvider); | |
| 4483 expect(result, isNotNull); | |
| 4484 expect(result, expected); | |
| 4485 } | |
| 4486 } | |
| 4487 | |
| 4488 /** | |
| 4489 * Assert that the result of comparing the left and right operands for inequal
ity is the expected | |
| 4490 * value, or that the operation throws an exception if the expected value is `
null`. | |
| 4491 * | |
| 4492 * @param expected the expected result of the operation | |
| 4493 * @param leftOperand the left operand to the operation | |
| 4494 * @param rightOperand the left operand to the operation | |
| 4495 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4496 */ | |
| 4497 void _assertNotEqual(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4498 DartObjectImpl rightOperand) { | |
| 4499 if (expected == null) { | |
| 4500 try { | |
| 4501 leftOperand.notEqual(_typeProvider, rightOperand); | |
| 4502 fail("Expected an EvaluationException"); | |
| 4503 } on EvaluationException {} | |
| 4504 } else { | |
| 4505 DartObjectImpl result = leftOperand.notEqual(_typeProvider, rightOperand); | |
| 4506 expect(result, isNotNull); | |
| 4507 expect(result, expected); | |
| 4508 } | |
| 4509 } | |
| 4510 | |
| 4511 /** | |
| 4512 * Assert that converting the operand to a string is the expected value, or th
at the operation | |
| 4513 * throws an exception if the expected value is `null`. | |
| 4514 * | |
| 4515 * @param expected the expected result of the operation | |
| 4516 * @param operand the operand to the operation | |
| 4517 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4518 */ | |
| 4519 void _assertPerformToString(DartObjectImpl expected, DartObjectImpl operand) { | |
| 4520 if (expected == null) { | |
| 4521 try { | |
| 4522 operand.performToString(_typeProvider); | |
| 4523 fail("Expected an EvaluationException"); | |
| 4524 } on EvaluationException {} | |
| 4525 } else { | |
| 4526 DartObjectImpl result = operand.performToString(_typeProvider); | |
| 4527 expect(result, isNotNull); | |
| 4528 expect(result, expected); | |
| 4529 } | |
| 4530 } | |
| 4531 | |
| 4532 /** | |
| 4533 * Assert that the result of taking the remainder of the left and right operan
ds is the expected | |
| 4534 * value, or that the operation throws an exception if the expected value is `
null`. | |
| 4535 * | |
| 4536 * @param expected the expected result of the operation | |
| 4537 * @param leftOperand the left operand to the operation | |
| 4538 * @param rightOperand the left operand to the operation | |
| 4539 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4540 */ | |
| 4541 void _assertRemainder(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4542 DartObjectImpl rightOperand) { | |
| 4543 if (expected == null) { | |
| 4544 try { | |
| 4545 leftOperand.remainder(_typeProvider, rightOperand); | |
| 4546 fail("Expected an EvaluationException"); | |
| 4547 } on EvaluationException {} | |
| 4548 } else { | |
| 4549 DartObjectImpl result = | |
| 4550 leftOperand.remainder(_typeProvider, rightOperand); | |
| 4551 expect(result, isNotNull); | |
| 4552 expect(result, expected); | |
| 4553 } | |
| 4554 } | |
| 4555 | |
| 4556 /** | |
| 4557 * Assert that the result of multiplying the left and right operands is the ex
pected value, or | |
| 4558 * that the operation throws an exception if the expected value is `null`. | |
| 4559 * | |
| 4560 * @param expected the expected result of the operation | |
| 4561 * @param leftOperand the left operand to the operation | |
| 4562 * @param rightOperand the left operand to the operation | |
| 4563 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4564 */ | |
| 4565 void _assertShiftLeft(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4566 DartObjectImpl rightOperand) { | |
| 4567 if (expected == null) { | |
| 4568 try { | |
| 4569 leftOperand.shiftLeft(_typeProvider, rightOperand); | |
| 4570 fail("Expected an EvaluationException"); | |
| 4571 } on EvaluationException {} | |
| 4572 } else { | |
| 4573 DartObjectImpl result = | |
| 4574 leftOperand.shiftLeft(_typeProvider, rightOperand); | |
| 4575 expect(result, isNotNull); | |
| 4576 expect(result, expected); | |
| 4577 } | |
| 4578 } | |
| 4579 | |
| 4580 /** | |
| 4581 * Assert that the result of multiplying the left and right operands is the ex
pected value, or | |
| 4582 * that the operation throws an exception if the expected value is `null`. | |
| 4583 * | |
| 4584 * @param expected the expected result of the operation | |
| 4585 * @param leftOperand the left operand to the operation | |
| 4586 * @param rightOperand the left operand to the operation | |
| 4587 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4588 */ | |
| 4589 void _assertShiftRight(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4590 DartObjectImpl rightOperand) { | |
| 4591 if (expected == null) { | |
| 4592 try { | |
| 4593 leftOperand.shiftRight(_typeProvider, rightOperand); | |
| 4594 fail("Expected an EvaluationException"); | |
| 4595 } on EvaluationException {} | |
| 4596 } else { | |
| 4597 DartObjectImpl result = | |
| 4598 leftOperand.shiftRight(_typeProvider, rightOperand); | |
| 4599 expect(result, isNotNull); | |
| 4600 expect(result, expected); | |
| 4601 } | |
| 4602 } | |
| 4603 | |
| 4604 /** | |
| 4605 * Assert that the length of the operand is the expected value, or that the op
eration throws an | |
| 4606 * exception if the expected value is `null`. | |
| 4607 * | |
| 4608 * @param expected the expected result of the operation | |
| 4609 * @param operand the operand to the operation | |
| 4610 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4611 */ | |
| 4612 void _assertStringLength(DartObjectImpl expected, DartObjectImpl operand) { | |
| 4613 if (expected == null) { | |
| 4614 try { | |
| 4615 operand.stringLength(_typeProvider); | |
| 4616 fail("Expected an EvaluationException"); | |
| 4617 } on EvaluationException {} | |
| 4618 } else { | |
| 4619 DartObjectImpl result = operand.stringLength(_typeProvider); | |
| 4620 expect(result, isNotNull); | |
| 4621 expect(result, expected); | |
| 4622 } | |
| 4623 } | |
| 4624 | |
| 4625 /** | |
| 4626 * Assert that the result of multiplying the left and right operands is the ex
pected value, or | |
| 4627 * that the operation throws an exception if the expected value is `null`. | |
| 4628 * | |
| 4629 * @param expected the expected result of the operation | |
| 4630 * @param leftOperand the left operand to the operation | |
| 4631 * @param rightOperand the left operand to the operation | |
| 4632 * @throws EvaluationException if the result is an exception when it should no
t be | |
| 4633 */ | |
| 4634 void _assertTimes(DartObjectImpl expected, DartObjectImpl leftOperand, | |
| 4635 DartObjectImpl rightOperand) { | |
| 4636 if (expected == null) { | |
| 4637 try { | |
| 4638 leftOperand.times(_typeProvider, rightOperand); | |
| 4639 fail("Expected an EvaluationException"); | |
| 4640 } on EvaluationException {} | |
| 4641 } else { | |
| 4642 DartObjectImpl result = leftOperand.times(_typeProvider, rightOperand); | |
| 4643 expect(result, isNotNull); | |
| 4644 expect(result, expected); | |
| 4645 } | |
| 4646 } | |
| 4647 | |
| 4648 DartObjectImpl _boolValue(bool value) { | |
| 4649 if (value == null) { | |
| 4650 return new DartObjectImpl( | |
| 4651 _typeProvider.boolType, BoolState.UNKNOWN_VALUE); | |
| 4652 } else if (identical(value, false)) { | |
| 4653 return new DartObjectImpl(_typeProvider.boolType, BoolState.FALSE_STATE); | |
| 4654 } else if (identical(value, true)) { | |
| 4655 return new DartObjectImpl(_typeProvider.boolType, BoolState.TRUE_STATE); | |
| 4656 } | |
| 4657 fail("Invalid boolean value used in test"); | |
| 4658 return null; | |
| 4659 } | |
| 4660 | |
| 4661 DartObjectImpl _doubleValue(double value) { | |
| 4662 if (value == null) { | |
| 4663 return new DartObjectImpl( | |
| 4664 _typeProvider.doubleType, DoubleState.UNKNOWN_VALUE); | |
| 4665 } else { | |
| 4666 return new DartObjectImpl( | |
| 4667 _typeProvider.doubleType, new DoubleState(value)); | |
| 4668 } | |
| 4669 } | |
| 4670 | |
| 4671 DartObjectImpl _dynamicValue() { | |
| 4672 return new DartObjectImpl( | |
| 4673 _typeProvider.nullType, DynamicState.DYNAMIC_STATE); | |
| 4674 } | |
| 4675 | |
| 4676 DartObjectImpl _intValue(int value) { | |
| 4677 if (value == null) { | |
| 4678 return new DartObjectImpl(_typeProvider.intType, IntState.UNKNOWN_VALUE); | |
| 4679 } else { | |
| 4680 return new DartObjectImpl(_typeProvider.intType, new IntState(value)); | |
| 4681 } | |
| 4682 } | |
| 4683 | |
| 4684 DartObjectImpl _listValue( | |
| 4685 [List<DartObjectImpl> elements = DartObjectImpl.EMPTY_LIST]) { | |
| 4686 return new DartObjectImpl(_typeProvider.listType, new ListState(elements)); | |
| 4687 } | |
| 4688 | |
| 4689 DartObjectImpl _mapValue( | |
| 4690 [List<DartObjectImpl> keyElementPairs = DartObjectImpl.EMPTY_LIST]) { | |
| 4691 Map<DartObjectImpl, DartObjectImpl> map = | |
| 4692 new Map<DartObjectImpl, DartObjectImpl>(); | |
| 4693 int count = keyElementPairs.length; | |
| 4694 for (int i = 0; i < count;) { | |
| 4695 map[keyElementPairs[i++]] = keyElementPairs[i++]; | |
| 4696 } | |
| 4697 return new DartObjectImpl(_typeProvider.mapType, new MapState(map)); | |
| 4698 } | |
| 4699 | |
| 4700 DartObjectImpl _nullValue() { | |
| 4701 return new DartObjectImpl(_typeProvider.nullType, NullState.NULL_STATE); | |
| 4702 } | |
| 4703 | |
| 4704 DartObjectImpl _numValue() { | |
| 4705 return new DartObjectImpl(_typeProvider.nullType, NumState.UNKNOWN_VALUE); | |
| 4706 } | |
| 4707 | |
| 4708 DartObjectImpl _stringValue(String value) { | |
| 4709 if (value == null) { | |
| 4710 return new DartObjectImpl( | |
| 4711 _typeProvider.stringType, StringState.UNKNOWN_VALUE); | |
| 4712 } else { | |
| 4713 return new DartObjectImpl( | |
| 4714 _typeProvider.stringType, new StringState(value)); | |
| 4715 } | |
| 4716 } | |
| 4717 | |
| 4718 DartObjectImpl _symbolValue(String value) { | |
| 4719 return new DartObjectImpl(_typeProvider.symbolType, new SymbolState(value)); | |
| 4720 } | |
| 4721 } | |
| 4722 | |
| 4723 @reflectiveTest | |
| 4724 class DartUriResolverTest { | 143 class DartUriResolverTest { |
| 4725 void test_creation() { | 144 void test_creation() { |
| 4726 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 145 DartSdk sdk = _createSdk(); |
| 4727 expect(sdkDirectory, isNotNull); | |
| 4728 DartSdk sdk = new DirectoryBasedDartSdk(sdkDirectory); | |
| 4729 expect(new DartUriResolver(sdk), isNotNull); | 146 expect(new DartUriResolver(sdk), isNotNull); |
| 4730 } | 147 } |
| 4731 | 148 |
| 4732 void test_isDartUri_null_scheme() { | 149 void test_isDartUri_null_scheme() { |
| 4733 Uri uri = parseUriWithException("foo.dart"); | 150 Uri uri = Uri.parse("foo.dart"); |
| 4734 expect('', uri.scheme); | 151 expect('', uri.scheme); |
| 4735 expect(DartUriResolver.isDartUri(uri), isFalse); | 152 expect(DartUriResolver.isDartUri(uri), isFalse); |
| 4736 } | 153 } |
| 4737 | 154 |
| 4738 void test_resolve_dart() { | 155 void test_resolve_dart() { |
| 4739 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 156 DartSdk sdk = _createSdk(); |
| 4740 expect(sdkDirectory, isNotNull); | 157 UriResolver resolver = new DartUriResolver(sdk); |
| 4741 DartSdk sdk = new DirectoryBasedDartSdk(sdkDirectory); | 158 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); |
| 159 expect(result, isNotNull); |
| 160 } |
| 161 |
| 162 void test_resolve_dart_nonExistingLibrary() { |
| 163 DartSdk sdk = _createSdk(); |
| 164 UriResolver resolver = new DartUriResolver(sdk); |
| 165 Source result = resolver.resolveAbsolute(Uri.parse("dart:cor")); |
| 166 expect(result, isNull); |
| 167 } |
| 168 |
| 169 void test_resolve_nonDart() { |
| 170 DartSdk sdk = _createSdk(); |
| 4742 UriResolver resolver = new DartUriResolver(sdk); | 171 UriResolver resolver = new DartUriResolver(sdk); |
| 4743 Source result = | 172 Source result = |
| 4744 resolver.resolveAbsolute(parseUriWithException("dart:core")); | 173 resolver.resolveAbsolute(Uri.parse("package:some/file.dart")); |
| 4745 expect(result, isNotNull); | |
| 4746 } | |
| 4747 | |
| 4748 void test_resolve_dart_nonExistingLibrary() { | |
| 4749 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | |
| 4750 expect(sdkDirectory, isNotNull); | |
| 4751 DartSdk sdk = new DirectoryBasedDartSdk(sdkDirectory); | |
| 4752 UriResolver resolver = new DartUriResolver(sdk); | |
| 4753 Source result = resolver.resolveAbsolute(parseUriWithException("dart:cor")); | |
| 4754 expect(result, isNull); | 174 expect(result, isNull); |
| 4755 } | 175 } |
| 4756 | 176 } |
| 4757 void test_resolve_nonDart() { | 177 |
| 4758 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 178 @deprecated |
| 4759 expect(sdkDirectory, isNotNull); | |
| 4760 DartSdk sdk = new DirectoryBasedDartSdk(sdkDirectory); | |
| 4761 UriResolver resolver = new DartUriResolver(sdk); | |
| 4762 Source result = resolver | |
| 4763 .resolveAbsolute(parseUriWithException("package:some/file.dart")); | |
| 4764 expect(result, isNull); | |
| 4765 } | |
| 4766 } | |
| 4767 | |
| 4768 @reflectiveTest | |
| 4769 class DeclaredVariablesTest extends EngineTestCase { | |
| 4770 void test_getBool_false() { | |
| 4771 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4772 String variableName = "var"; | |
| 4773 DeclaredVariables variables = new DeclaredVariables(); | |
| 4774 variables.define(variableName, "false"); | |
| 4775 DartObject object = variables.getBool(typeProvider, variableName); | |
| 4776 expect(object, isNotNull); | |
| 4777 expect(object.toBoolValue(), false); | |
| 4778 } | |
| 4779 | |
| 4780 void test_getBool_invalid() { | |
| 4781 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4782 String variableName = "var"; | |
| 4783 DeclaredVariables variables = new DeclaredVariables(); | |
| 4784 variables.define(variableName, "not true"); | |
| 4785 _assertNullDartObject( | |
| 4786 typeProvider, variables.getBool(typeProvider, variableName)); | |
| 4787 } | |
| 4788 | |
| 4789 void test_getBool_true() { | |
| 4790 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4791 String variableName = "var"; | |
| 4792 DeclaredVariables variables = new DeclaredVariables(); | |
| 4793 variables.define(variableName, "true"); | |
| 4794 DartObject object = variables.getBool(typeProvider, variableName); | |
| 4795 expect(object, isNotNull); | |
| 4796 expect(object.toBoolValue(), true); | |
| 4797 } | |
| 4798 | |
| 4799 void test_getBool_undefined() { | |
| 4800 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4801 String variableName = "var"; | |
| 4802 DeclaredVariables variables = new DeclaredVariables(); | |
| 4803 _assertUnknownDartObject( | |
| 4804 typeProvider.boolType, variables.getBool(typeProvider, variableName)); | |
| 4805 } | |
| 4806 | |
| 4807 void test_getInt_invalid() { | |
| 4808 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4809 String variableName = "var"; | |
| 4810 DeclaredVariables variables = new DeclaredVariables(); | |
| 4811 variables.define(variableName, "four score and seven years"); | |
| 4812 _assertNullDartObject( | |
| 4813 typeProvider, variables.getInt(typeProvider, variableName)); | |
| 4814 } | |
| 4815 | |
| 4816 void test_getInt_undefined() { | |
| 4817 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4818 String variableName = "var"; | |
| 4819 DeclaredVariables variables = new DeclaredVariables(); | |
| 4820 _assertUnknownDartObject( | |
| 4821 typeProvider.intType, variables.getInt(typeProvider, variableName)); | |
| 4822 } | |
| 4823 | |
| 4824 void test_getInt_valid() { | |
| 4825 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4826 String variableName = "var"; | |
| 4827 DeclaredVariables variables = new DeclaredVariables(); | |
| 4828 variables.define(variableName, "23"); | |
| 4829 DartObject object = variables.getInt(typeProvider, variableName); | |
| 4830 expect(object, isNotNull); | |
| 4831 expect(object.toIntValue(), 23); | |
| 4832 } | |
| 4833 | |
| 4834 void test_getString_defined() { | |
| 4835 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4836 String variableName = "var"; | |
| 4837 String value = "value"; | |
| 4838 DeclaredVariables variables = new DeclaredVariables(); | |
| 4839 variables.define(variableName, value); | |
| 4840 DartObject object = variables.getString(typeProvider, variableName); | |
| 4841 expect(object, isNotNull); | |
| 4842 expect(object.toStringValue(), value); | |
| 4843 } | |
| 4844 | |
| 4845 void test_getString_undefined() { | |
| 4846 TestTypeProvider typeProvider = new TestTypeProvider(); | |
| 4847 String variableName = "var"; | |
| 4848 DeclaredVariables variables = new DeclaredVariables(); | |
| 4849 _assertUnknownDartObject(typeProvider.stringType, | |
| 4850 variables.getString(typeProvider, variableName)); | |
| 4851 } | |
| 4852 | |
| 4853 void _assertNullDartObject(TestTypeProvider typeProvider, DartObject result) { | |
| 4854 expect(result.type, typeProvider.nullType); | |
| 4855 } | |
| 4856 | |
| 4857 void _assertUnknownDartObject( | |
| 4858 ParameterizedType expectedType, DartObject result) { | |
| 4859 expect((result as DartObjectImpl).isUnknown, isTrue); | |
| 4860 expect(result.type, expectedType); | |
| 4861 } | |
| 4862 } | |
| 4863 | |
| 4864 @reflectiveTest | 179 @reflectiveTest |
| 4865 class DirectoryBasedDartSdkTest { | 180 class DirectoryBasedDartSdkTest { |
| 4866 void fail_getDocFileFor() { | 181 void fail_getDocFileFor() { |
| 4867 DirectoryBasedDartSdk sdk = _createDartSdk(); | 182 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4868 JavaFile docFile = sdk.getDocFileFor("html"); | 183 JavaFile docFile = sdk.getDocFileFor("html"); |
| 4869 expect(docFile, isNotNull); | 184 expect(docFile, isNotNull); |
| 4870 } | 185 } |
| 4871 | 186 |
| 187 void test_analysisOptions_afterContextCreation() { |
| 188 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 189 sdk.context; |
| 190 expect(() { |
| 191 sdk.analysisOptions = new AnalysisOptionsImpl(); |
| 192 }, throwsStateError); |
| 193 } |
| 194 |
| 195 void test_analysisOptions_beforeContextCreation() { |
| 196 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 197 sdk.analysisOptions = new AnalysisOptionsImpl(); |
| 198 sdk.context; |
| 199 // cannot change "analysisOptions" in the context |
| 200 expect(() { |
| 201 sdk.context.analysisOptions = new AnalysisOptionsImpl(); |
| 202 }, throwsStateError); |
| 203 } |
| 204 |
| 4872 void test_creation() { | 205 void test_creation() { |
| 4873 DirectoryBasedDartSdk sdk = _createDartSdk(); | 206 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4874 expect(sdk, isNotNull); | 207 expect(sdk, isNotNull); |
| 4875 } | 208 } |
| 4876 | 209 |
| 4877 void test_fromFile_invalid() { | 210 void test_fromFile_invalid() { |
| 4878 DirectoryBasedDartSdk sdk = _createDartSdk(); | 211 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4879 expect( | 212 expect( |
| 4880 sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), isNull); | 213 sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), isNull); |
| 4881 } | 214 } |
| 4882 | 215 |
| 4883 void test_fromFile_library() { | 216 void test_fromFile_library() { |
| 4884 DirectoryBasedDartSdk sdk = _createDartSdk(); | 217 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4885 Source source = sdk.fromFileUri(new JavaFile.relative( | 218 Source source = sdk.fromFileUri(new JavaFile.relative( |
| 4886 new JavaFile.relative(sdk.libraryDirectory, "core"), "core.dart") | 219 new JavaFile.relative(sdk.libraryDirectory, "core"), "core.dart") |
| 4887 .toURI()); | 220 .toURI()); |
| 4888 expect(source, isNotNull); | 221 expect(source, isNotNull); |
| 4889 expect(source.isInSystemLibrary, isTrue); | 222 expect(source.isInSystemLibrary, isTrue); |
| 4890 expect(source.uri.toString(), "dart:core"); | 223 expect(source.uri.toString(), "dart:core"); |
| 4891 } | 224 } |
| 4892 | 225 |
| 226 void test_fromFile_library_firstExact() { |
| 227 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 228 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); |
| 229 JavaFile dirDartium = new JavaFile.relative(dirHtml, "dartium"); |
| 230 JavaFile file = new JavaFile.relative(dirDartium, "html_dartium.dart"); |
| 231 expect(file.isFile(), isTrue); |
| 232 Source source = sdk.fromFileUri(file.toURI()); |
| 233 expect(source, isNotNull); |
| 234 expect(source.isInSystemLibrary, isTrue); |
| 235 expect(source.uri.toString(), "dart:html"); |
| 236 } |
| 237 |
| 238 void test_fromFile_library_html_common_dart2js() { |
| 239 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 240 JavaFile dirHtml = new JavaFile.relative(sdk.libraryDirectory, "html"); |
| 241 JavaFile dirCommon = new JavaFile.relative(dirHtml, "html_common"); |
| 242 JavaFile file = |
| 243 new JavaFile.relative(dirCommon, "html_common_dart2js.dart"); |
| 244 expect(file.isFile(), isTrue); |
| 245 Source source = sdk.fromFileUri(file.toURI()); |
| 246 expect(source, isNotNull); |
| 247 expect(source.isInSystemLibrary, isTrue); |
| 248 expect(source.uri.toString(), "dart:html_common/html_common_dart2js.dart"); |
| 249 } |
| 250 |
| 4893 void test_fromFile_part() { | 251 void test_fromFile_part() { |
| 4894 DirectoryBasedDartSdk sdk = _createDartSdk(); | 252 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4895 Source source = sdk.fromFileUri(new JavaFile.relative( | 253 Source source = sdk.fromFileUri(new JavaFile.relative( |
| 4896 new JavaFile.relative(sdk.libraryDirectory, "core"), "num.dart") | 254 new JavaFile.relative(sdk.libraryDirectory, "core"), "num.dart") |
| 4897 .toURI()); | 255 .toURI()); |
| 4898 expect(source, isNotNull); | 256 expect(source, isNotNull); |
| 4899 expect(source.isInSystemLibrary, isTrue); | 257 expect(source.isInSystemLibrary, isTrue); |
| 4900 expect(source.uri.toString(), "dart:core/num.dart"); | 258 expect(source.uri.toString(), "dart:core/num.dart"); |
| 4901 } | 259 } |
| 4902 | 260 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4944 } | 302 } |
| 4945 | 303 |
| 4946 void test_getVmExecutable() { | 304 void test_getVmExecutable() { |
| 4947 DirectoryBasedDartSdk sdk = _createDartSdk(); | 305 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 4948 JavaFile executable = sdk.vmExecutable; | 306 JavaFile executable = sdk.vmExecutable; |
| 4949 expect(executable, isNotNull); | 307 expect(executable, isNotNull); |
| 4950 expect(executable.exists(), isTrue); | 308 expect(executable.exists(), isTrue); |
| 4951 expect(executable.isExecutable(), isTrue); | 309 expect(executable.isExecutable(), isTrue); |
| 4952 } | 310 } |
| 4953 | 311 |
| 312 void test_useSummary_afterContextCreation() { |
| 313 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 314 sdk.context; |
| 315 expect(() { |
| 316 sdk.useSummary = true; |
| 317 }, throwsStateError); |
| 318 } |
| 319 |
| 320 void test_useSummary_beforeContextCreation() { |
| 321 DirectoryBasedDartSdk sdk = _createDartSdk(); |
| 322 sdk.useSummary = true; |
| 323 sdk.context; |
| 324 } |
| 325 |
| 4954 DirectoryBasedDartSdk _createDartSdk() { | 326 DirectoryBasedDartSdk _createDartSdk() { |
| 4955 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 327 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; |
| 4956 expect(sdkDirectory, isNotNull, | 328 expect(sdkDirectory, isNotNull, |
| 4957 reason: | 329 reason: |
| 4958 "No SDK configured; set the property 'com.google.dart.sdk' on the co
mmand line"); | 330 "No SDK configured; set the property 'com.google.dart.sdk' on the co
mmand line"); |
| 4959 return new DirectoryBasedDartSdk(sdkDirectory); | 331 return new DirectoryBasedDartSdk(sdkDirectory); |
| 4960 } | 332 } |
| 4961 } | 333 } |
| 4962 | 334 |
| 335 @deprecated |
| 4963 @reflectiveTest | 336 @reflectiveTest |
| 4964 class DirectoryBasedSourceContainerTest { | 337 class DirectoryBasedSourceContainerTest { |
| 4965 void test_contains() { | 338 void test_contains() { |
| 4966 JavaFile dir = FileUtilities2.createFile("/does/not/exist"); | 339 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 4967 JavaFile file1 = FileUtilities2.createFile("/does/not/exist/some.dart"); | 340 File file1 = resourceProvider.getFile('/does/not/exist/some.dart'); |
| 4968 JavaFile file2 = | 341 File file2 = resourceProvider.getFile('/does/not/exist/folder/some2.dart'); |
| 4969 FileUtilities2.createFile("/does/not/exist/folder/some2.dart"); | 342 File file3 = resourceProvider.getFile('/does/not/exist3/some3.dart'); |
| 4970 JavaFile file3 = FileUtilities2.createFile("/does/not/exist3/some3.dart"); | 343 Source source1 = new FileSource(file1); |
| 4971 FileBasedSource source1 = new FileBasedSource(file1); | 344 Source source2 = new FileSource(file2); |
| 4972 FileBasedSource source2 = new FileBasedSource(file2); | 345 Source source3 = new FileSource(file3); |
| 4973 FileBasedSource source3 = new FileBasedSource(file3); | |
| 4974 DirectoryBasedSourceContainer container = | 346 DirectoryBasedSourceContainer container = |
| 4975 new DirectoryBasedSourceContainer.con1(dir); | 347 new DirectoryBasedSourceContainer.con2('/does/not/exist'); |
| 4976 expect(container.contains(source1), isTrue); | 348 expect(container.contains(source1), isTrue); |
| 4977 expect(container.contains(source2), isTrue); | 349 expect(container.contains(source2), isTrue); |
| 4978 expect(container.contains(source3), isFalse); | 350 expect(container.contains(source3), isFalse); |
| 4979 } | 351 } |
| 4980 } | 352 } |
| 4981 | 353 |
| 4982 @reflectiveTest | 354 @reflectiveTest |
| 4983 class ElementBuilderTest extends EngineTestCase { | 355 class ElementBuilderTest extends ParserTestCase { |
| 356 CompilationUnitElement compilationUnitElement; |
| 357 CompilationUnit compilationUnit; |
| 358 |
| 359 /** |
| 360 * Parse the given [code], pass it through [ElementBuilder], and return the |
| 361 * resulting [ElementHolder]. |
| 362 */ |
| 363 ElementHolder buildElementsForText(String code) { |
| 364 TestLogger logger = new TestLogger(); |
| 365 AnalysisEngine.instance.logger = logger; |
| 366 try { |
| 367 compilationUnit = ParserTestCase.parseCompilationUnit(code); |
| 368 ElementHolder holder = new ElementHolder(); |
| 369 ElementBuilder builder = |
| 370 new ElementBuilder(holder, compilationUnitElement); |
| 371 compilationUnit.accept(builder); |
| 372 return holder; |
| 373 } finally { |
| 374 expect(logger.log, hasLength(0)); |
| 375 AnalysisEngine.instance.logger = Logger.NULL; |
| 376 } |
| 377 } |
| 378 |
| 379 /** |
| 380 * Verify that the given [metadata] has exactly one annotation, and that its |
| 381 * [ElementAnnotationImpl] is unresolved. |
| 382 */ |
| 383 void checkAnnotation(NodeList<Annotation> metadata) { |
| 384 expect(metadata, hasLength(1)); |
| 385 expect(metadata[0], new isInstanceOf<AnnotationImpl>()); |
| 386 AnnotationImpl annotation = metadata[0]; |
| 387 expect(annotation.elementAnnotation, |
| 388 new isInstanceOf<ElementAnnotationImpl>()); |
| 389 ElementAnnotationImpl elementAnnotation = annotation.elementAnnotation; |
| 390 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 391 expect(elementAnnotation.compilationUnit, isNotNull); |
| 392 expect(elementAnnotation.compilationUnit, compilationUnitElement); |
| 393 } |
| 394 |
| 395 /** |
| 396 * Verify that the given [element] has exactly one annotation, and that its |
| 397 * [ElementAnnotationImpl] is unresolved. |
| 398 */ |
| 399 void checkMetadata(Element element) { |
| 400 expect(element.metadata, hasLength(1)); |
| 401 expect(element.metadata[0], new isInstanceOf<ElementAnnotationImpl>()); |
| 402 ElementAnnotationImpl elementAnnotation = element.metadata[0]; |
| 403 expect(elementAnnotation.element, isNull); // Not yet resolved |
| 404 expect(elementAnnotation.compilationUnit, isNotNull); |
| 405 expect(elementAnnotation.compilationUnit, compilationUnitElement); |
| 406 } |
| 407 |
| 408 void fail_visitMethodDeclaration_setter_duplicate() { |
| 409 // https://github.com/dart-lang/sdk/issues/25601 |
| 410 String code = r''' |
| 411 class C { |
| 412 set zzz(x) {} |
| 413 set zzz(y) {} |
| 414 } |
| 415 '''; |
| 416 ClassElement classElement = buildElementsForText(code).types[0]; |
| 417 for (PropertyAccessorElement accessor in classElement.accessors) { |
| 418 expect(accessor.variable.setter, same(accessor)); |
| 419 } |
| 420 } |
| 421 |
| 422 @override |
| 423 void setUp() { |
| 424 super.setUp(); |
| 425 compilationUnitElement = new CompilationUnitElementImpl('test.dart'); |
| 426 } |
| 427 |
| 428 void test_metadata_fieldDeclaration() { |
| 429 List<FieldElement> fields = |
| 430 buildElementsForText('class C { @a int x, y; }').types[0].fields; |
| 431 checkMetadata(fields[0]); |
| 432 checkMetadata(fields[1]); |
| 433 expect(fields[0].metadata, same(fields[1].metadata)); |
| 434 } |
| 435 |
| 436 void test_metadata_localVariableDeclaration() { |
| 437 List<LocalVariableElement> localVariables = |
| 438 buildElementsForText('f() { @a int x, y; }') |
| 439 .functions[0] |
| 440 .localVariables; |
| 441 checkMetadata(localVariables[0]); |
| 442 checkMetadata(localVariables[1]); |
| 443 expect(localVariables[0].metadata, same(localVariables[1].metadata)); |
| 444 } |
| 445 |
| 446 void test_metadata_topLevelVariableDeclaration() { |
| 447 List<TopLevelVariableElement> topLevelVariables = |
| 448 buildElementsForText('@a int x, y;').topLevelVariables; |
| 449 checkMetadata(topLevelVariables[0]); |
| 450 checkMetadata(topLevelVariables[1]); |
| 451 expect(topLevelVariables[0].metadata, same(topLevelVariables[1].metadata)); |
| 452 } |
| 453 |
| 454 void test_metadata_visitClassDeclaration() { |
| 455 ClassElement classElement = buildElementsForText('@a class C {}').types[0]; |
| 456 checkMetadata(classElement); |
| 457 } |
| 458 |
| 459 void test_metadata_visitClassTypeAlias() { |
| 460 ClassElement classElement = |
| 461 buildElementsForText('@a class C = D with E;').types[0]; |
| 462 checkMetadata(classElement); |
| 463 } |
| 464 |
| 465 void test_metadata_visitConstructorDeclaration() { |
| 466 ConstructorElement constructorElement = |
| 467 buildElementsForText('class C { @a C(); }').types[0].constructors[0]; |
| 468 checkMetadata(constructorElement); |
| 469 } |
| 470 |
| 471 void test_metadata_visitDeclaredIdentifier() { |
| 472 LocalVariableElement localVariableElement = |
| 473 buildElementsForText('f() { for (@a var x in y) {} }') |
| 474 .functions[0] |
| 475 .localVariables[0]; |
| 476 checkMetadata(localVariableElement); |
| 477 } |
| 478 |
| 479 void test_metadata_visitDefaultFormalParameter_fieldFormalParameter() { |
| 480 ParameterElement parameterElement = |
| 481 buildElementsForText('class C { var x; C([@a this.x = null]); }') |
| 482 .types[0] |
| 483 .constructors[0] |
| 484 .parameters[0]; |
| 485 checkMetadata(parameterElement); |
| 486 } |
| 487 |
| 488 void |
| 489 test_metadata_visitDefaultFormalParameter_functionTypedFormalParameter() { |
| 490 ParameterElement parameterElement = |
| 491 buildElementsForText('f([@a g() = null]) {}') |
| 492 .functions[0] |
| 493 .parameters[0]; |
| 494 checkMetadata(parameterElement); |
| 495 } |
| 496 |
| 497 void test_metadata_visitDefaultFormalParameter_simpleFormalParameter() { |
| 498 ParameterElement parameterElement = |
| 499 buildElementsForText('f([@a gx = null]) {}').functions[0].parameters[0]; |
| 500 checkMetadata(parameterElement); |
| 501 } |
| 502 |
| 503 void test_metadata_visitEnumDeclaration() { |
| 504 ClassElement classElement = |
| 505 buildElementsForText('@a enum E { v }').enums[0]; |
| 506 checkMetadata(classElement); |
| 507 } |
| 508 |
| 509 void test_metadata_visitExportDirective() { |
| 510 buildElementsForText('@a export "foo.dart";'); |
| 511 expect(compilationUnit.directives[0], new isInstanceOf<ExportDirective>()); |
| 512 ExportDirective exportDirective = compilationUnit.directives[0]; |
| 513 checkAnnotation(exportDirective.metadata); |
| 514 } |
| 515 |
| 516 void test_metadata_visitFieldFormalParameter() { |
| 517 ParameterElement parameterElement = |
| 518 buildElementsForText('class C { var x; C(@a this.x); }') |
| 519 .types[0] |
| 520 .constructors[0] |
| 521 .parameters[0]; |
| 522 checkMetadata(parameterElement); |
| 523 } |
| 524 |
| 525 void test_metadata_visitFunctionDeclaration_function() { |
| 526 FunctionElement functionElement = |
| 527 buildElementsForText('@a f() {}').functions[0]; |
| 528 checkMetadata(functionElement); |
| 529 } |
| 530 |
| 531 void test_metadata_visitFunctionDeclaration_getter() { |
| 532 PropertyAccessorElement propertyAccessorElement = |
| 533 buildElementsForText('@a get f => null;').accessors[0]; |
| 534 checkMetadata(propertyAccessorElement); |
| 535 } |
| 536 |
| 537 void test_metadata_visitFunctionDeclaration_setter() { |
| 538 PropertyAccessorElement propertyAccessorElement = |
| 539 buildElementsForText('@a set f(value) {}').accessors[0]; |
| 540 checkMetadata(propertyAccessorElement); |
| 541 } |
| 542 |
| 543 void test_metadata_visitFunctionTypeAlias() { |
| 544 FunctionTypeAliasElement functionTypeAliasElement = |
| 545 buildElementsForText('@a typedef F();').typeAliases[0]; |
| 546 checkMetadata(functionTypeAliasElement); |
| 547 } |
| 548 |
| 549 void test_metadata_visitFunctionTypedFormalParameter() { |
| 550 ParameterElement parameterElement = |
| 551 buildElementsForText('f(@a g()) {}').functions[0].parameters[0]; |
| 552 checkMetadata(parameterElement); |
| 553 } |
| 554 |
| 555 void test_metadata_visitImportDirective() { |
| 556 buildElementsForText('@a import "foo.dart";'); |
| 557 expect(compilationUnit.directives[0], new isInstanceOf<ImportDirective>()); |
| 558 ImportDirective importDirective = compilationUnit.directives[0]; |
| 559 checkAnnotation(importDirective.metadata); |
| 560 } |
| 561 |
| 562 void test_metadata_visitLibraryDirective() { |
| 563 buildElementsForText('@a library L;'); |
| 564 expect(compilationUnit.directives[0], new isInstanceOf<LibraryDirective>()); |
| 565 LibraryDirective libraryDirective = compilationUnit.directives[0]; |
| 566 checkAnnotation(libraryDirective.metadata); |
| 567 } |
| 568 |
| 569 void test_metadata_visitMethodDeclaration_getter() { |
| 570 PropertyAccessorElement propertyAccessorElement = |
| 571 buildElementsForText('class C { @a get m => null; }') |
| 572 .types[0] |
| 573 .accessors[0]; |
| 574 checkMetadata(propertyAccessorElement); |
| 575 } |
| 576 |
| 577 void test_metadata_visitMethodDeclaration_method() { |
| 578 MethodElement methodElement = |
| 579 buildElementsForText('class C { @a m() {} }').types[0].methods[0]; |
| 580 checkMetadata(methodElement); |
| 581 } |
| 582 |
| 583 void test_metadata_visitMethodDeclaration_setter() { |
| 584 PropertyAccessorElement propertyAccessorElement = |
| 585 buildElementsForText('class C { @a set f(value) {} }') |
| 586 .types[0] |
| 587 .accessors[0]; |
| 588 checkMetadata(propertyAccessorElement); |
| 589 } |
| 590 |
| 591 void test_metadata_visitPartDirective() { |
| 592 buildElementsForText('@a part "foo.dart";'); |
| 593 expect(compilationUnit.directives[0], new isInstanceOf<PartDirective>()); |
| 594 PartDirective partDirective = compilationUnit.directives[0]; |
| 595 checkAnnotation(partDirective.metadata); |
| 596 } |
| 597 |
| 598 void test_metadata_visitPartOfDirective() { |
| 599 // We don't build ElementAnnotation objects for `part of` directives, since |
| 600 // analyzer ignores them in favor of annotations on the library directive. |
| 601 buildElementsForText('@a part of L;'); |
| 602 expect(compilationUnit.directives[0], new isInstanceOf<PartOfDirective>()); |
| 603 PartOfDirective partOfDirective = compilationUnit.directives[0]; |
| 604 expect(partOfDirective.metadata, hasLength(1)); |
| 605 expect(partOfDirective.metadata[0].elementAnnotation, isNull); |
| 606 } |
| 607 |
| 608 void test_metadata_visitSimpleFormalParameter() { |
| 609 ParameterElement parameterElement = |
| 610 buildElementsForText('f(@a x) {}').functions[0].parameters[0]; |
| 611 checkMetadata(parameterElement); |
| 612 } |
| 613 |
| 614 void test_metadata_visitTypeParameter() { |
| 615 TypeParameterElement typeParameterElement = |
| 616 buildElementsForText('class C<@a T> {}').types[0].typeParameters[0]; |
| 617 checkMetadata(typeParameterElement); |
| 618 } |
| 619 |
| 4984 void test_visitCatchClause() { | 620 void test_visitCatchClause() { |
| 4985 // } catch (e, s) { | 621 // } catch (e, s) { |
| 4986 ElementHolder holder = new ElementHolder(); | 622 ElementHolder holder = new ElementHolder(); |
| 4987 ElementBuilder builder = new ElementBuilder(holder); | 623 ElementBuilder builder = _makeBuilder(holder); |
| 4988 String exceptionParameterName = "e"; | 624 String exceptionParameterName = "e"; |
| 4989 String stackParameterName = "s"; | 625 String stackParameterName = "s"; |
| 4990 CatchClause clause = | 626 CatchClause clause = |
| 4991 AstFactory.catchClause2(exceptionParameterName, stackParameterName); | 627 AstFactory.catchClause2(exceptionParameterName, stackParameterName); |
| 628 _setNodeSourceRange(clause, 100, 110); |
| 4992 clause.accept(builder); | 629 clause.accept(builder); |
| 4993 | 630 |
| 4994 List<LocalVariableElement> variables = holder.localVariables; | 631 List<LocalVariableElement> variables = holder.localVariables; |
| 4995 expect(variables, hasLength(2)); | 632 expect(variables, hasLength(2)); |
| 4996 VariableElement exceptionVariable = variables[0]; | 633 |
| 634 LocalVariableElement exceptionVariable = variables[0]; |
| 4997 expect(exceptionVariable, isNotNull); | 635 expect(exceptionVariable, isNotNull); |
| 4998 expect(exceptionVariable.name, exceptionParameterName); | 636 expect(exceptionVariable.name, exceptionParameterName); |
| 4999 expect(exceptionVariable.hasImplicitType, isTrue); | 637 expect(exceptionVariable.hasImplicitType, isTrue); |
| 5000 expect(exceptionVariable.isSynthetic, isFalse); | 638 expect(exceptionVariable.isSynthetic, isFalse); |
| 5001 expect(exceptionVariable.isConst, isFalse); | 639 expect(exceptionVariable.isConst, isFalse); |
| 5002 expect(exceptionVariable.isFinal, isFalse); | 640 expect(exceptionVariable.isFinal, isFalse); |
| 5003 expect(exceptionVariable.initializer, isNull); | 641 expect(exceptionVariable.initializer, isNull); |
| 5004 VariableElement stackVariable = variables[1]; | 642 _assertVisibleRange(exceptionVariable, 100, 110); |
| 643 |
| 644 LocalVariableElement stackVariable = variables[1]; |
| 5005 expect(stackVariable, isNotNull); | 645 expect(stackVariable, isNotNull); |
| 5006 expect(stackVariable.name, stackParameterName); | 646 expect(stackVariable.name, stackParameterName); |
| 5007 expect(stackVariable.isSynthetic, isFalse); | 647 expect(stackVariable.isSynthetic, isFalse); |
| 5008 expect(stackVariable.isConst, isFalse); | 648 expect(stackVariable.isConst, isFalse); |
| 5009 expect(stackVariable.isFinal, isFalse); | 649 expect(stackVariable.isFinal, isFalse); |
| 5010 expect(stackVariable.initializer, isNull); | 650 expect(stackVariable.initializer, isNull); |
| 651 _assertVisibleRange(stackVariable, 100, 110); |
| 5011 } | 652 } |
| 5012 | 653 |
| 5013 void test_visitCatchClause_withType() { | 654 void test_visitCatchClause_withType() { |
| 5014 // } on E catch (e) { | 655 // } on E catch (e) { |
| 5015 ElementHolder holder = new ElementHolder(); | 656 ElementHolder holder = new ElementHolder(); |
| 5016 ElementBuilder builder = new ElementBuilder(holder); | 657 ElementBuilder builder = _makeBuilder(holder); |
| 5017 String exceptionParameterName = "e"; | 658 String exceptionParameterName = "e"; |
| 5018 CatchClause clause = AstFactory.catchClause4( | 659 CatchClause clause = AstFactory.catchClause4( |
| 5019 AstFactory.typeName4('E'), exceptionParameterName); | 660 AstFactory.typeName4('E'), exceptionParameterName); |
| 5020 clause.accept(builder); | 661 clause.accept(builder); |
| 5021 | 662 |
| 5022 List<LocalVariableElement> variables = holder.localVariables; | 663 List<LocalVariableElement> variables = holder.localVariables; |
| 5023 expect(variables, hasLength(1)); | 664 expect(variables, hasLength(1)); |
| 5024 VariableElement exceptionVariable = variables[0]; | 665 VariableElement exceptionVariable = variables[0]; |
| 5025 expect(exceptionVariable, isNotNull); | 666 expect(exceptionVariable, isNotNull); |
| 5026 expect(exceptionVariable.name, exceptionParameterName); | 667 expect(exceptionVariable.name, exceptionParameterName); |
| 5027 expect(exceptionVariable.hasImplicitType, isFalse); | 668 expect(exceptionVariable.hasImplicitType, isFalse); |
| 5028 } | 669 } |
| 5029 | 670 |
| 5030 void test_visitClassDeclaration_abstract() { | 671 void test_visitClassDeclaration_abstract() { |
| 5031 ElementHolder holder = new ElementHolder(); | 672 ElementHolder holder = new ElementHolder(); |
| 5032 ElementBuilder builder = new ElementBuilder(holder); | 673 ElementBuilder builder = _makeBuilder(holder); |
| 5033 String className = "C"; | 674 String className = "C"; |
| 5034 ClassDeclaration classDeclaration = AstFactory.classDeclaration( | 675 ClassDeclaration classDeclaration = AstFactory.classDeclaration( |
| 5035 Keyword.ABSTRACT, className, null, null, null, null); | 676 Keyword.ABSTRACT, className, null, null, null, null); |
| 5036 classDeclaration.accept(builder); | 677 classDeclaration.accept(builder); |
| 5037 List<ClassElement> types = holder.types; | 678 List<ClassElement> types = holder.types; |
| 5038 expect(types, hasLength(1)); | 679 expect(types, hasLength(1)); |
| 5039 ClassElement type = types[0]; | 680 ClassElement type = types[0]; |
| 5040 expect(type, isNotNull); | 681 expect(type, isNotNull); |
| 5041 expect(type.name, className); | 682 expect(type.name, className); |
| 5042 List<TypeParameterElement> typeParameters = type.typeParameters; | 683 List<TypeParameterElement> typeParameters = type.typeParameters; |
| 5043 expect(typeParameters, hasLength(0)); | 684 expect(typeParameters, hasLength(0)); |
| 5044 expect(type.isAbstract, isTrue); | 685 expect(type.isAbstract, isTrue); |
| 5045 expect(type.isMixinApplication, isFalse); | 686 expect(type.isMixinApplication, isFalse); |
| 5046 expect(type.isSynthetic, isFalse); | 687 expect(type.isSynthetic, isFalse); |
| 5047 } | 688 } |
| 5048 | 689 |
| 690 void test_visitClassDeclaration_invalidFunctionInAnnotation_class() { |
| 691 // https://github.com/dart-lang/sdk/issues/25696 |
| 692 String code = r''' |
| 693 class A { |
| 694 const A({f}); |
| 695 } |
| 696 |
| 697 @A(f: () {}) |
| 698 class C {} |
| 699 '''; |
| 700 buildElementsForText(code); |
| 701 } |
| 702 |
| 703 void test_visitClassDeclaration_invalidFunctionInAnnotation_method() { |
| 704 String code = r''' |
| 705 class A { |
| 706 const A({f}); |
| 707 } |
| 708 |
| 709 class C { |
| 710 @A(f: () {}) |
| 711 void m() {} |
| 712 } |
| 713 '''; |
| 714 ElementHolder holder = buildElementsForText(code); |
| 715 ClassElement elementC = holder.types[1]; |
| 716 expect(elementC, isNotNull); |
| 717 MethodElement methodM = elementC.methods[0]; |
| 718 expect(methodM, isNotNull); |
| 719 expect(methodM.functions, isEmpty); |
| 720 } |
| 721 |
| 5049 void test_visitClassDeclaration_minimal() { | 722 void test_visitClassDeclaration_minimal() { |
| 5050 ElementHolder holder = new ElementHolder(); | 723 ElementHolder holder = new ElementHolder(); |
| 5051 ElementBuilder builder = new ElementBuilder(holder); | 724 ElementBuilder builder = _makeBuilder(holder); |
| 5052 String className = "C"; | 725 String className = "C"; |
| 5053 ClassDeclaration classDeclaration = | 726 ClassDeclaration classDeclaration = |
| 5054 AstFactory.classDeclaration(null, className, null, null, null, null); | 727 AstFactory.classDeclaration(null, className, null, null, null, null); |
| 5055 classDeclaration.documentationComment = AstFactory.documentationComment( | 728 classDeclaration.documentationComment = AstFactory.documentationComment( |
| 5056 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 729 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 730 classDeclaration.endToken.offset = 80; |
| 5057 classDeclaration.accept(builder); | 731 classDeclaration.accept(builder); |
| 5058 List<ClassElement> types = holder.types; | 732 List<ClassElement> types = holder.types; |
| 5059 expect(types, hasLength(1)); | 733 expect(types, hasLength(1)); |
| 5060 ClassElement type = types[0]; | 734 ClassElement type = types[0]; |
| 5061 expect(type, isNotNull); | 735 expect(type, isNotNull); |
| 5062 expect(type.name, className); | 736 expect(type.name, className); |
| 5063 List<TypeParameterElement> typeParameters = type.typeParameters; | 737 List<TypeParameterElement> typeParameters = type.typeParameters; |
| 5064 expect(typeParameters, hasLength(0)); | 738 expect(typeParameters, hasLength(0)); |
| 5065 expect(type.isAbstract, isFalse); | 739 expect(type.isAbstract, isFalse); |
| 5066 expect(type.isMixinApplication, isFalse); | 740 expect(type.isMixinApplication, isFalse); |
| 5067 expect(type.isSynthetic, isFalse); | 741 expect(type.isSynthetic, isFalse); |
| 5068 _assertHasDocRange(type, 50, 7); | 742 expect(type.documentationComment, '/// aaa'); |
| 743 _assertHasCodeRange(type, 50, 31); |
| 5069 } | 744 } |
| 5070 | 745 |
| 5071 void test_visitClassDeclaration_parameterized() { | 746 void test_visitClassDeclaration_parameterized() { |
| 5072 ElementHolder holder = new ElementHolder(); | 747 ElementHolder holder = new ElementHolder(); |
| 5073 ElementBuilder builder = new ElementBuilder(holder); | 748 ElementBuilder builder = _makeBuilder(holder); |
| 5074 String className = "C"; | 749 String className = "C"; |
| 5075 String firstVariableName = "E"; | 750 String firstVariableName = "E"; |
| 5076 String secondVariableName = "F"; | 751 String secondVariableName = "F"; |
| 5077 ClassDeclaration classDeclaration = AstFactory.classDeclaration( | 752 ClassDeclaration classDeclaration = AstFactory.classDeclaration( |
| 5078 null, | 753 null, |
| 5079 className, | 754 className, |
| 5080 AstFactory.typeParameterList([firstVariableName, secondVariableName]), | 755 AstFactory.typeParameterList([firstVariableName, secondVariableName]), |
| 5081 null, | 756 null, |
| 5082 null, | 757 null, |
| 5083 null); | 758 null); |
| 5084 classDeclaration.accept(builder); | 759 classDeclaration.accept(builder); |
| 5085 List<ClassElement> types = holder.types; | 760 List<ClassElement> types = holder.types; |
| 5086 expect(types, hasLength(1)); | 761 expect(types, hasLength(1)); |
| 5087 ClassElement type = types[0]; | 762 ClassElement type = types[0]; |
| 5088 expect(type, isNotNull); | 763 expect(type, isNotNull); |
| 5089 expect(type.name, className); | 764 expect(type.name, className); |
| 5090 List<TypeParameterElement> typeParameters = type.typeParameters; | 765 List<TypeParameterElement> typeParameters = type.typeParameters; |
| 5091 expect(typeParameters, hasLength(2)); | 766 expect(typeParameters, hasLength(2)); |
| 5092 expect(typeParameters[0].name, firstVariableName); | 767 expect(typeParameters[0].name, firstVariableName); |
| 5093 expect(typeParameters[1].name, secondVariableName); | 768 expect(typeParameters[1].name, secondVariableName); |
| 5094 expect(type.isAbstract, isFalse); | 769 expect(type.isAbstract, isFalse); |
| 5095 expect(type.isMixinApplication, isFalse); | 770 expect(type.isMixinApplication, isFalse); |
| 5096 expect(type.isSynthetic, isFalse); | 771 expect(type.isSynthetic, isFalse); |
| 5097 } | 772 } |
| 5098 | 773 |
| 5099 void test_visitClassDeclaration_withMembers() { | 774 void test_visitClassDeclaration_withMembers() { |
| 5100 ElementHolder holder = new ElementHolder(); | 775 ElementHolder holder = new ElementHolder(); |
| 5101 ElementBuilder builder = new ElementBuilder(holder); | 776 ElementBuilder builder = _makeBuilder(holder); |
| 5102 String className = "C"; | 777 String className = "C"; |
| 5103 String typeParameterName = "E"; | 778 String typeParameterName = "E"; |
| 5104 String fieldName = "f"; | 779 String fieldName = "f"; |
| 5105 String methodName = "m"; | 780 String methodName = "m"; |
| 5106 ClassDeclaration classDeclaration = AstFactory.classDeclaration( | 781 ClassDeclaration classDeclaration = AstFactory.classDeclaration( |
| 5107 null, | 782 null, |
| 5108 className, | 783 className, |
| 5109 AstFactory.typeParameterList([typeParameterName]), | 784 AstFactory.typeParameterList([typeParameterName]), |
| 5110 null, | 785 null, |
| 5111 null, | 786 null, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5145 MethodElement method = methods[0]; | 820 MethodElement method = methods[0]; |
| 5146 expect(method, isNotNull); | 821 expect(method, isNotNull); |
| 5147 expect(method.name, methodName); | 822 expect(method.name, methodName); |
| 5148 } | 823 } |
| 5149 | 824 |
| 5150 void test_visitClassTypeAlias() { | 825 void test_visitClassTypeAlias() { |
| 5151 // class B {} | 826 // class B {} |
| 5152 // class M {} | 827 // class M {} |
| 5153 // class C = B with M | 828 // class C = B with M |
| 5154 ElementHolder holder = new ElementHolder(); | 829 ElementHolder holder = new ElementHolder(); |
| 5155 ElementBuilder builder = new ElementBuilder(holder); | 830 ElementBuilder builder = _makeBuilder(holder); |
| 5156 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 831 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
| 5157 ConstructorElementImpl constructorB = | 832 ConstructorElementImpl constructorB = |
| 5158 ElementFactory.constructorElement2(classB, '', []); | 833 ElementFactory.constructorElement2(classB, '', []); |
| 5159 constructorB.setModifier(Modifier.SYNTHETIC, true); | 834 constructorB.setModifier(Modifier.SYNTHETIC, true); |
| 5160 classB.constructors = [constructorB]; | 835 classB.constructors = [constructorB]; |
| 5161 ClassElement classM = ElementFactory.classElement2('M', []); | 836 ClassElement classM = ElementFactory.classElement2('M', []); |
| 5162 WithClause withClause = | 837 WithClause withClause = |
| 5163 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 838 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
| 5164 ClassTypeAlias alias = AstFactory.classTypeAlias( | 839 ClassTypeAlias alias = AstFactory.classTypeAlias( |
| 5165 'C', null, null, AstFactory.typeName(classB, []), withClause, null); | 840 'C', null, null, AstFactory.typeName(classB, []), withClause, null); |
| 5166 alias.accept(builder); | 841 alias.accept(builder); |
| 5167 List<ClassElement> types = holder.types; | 842 List<ClassElement> types = holder.types; |
| 5168 expect(types, hasLength(1)); | 843 expect(types, hasLength(1)); |
| 5169 ClassElement type = types[0]; | 844 ClassElement type = types[0]; |
| 5170 expect(alias.element, same(type)); | 845 expect(alias.element, same(type)); |
| 5171 expect(type.name, equals('C')); | 846 expect(type.name, equals('C')); |
| 5172 expect(type.isAbstract, isFalse); | 847 expect(type.isAbstract, isFalse); |
| 5173 expect(type.isMixinApplication, isTrue); | 848 expect(type.isMixinApplication, isTrue); |
| 5174 expect(type.isSynthetic, isFalse); | 849 expect(type.isSynthetic, isFalse); |
| 5175 expect(type.typeParameters, isEmpty); | 850 expect(type.typeParameters, isEmpty); |
| 5176 expect(type.fields, isEmpty); | 851 expect(type.fields, isEmpty); |
| 5177 expect(type.methods, isEmpty); | 852 expect(type.methods, isEmpty); |
| 5178 } | 853 } |
| 5179 | 854 |
| 5180 void test_visitClassTypeAlias_abstract() { | 855 void test_visitClassTypeAlias_abstract() { |
| 5181 // class B {} | 856 // class B {} |
| 5182 // class M {} | 857 // class M {} |
| 5183 // abstract class C = B with M | 858 // abstract class C = B with M |
| 5184 ElementHolder holder = new ElementHolder(); | 859 ElementHolder holder = new ElementHolder(); |
| 5185 ElementBuilder builder = new ElementBuilder(holder); | 860 ElementBuilder builder = _makeBuilder(holder); |
| 5186 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 861 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
| 5187 ConstructorElementImpl constructorB = | 862 ConstructorElementImpl constructorB = |
| 5188 ElementFactory.constructorElement2(classB, '', []); | 863 ElementFactory.constructorElement2(classB, '', []); |
| 5189 constructorB.setModifier(Modifier.SYNTHETIC, true); | 864 constructorB.setModifier(Modifier.SYNTHETIC, true); |
| 5190 classB.constructors = [constructorB]; | 865 classB.constructors = [constructorB]; |
| 5191 ClassElement classM = ElementFactory.classElement2('M', []); | 866 ClassElement classM = ElementFactory.classElement2('M', []); |
| 5192 WithClause withClause = | 867 WithClause withClause = |
| 5193 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 868 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
| 5194 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', null, | 869 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', null, |
| 5195 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null); | 870 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null); |
| 5196 classCAst.accept(builder); | 871 classCAst.accept(builder); |
| 5197 List<ClassElement> types = holder.types; | 872 List<ClassElement> types = holder.types; |
| 5198 expect(types, hasLength(1)); | 873 expect(types, hasLength(1)); |
| 5199 ClassElement type = types[0]; | 874 ClassElement type = types[0]; |
| 5200 expect(type.isAbstract, isTrue); | 875 expect(type.isAbstract, isTrue); |
| 5201 expect(type.isMixinApplication, isTrue); | 876 expect(type.isMixinApplication, isTrue); |
| 5202 } | 877 } |
| 5203 | 878 |
| 5204 void test_visitClassTypeAlias_typeParams() { | 879 void test_visitClassTypeAlias_typeParams() { |
| 5205 // class B {} | 880 // class B {} |
| 5206 // class M {} | 881 // class M {} |
| 5207 // class C<T> = B with M | 882 // class C<T> = B with M |
| 5208 ElementHolder holder = new ElementHolder(); | 883 ElementHolder holder = new ElementHolder(); |
| 5209 ElementBuilder builder = new ElementBuilder(holder); | 884 ElementBuilder builder = _makeBuilder(holder); |
| 5210 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 885 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
| 5211 ConstructorElementImpl constructorB = | 886 ConstructorElementImpl constructorB = |
| 5212 ElementFactory.constructorElement2(classB, '', []); | 887 ElementFactory.constructorElement2(classB, '', []); |
| 5213 constructorB.setModifier(Modifier.SYNTHETIC, true); | 888 constructorB.setModifier(Modifier.SYNTHETIC, true); |
| 5214 classB.constructors = [constructorB]; | 889 classB.constructors = [constructorB]; |
| 5215 ClassElementImpl classM = ElementFactory.classElement2('M', []); | 890 ClassElementImpl classM = ElementFactory.classElement2('M', []); |
| 5216 WithClause withClause = | 891 WithClause withClause = |
| 5217 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 892 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
| 5218 ClassTypeAlias classCAst = AstFactory.classTypeAlias( | 893 ClassTypeAlias classCAst = AstFactory.classTypeAlias( |
| 5219 'C', | 894 'C', |
| 5220 AstFactory.typeParameterList(['T']), | 895 AstFactory.typeParameterList(['T']), |
| 5221 null, | 896 null, |
| 5222 AstFactory.typeName(classB, []), | 897 AstFactory.typeName(classB, []), |
| 5223 withClause, | 898 withClause, |
| 5224 null); | 899 null); |
| 5225 classCAst.accept(builder); | 900 classCAst.accept(builder); |
| 5226 List<ClassElement> types = holder.types; | 901 List<ClassElement> types = holder.types; |
| 5227 expect(types, hasLength(1)); | 902 expect(types, hasLength(1)); |
| 5228 ClassElement type = types[0]; | 903 ClassElement type = types[0]; |
| 5229 expect(type.typeParameters, hasLength(1)); | 904 expect(type.typeParameters, hasLength(1)); |
| 5230 expect(type.typeParameters[0].name, equals('T')); | 905 expect(type.typeParameters[0].name, equals('T')); |
| 5231 } | 906 } |
| 5232 | 907 |
| 908 void test_visitCompilationUnit_codeRange() { |
| 909 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory |
| 910 .topLevelVariableDeclaration(null, AstFactory.typeName4('int'), |
| 911 [AstFactory.variableDeclaration('V')]); |
| 912 CompilationUnit unit = new CompilationUnit( |
| 913 topLevelVariableDeclaration.beginToken, |
| 914 null, |
| 915 [], |
| 916 [topLevelVariableDeclaration], |
| 917 topLevelVariableDeclaration.endToken); |
| 918 ElementHolder holder = new ElementHolder(); |
| 919 ElementBuilder builder = _makeBuilder(holder); |
| 920 unit.beginToken.offset = 10; |
| 921 unit.endToken.offset = 40; |
| 922 unit.accept(builder); |
| 923 |
| 924 CompilationUnitElement element = builder.compilationUnitElement; |
| 925 _assertHasCodeRange(element, 0, 41); |
| 926 } |
| 927 |
| 5233 void test_visitConstructorDeclaration_external() { | 928 void test_visitConstructorDeclaration_external() { |
| 5234 ElementHolder holder = new ElementHolder(); | 929 ElementHolder holder = new ElementHolder(); |
| 5235 ElementBuilder builder = new ElementBuilder(holder); | 930 ElementBuilder builder = _makeBuilder(holder); |
| 5236 String className = "A"; | 931 String className = "A"; |
| 5237 ConstructorDeclaration constructorDeclaration = AstFactory | 932 ConstructorDeclaration constructorDeclaration = |
| 5238 .constructorDeclaration2( | 933 AstFactory.constructorDeclaration2( |
| 5239 null, | 934 null, |
| 5240 null, | 935 null, |
| 5241 AstFactory.identifier3(className), | 936 AstFactory.identifier3(className), |
| 5242 null, | 937 null, |
| 5243 AstFactory.formalParameterList(), | 938 AstFactory.formalParameterList(), |
| 5244 null, | 939 null, |
| 5245 AstFactory.blockFunctionBody2()); | 940 AstFactory.blockFunctionBody2()); |
| 5246 constructorDeclaration.externalKeyword = | 941 constructorDeclaration.externalKeyword = |
| 5247 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 942 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 5248 constructorDeclaration.accept(builder); | 943 constructorDeclaration.accept(builder); |
| 5249 List<ConstructorElement> constructors = holder.constructors; | 944 List<ConstructorElement> constructors = holder.constructors; |
| 5250 expect(constructors, hasLength(1)); | 945 expect(constructors, hasLength(1)); |
| 5251 ConstructorElement constructor = constructors[0]; | 946 ConstructorElement constructor = constructors[0]; |
| 5252 expect(constructor, isNotNull); | 947 expect(constructor, isNotNull); |
| 5253 expect(constructor.isExternal, isTrue); | 948 expect(constructor.isExternal, isTrue); |
| 5254 expect(constructor.isFactory, isFalse); | 949 expect(constructor.isFactory, isFalse); |
| 5255 expect(constructor.name, ""); | 950 expect(constructor.name, ""); |
| 5256 expect(constructor.functions, hasLength(0)); | 951 expect(constructor.functions, hasLength(0)); |
| 5257 expect(constructor.labels, hasLength(0)); | 952 expect(constructor.labels, hasLength(0)); |
| 5258 expect(constructor.localVariables, hasLength(0)); | 953 expect(constructor.localVariables, hasLength(0)); |
| 5259 expect(constructor.parameters, hasLength(0)); | 954 expect(constructor.parameters, hasLength(0)); |
| 5260 } | 955 } |
| 5261 | 956 |
| 5262 void test_visitConstructorDeclaration_factory() { | 957 void test_visitConstructorDeclaration_factory() { |
| 5263 ElementHolder holder = new ElementHolder(); | 958 ElementHolder holder = new ElementHolder(); |
| 5264 ElementBuilder builder = new ElementBuilder(holder); | 959 ElementBuilder builder = _makeBuilder(holder); |
| 5265 String className = "A"; | 960 String className = "A"; |
| 5266 ConstructorDeclaration constructorDeclaration = AstFactory | 961 ConstructorDeclaration constructorDeclaration = |
| 5267 .constructorDeclaration2( | 962 AstFactory.constructorDeclaration2( |
| 5268 null, | 963 null, |
| 5269 Keyword.FACTORY, | 964 Keyword.FACTORY, |
| 5270 AstFactory.identifier3(className), | 965 AstFactory.identifier3(className), |
| 5271 null, | 966 null, |
| 5272 AstFactory.formalParameterList(), | 967 AstFactory.formalParameterList(), |
| 5273 null, | 968 null, |
| 5274 AstFactory.blockFunctionBody2()); | 969 AstFactory.blockFunctionBody2()); |
| 5275 constructorDeclaration.accept(builder); | 970 constructorDeclaration.accept(builder); |
| 5276 List<ConstructorElement> constructors = holder.constructors; | 971 List<ConstructorElement> constructors = holder.constructors; |
| 5277 expect(constructors, hasLength(1)); | 972 expect(constructors, hasLength(1)); |
| 5278 ConstructorElement constructor = constructors[0]; | 973 ConstructorElement constructor = constructors[0]; |
| 5279 expect(constructor, isNotNull); | 974 expect(constructor, isNotNull); |
| 5280 expect(constructor.isExternal, isFalse); | 975 expect(constructor.isExternal, isFalse); |
| 5281 expect(constructor.isFactory, isTrue); | 976 expect(constructor.isFactory, isTrue); |
| 5282 expect(constructor.name, ""); | 977 expect(constructor.name, ""); |
| 5283 expect(constructor.functions, hasLength(0)); | 978 expect(constructor.functions, hasLength(0)); |
| 5284 expect(constructor.labels, hasLength(0)); | 979 expect(constructor.labels, hasLength(0)); |
| 5285 expect(constructor.localVariables, hasLength(0)); | 980 expect(constructor.localVariables, hasLength(0)); |
| 5286 expect(constructor.parameters, hasLength(0)); | 981 expect(constructor.parameters, hasLength(0)); |
| 5287 } | 982 } |
| 5288 | 983 |
| 5289 void test_visitConstructorDeclaration_minimal() { | 984 void test_visitConstructorDeclaration_minimal() { |
| 5290 ElementHolder holder = new ElementHolder(); | 985 ElementHolder holder = new ElementHolder(); |
| 5291 ElementBuilder builder = new ElementBuilder(holder); | 986 ElementBuilder builder = _makeBuilder(holder); |
| 5292 String className = "A"; | 987 String className = "A"; |
| 5293 ConstructorDeclaration constructorDeclaration = AstFactory | 988 ConstructorDeclaration constructorDeclaration = |
| 5294 .constructorDeclaration2( | 989 AstFactory.constructorDeclaration2( |
| 5295 null, | 990 null, |
| 5296 null, | 991 null, |
| 5297 AstFactory.identifier3(className), | 992 AstFactory.identifier3(className), |
| 5298 null, | 993 null, |
| 5299 AstFactory.formalParameterList(), | 994 AstFactory.formalParameterList(), |
| 5300 null, | 995 null, |
| 5301 AstFactory.blockFunctionBody2()); | 996 AstFactory.blockFunctionBody2()); |
| 5302 constructorDeclaration.documentationComment = AstFactory | 997 constructorDeclaration.documentationComment = AstFactory |
| 5303 .documentationComment( | 998 .documentationComment( |
| 5304 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 999 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1000 constructorDeclaration.endToken.offset = 80; |
| 5305 constructorDeclaration.accept(builder); | 1001 constructorDeclaration.accept(builder); |
| 5306 | 1002 |
| 5307 List<ConstructorElement> constructors = holder.constructors; | 1003 List<ConstructorElement> constructors = holder.constructors; |
| 5308 expect(constructors, hasLength(1)); | 1004 expect(constructors, hasLength(1)); |
| 5309 ConstructorElement constructor = constructors[0]; | 1005 ConstructorElement constructor = constructors[0]; |
| 5310 expect(constructor, isNotNull); | 1006 expect(constructor, isNotNull); |
| 5311 _assertHasDocRange(constructor, 50, 7); | 1007 _assertHasCodeRange(constructor, 50, 31); |
| 1008 expect(constructor.documentationComment, '/// aaa'); |
| 5312 expect(constructor.isExternal, isFalse); | 1009 expect(constructor.isExternal, isFalse); |
| 5313 expect(constructor.isFactory, isFalse); | 1010 expect(constructor.isFactory, isFalse); |
| 5314 expect(constructor.name, ""); | 1011 expect(constructor.name, ""); |
| 5315 expect(constructor.functions, hasLength(0)); | 1012 expect(constructor.functions, hasLength(0)); |
| 5316 expect(constructor.labels, hasLength(0)); | 1013 expect(constructor.labels, hasLength(0)); |
| 5317 expect(constructor.localVariables, hasLength(0)); | 1014 expect(constructor.localVariables, hasLength(0)); |
| 5318 expect(constructor.parameters, hasLength(0)); | 1015 expect(constructor.parameters, hasLength(0)); |
| 5319 } | 1016 } |
| 5320 | 1017 |
| 5321 void test_visitConstructorDeclaration_named() { | 1018 void test_visitConstructorDeclaration_named() { |
| 5322 ElementHolder holder = new ElementHolder(); | 1019 ElementHolder holder = new ElementHolder(); |
| 5323 ElementBuilder builder = new ElementBuilder(holder); | 1020 ElementBuilder builder = _makeBuilder(holder); |
| 5324 String className = "A"; | 1021 String className = "A"; |
| 5325 String constructorName = "c"; | 1022 String constructorName = "c"; |
| 5326 ConstructorDeclaration constructorDeclaration = AstFactory | 1023 ConstructorDeclaration constructorDeclaration = |
| 5327 .constructorDeclaration2( | 1024 AstFactory.constructorDeclaration2( |
| 5328 null, | 1025 null, |
| 5329 null, | 1026 null, |
| 5330 AstFactory.identifier3(className), | 1027 AstFactory.identifier3(className), |
| 5331 constructorName, | 1028 constructorName, |
| 5332 AstFactory.formalParameterList(), | 1029 AstFactory.formalParameterList(), |
| 5333 null, | 1030 null, |
| 5334 AstFactory.blockFunctionBody2()); | 1031 AstFactory.blockFunctionBody2()); |
| 5335 constructorDeclaration.accept(builder); | 1032 constructorDeclaration.accept(builder); |
| 5336 List<ConstructorElement> constructors = holder.constructors; | 1033 List<ConstructorElement> constructors = holder.constructors; |
| 5337 expect(constructors, hasLength(1)); | 1034 expect(constructors, hasLength(1)); |
| 5338 ConstructorElement constructor = constructors[0]; | 1035 ConstructorElement constructor = constructors[0]; |
| 5339 expect(constructor, isNotNull); | 1036 expect(constructor, isNotNull); |
| 5340 expect(constructor.isExternal, isFalse); | 1037 expect(constructor.isExternal, isFalse); |
| 5341 expect(constructor.isFactory, isFalse); | 1038 expect(constructor.isFactory, isFalse); |
| 5342 expect(constructor.name, constructorName); | 1039 expect(constructor.name, constructorName); |
| 5343 expect(constructor.functions, hasLength(0)); | 1040 expect(constructor.functions, hasLength(0)); |
| 5344 expect(constructor.labels, hasLength(0)); | 1041 expect(constructor.labels, hasLength(0)); |
| 5345 expect(constructor.localVariables, hasLength(0)); | 1042 expect(constructor.localVariables, hasLength(0)); |
| 5346 expect(constructor.parameters, hasLength(0)); | 1043 expect(constructor.parameters, hasLength(0)); |
| 5347 expect(constructorDeclaration.name.staticElement, same(constructor)); | 1044 expect(constructorDeclaration.name.staticElement, same(constructor)); |
| 5348 expect(constructorDeclaration.element, same(constructor)); | 1045 expect(constructorDeclaration.element, same(constructor)); |
| 5349 } | 1046 } |
| 5350 | 1047 |
| 5351 void test_visitConstructorDeclaration_unnamed() { | 1048 void test_visitConstructorDeclaration_unnamed() { |
| 5352 ElementHolder holder = new ElementHolder(); | 1049 ElementHolder holder = new ElementHolder(); |
| 5353 ElementBuilder builder = new ElementBuilder(holder); | 1050 ElementBuilder builder = _makeBuilder(holder); |
| 5354 String className = "A"; | 1051 String className = "A"; |
| 5355 ConstructorDeclaration constructorDeclaration = AstFactory | 1052 ConstructorDeclaration constructorDeclaration = |
| 5356 .constructorDeclaration2( | 1053 AstFactory.constructorDeclaration2( |
| 5357 null, | 1054 null, |
| 5358 null, | 1055 null, |
| 5359 AstFactory.identifier3(className), | 1056 AstFactory.identifier3(className), |
| 5360 null, | 1057 null, |
| 5361 AstFactory.formalParameterList(), | 1058 AstFactory.formalParameterList(), |
| 5362 null, | 1059 null, |
| 5363 AstFactory.blockFunctionBody2()); | 1060 AstFactory.blockFunctionBody2()); |
| 5364 constructorDeclaration.accept(builder); | 1061 constructorDeclaration.accept(builder); |
| 5365 List<ConstructorElement> constructors = holder.constructors; | 1062 List<ConstructorElement> constructors = holder.constructors; |
| 5366 expect(constructors, hasLength(1)); | 1063 expect(constructors, hasLength(1)); |
| 5367 ConstructorElement constructor = constructors[0]; | 1064 ConstructorElement constructor = constructors[0]; |
| 5368 expect(constructor, isNotNull); | 1065 expect(constructor, isNotNull); |
| 5369 expect(constructor.isExternal, isFalse); | 1066 expect(constructor.isExternal, isFalse); |
| 5370 expect(constructor.isFactory, isFalse); | 1067 expect(constructor.isFactory, isFalse); |
| 5371 expect(constructor.name, ""); | 1068 expect(constructor.name, ""); |
| 5372 expect(constructor.functions, hasLength(0)); | 1069 expect(constructor.functions, hasLength(0)); |
| 5373 expect(constructor.labels, hasLength(0)); | 1070 expect(constructor.labels, hasLength(0)); |
| 5374 expect(constructor.localVariables, hasLength(0)); | 1071 expect(constructor.localVariables, hasLength(0)); |
| 5375 expect(constructor.parameters, hasLength(0)); | 1072 expect(constructor.parameters, hasLength(0)); |
| 5376 expect(constructorDeclaration.element, same(constructor)); | 1073 expect(constructorDeclaration.element, same(constructor)); |
| 5377 } | 1074 } |
| 5378 | 1075 |
| 5379 void test_visitDeclaredIdentifier_noType() { | 1076 void test_visitDeclaredIdentifier_noType() { |
| 5380 // var i | 1077 // var i |
| 5381 ElementHolder holder = new ElementHolder(); | 1078 ElementHolder holder = new ElementHolder(); |
| 5382 ElementBuilder builder = new ElementBuilder(holder); | 1079 ElementBuilder builder = _makeBuilder(holder); |
| 5383 var variableName = 'i'; | 1080 var variableName = 'i'; |
| 5384 DeclaredIdentifier identifier = | 1081 DeclaredIdentifier identifier = |
| 5385 AstFactory.declaredIdentifier3(variableName); | 1082 AstFactory.declaredIdentifier3(variableName); |
| 5386 AstFactory.forEachStatement( | 1083 AstFactory.forEachStatement( |
| 5387 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); | 1084 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); |
| 1085 identifier.beginToken.offset = 50; |
| 1086 identifier.endToken.offset = 80; |
| 5388 identifier.accept(builder); | 1087 identifier.accept(builder); |
| 5389 | 1088 |
| 5390 List<LocalVariableElement> variables = holder.localVariables; | 1089 List<LocalVariableElement> variables = holder.localVariables; |
| 5391 expect(variables, hasLength(1)); | 1090 expect(variables, hasLength(1)); |
| 5392 LocalVariableElement variable = variables[0]; | 1091 LocalVariableElement variable = variables[0]; |
| 1092 _assertHasCodeRange(variable, 50, 31); |
| 5393 expect(variable, isNotNull); | 1093 expect(variable, isNotNull); |
| 5394 expect(variable.hasImplicitType, isTrue); | 1094 expect(variable.hasImplicitType, isTrue); |
| 5395 expect(variable.isConst, isFalse); | 1095 expect(variable.isConst, isFalse); |
| 5396 expect(variable.isDeprecated, isFalse); | 1096 expect(variable.isDeprecated, isFalse); |
| 5397 expect(variable.isFinal, isFalse); | 1097 expect(variable.isFinal, isFalse); |
| 5398 expect(variable.isOverride, isFalse); | 1098 expect(variable.isOverride, isFalse); |
| 5399 expect(variable.isPrivate, isFalse); | 1099 expect(variable.isPrivate, isFalse); |
| 5400 expect(variable.isPublic, isTrue); | 1100 expect(variable.isPublic, isTrue); |
| 5401 expect(variable.isSynthetic, isFalse); | 1101 expect(variable.isSynthetic, isFalse); |
| 5402 expect(variable.name, variableName); | 1102 expect(variable.name, variableName); |
| 5403 } | 1103 } |
| 5404 | 1104 |
| 5405 void test_visitDeclaredIdentifier_type() { | 1105 void test_visitDeclaredIdentifier_type() { |
| 5406 // E i | 1106 // E i |
| 5407 ElementHolder holder = new ElementHolder(); | 1107 ElementHolder holder = new ElementHolder(); |
| 5408 ElementBuilder builder = new ElementBuilder(holder); | 1108 ElementBuilder builder = _makeBuilder(holder); |
| 5409 var variableName = 'i'; | 1109 var variableName = 'i'; |
| 5410 DeclaredIdentifier identifier = | 1110 DeclaredIdentifier identifier = |
| 5411 AstFactory.declaredIdentifier4(AstFactory.typeName4('E'), variableName); | 1111 AstFactory.declaredIdentifier4(AstFactory.typeName4('E'), variableName); |
| 5412 AstFactory.forEachStatement( | 1112 AstFactory.forEachStatement( |
| 5413 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); | 1113 identifier, AstFactory.nullLiteral(), AstFactory.emptyStatement()); |
| 1114 identifier.beginToken.offset = 50; |
| 1115 identifier.endToken.offset = 80; |
| 5414 identifier.accept(builder); | 1116 identifier.accept(builder); |
| 5415 | 1117 |
| 5416 List<LocalVariableElement> variables = holder.localVariables; | 1118 List<LocalVariableElement> variables = holder.localVariables; |
| 5417 expect(variables, hasLength(1)); | 1119 expect(variables, hasLength(1)); |
| 5418 LocalVariableElement variable = variables[0]; | 1120 LocalVariableElement variable = variables[0]; |
| 5419 expect(variable, isNotNull); | 1121 expect(variable, isNotNull); |
| 1122 _assertHasCodeRange(variable, 50, 31); |
| 5420 expect(variable.hasImplicitType, isFalse); | 1123 expect(variable.hasImplicitType, isFalse); |
| 5421 expect(variable.isConst, isFalse); | 1124 expect(variable.isConst, isFalse); |
| 5422 expect(variable.isDeprecated, isFalse); | 1125 expect(variable.isDeprecated, isFalse); |
| 5423 expect(variable.isFinal, isFalse); | 1126 expect(variable.isFinal, isFalse); |
| 5424 expect(variable.isOverride, isFalse); | 1127 expect(variable.isOverride, isFalse); |
| 5425 expect(variable.isPrivate, isFalse); | 1128 expect(variable.isPrivate, isFalse); |
| 5426 expect(variable.isPublic, isTrue); | 1129 expect(variable.isPublic, isTrue); |
| 5427 expect(variable.isSynthetic, isFalse); | 1130 expect(variable.isSynthetic, isFalse); |
| 5428 expect(variable.name, variableName); | 1131 expect(variable.name, variableName); |
| 5429 } | 1132 } |
| 5430 | 1133 |
| 5431 void test_visitDefaultFormalParameter_noType() { | 1134 void test_visitDefaultFormalParameter_noType() { |
| 5432 // p = 0 | 1135 // p = 0 |
| 5433 ElementHolder holder = new ElementHolder(); | 1136 ElementHolder holder = new ElementHolder(); |
| 5434 ElementBuilder builder = new ElementBuilder(holder); | 1137 ElementBuilder builder = _makeBuilder(holder); |
| 5435 String parameterName = 'p'; | 1138 String parameterName = 'p'; |
| 5436 DefaultFormalParameter formalParameter = AstFactory | 1139 DefaultFormalParameter formalParameter = |
| 5437 .positionalFormalParameter( | 1140 AstFactory.positionalFormalParameter( |
| 5438 AstFactory.simpleFormalParameter3(parameterName), | 1141 AstFactory.simpleFormalParameter3(parameterName), |
| 5439 AstFactory.integer(0)); | 1142 AstFactory.integer(0)); |
| 1143 formalParameter.beginToken.offset = 50; |
| 1144 formalParameter.endToken.offset = 80; |
| 5440 formalParameter.accept(builder); | 1145 formalParameter.accept(builder); |
| 5441 | 1146 |
| 5442 List<ParameterElement> parameters = holder.parameters; | 1147 List<ParameterElement> parameters = holder.parameters; |
| 5443 expect(parameters, hasLength(1)); | 1148 expect(parameters, hasLength(1)); |
| 5444 ParameterElement parameter = parameters[0]; | 1149 ParameterElement parameter = parameters[0]; |
| 1150 _assertHasCodeRange(parameter, 50, 31); |
| 5445 expect(parameter.hasImplicitType, isTrue); | 1151 expect(parameter.hasImplicitType, isTrue); |
| 1152 expect(parameter.initializer, isNotNull); |
| 1153 expect(parameter.initializer.type, isNotNull); |
| 1154 expect(parameter.initializer.hasImplicitReturnType, isTrue); |
| 5446 expect(parameter.isConst, isFalse); | 1155 expect(parameter.isConst, isFalse); |
| 5447 expect(parameter.isDeprecated, isFalse); | 1156 expect(parameter.isDeprecated, isFalse); |
| 5448 expect(parameter.isFinal, isFalse); | 1157 expect(parameter.isFinal, isFalse); |
| 5449 expect(parameter.isInitializingFormal, isFalse); | 1158 expect(parameter.isInitializingFormal, isFalse); |
| 5450 expect(parameter.isOverride, isFalse); | 1159 expect(parameter.isOverride, isFalse); |
| 5451 expect(parameter.isPrivate, isFalse); | 1160 expect(parameter.isPrivate, isFalse); |
| 5452 expect(parameter.isPublic, isTrue); | 1161 expect(parameter.isPublic, isTrue); |
| 5453 expect(parameter.isSynthetic, isFalse); | 1162 expect(parameter.isSynthetic, isFalse); |
| 5454 expect(parameter.name, parameterName); | 1163 expect(parameter.name, parameterName); |
| 5455 } | 1164 } |
| 5456 | 1165 |
| 5457 void test_visitDefaultFormalParameter_type() { | 1166 void test_visitDefaultFormalParameter_type() { |
| 5458 // E p = 0 | 1167 // E p = 0 |
| 5459 ElementHolder holder = new ElementHolder(); | 1168 ElementHolder holder = new ElementHolder(); |
| 5460 ElementBuilder builder = new ElementBuilder(holder); | 1169 ElementBuilder builder = _makeBuilder(holder); |
| 5461 String parameterName = 'p'; | 1170 String parameterName = 'p'; |
| 5462 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( | 1171 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( |
| 5463 AstFactory.simpleFormalParameter4( | 1172 AstFactory.simpleFormalParameter4( |
| 5464 AstFactory.typeName4('E'), parameterName), | 1173 AstFactory.typeName4('E'), parameterName), |
| 5465 AstFactory.integer(0)); | 1174 AstFactory.integer(0)); |
| 5466 formalParameter.accept(builder); | 1175 formalParameter.accept(builder); |
| 5467 | 1176 |
| 5468 List<ParameterElement> parameters = holder.parameters; | 1177 List<ParameterElement> parameters = holder.parameters; |
| 5469 expect(parameters, hasLength(1)); | 1178 expect(parameters, hasLength(1)); |
| 5470 ParameterElement parameter = parameters[0]; | 1179 ParameterElement parameter = parameters[0]; |
| 5471 expect(parameter.hasImplicitType, isFalse); | 1180 expect(parameter.hasImplicitType, isFalse); |
| 1181 expect(parameter.initializer, isNotNull); |
| 1182 expect(parameter.initializer.type, isNotNull); |
| 1183 expect(parameter.initializer.hasImplicitReturnType, isTrue); |
| 5472 expect(parameter.isConst, isFalse); | 1184 expect(parameter.isConst, isFalse); |
| 5473 expect(parameter.isDeprecated, isFalse); | 1185 expect(parameter.isDeprecated, isFalse); |
| 5474 expect(parameter.isFinal, isFalse); | 1186 expect(parameter.isFinal, isFalse); |
| 5475 expect(parameter.isInitializingFormal, isFalse); | 1187 expect(parameter.isInitializingFormal, isFalse); |
| 5476 expect(parameter.isOverride, isFalse); | 1188 expect(parameter.isOverride, isFalse); |
| 5477 expect(parameter.isPrivate, isFalse); | 1189 expect(parameter.isPrivate, isFalse); |
| 5478 expect(parameter.isPublic, isTrue); | 1190 expect(parameter.isPublic, isTrue); |
| 5479 expect(parameter.isSynthetic, isFalse); | 1191 expect(parameter.isSynthetic, isFalse); |
| 5480 expect(parameter.name, parameterName); | 1192 expect(parameter.name, parameterName); |
| 5481 } | 1193 } |
| 5482 | 1194 |
| 5483 void test_visitEnumDeclaration() { | 1195 void test_visitEnumDeclaration() { |
| 5484 ElementHolder holder = new ElementHolder(); | 1196 ElementHolder holder = new ElementHolder(); |
| 5485 ElementBuilder builder = new ElementBuilder(holder); | 1197 ElementBuilder builder = _makeBuilder(holder); |
| 5486 String enumName = "E"; | 1198 String enumName = "E"; |
| 5487 EnumDeclaration enumDeclaration = | 1199 EnumDeclaration enumDeclaration = |
| 5488 AstFactory.enumDeclaration2(enumName, ["ONE"]); | 1200 AstFactory.enumDeclaration2(enumName, ["ONE"]); |
| 5489 enumDeclaration.documentationComment = AstFactory.documentationComment( | 1201 enumDeclaration.documentationComment = AstFactory.documentationComment( |
| 5490 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1202 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1203 enumDeclaration.endToken.offset = 80; |
| 5491 enumDeclaration.accept(builder); | 1204 enumDeclaration.accept(builder); |
| 5492 List<ClassElement> enums = holder.enums; | 1205 List<ClassElement> enums = holder.enums; |
| 5493 expect(enums, hasLength(1)); | 1206 expect(enums, hasLength(1)); |
| 5494 ClassElement enumElement = enums[0]; | 1207 ClassElement enumElement = enums[0]; |
| 5495 expect(enumElement, isNotNull); | 1208 expect(enumElement, isNotNull); |
| 5496 _assertHasDocRange(enumElement, 50, 7); | 1209 _assertHasCodeRange(enumElement, 50, 31); |
| 1210 expect(enumElement.documentationComment, '/// aaa'); |
| 5497 expect(enumElement.name, enumName); | 1211 expect(enumElement.name, enumName); |
| 5498 } | 1212 } |
| 5499 | 1213 |
| 5500 void test_visitFieldDeclaration() { | 1214 void test_visitFieldDeclaration() { |
| 5501 ElementHolder holder = new ElementHolder(); | 1215 ElementHolder holder = new ElementHolder(); |
| 5502 ElementBuilder builder = new ElementBuilder(holder); | 1216 ElementBuilder builder = _makeBuilder(holder); |
| 5503 String firstFieldName = "x"; | 1217 String firstFieldName = "x"; |
| 5504 String secondFieldName = "y"; | 1218 String secondFieldName = "y"; |
| 5505 FieldDeclaration fieldDeclaration = | 1219 FieldDeclaration fieldDeclaration = |
| 5506 AstFactory.fieldDeclaration2(false, null, [ | 1220 AstFactory.fieldDeclaration2(false, null, [ |
| 5507 AstFactory.variableDeclaration(firstFieldName), | 1221 AstFactory.variableDeclaration(firstFieldName), |
| 5508 AstFactory.variableDeclaration(secondFieldName) | 1222 AstFactory.variableDeclaration(secondFieldName) |
| 5509 ]); | 1223 ]); |
| 5510 fieldDeclaration.documentationComment = AstFactory.documentationComment( | 1224 fieldDeclaration.documentationComment = AstFactory.documentationComment( |
| 5511 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1225 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1226 fieldDeclaration.endToken.offset = 110; |
| 5512 fieldDeclaration.accept(builder); | 1227 fieldDeclaration.accept(builder); |
| 5513 | 1228 |
| 5514 List<FieldElement> fields = holder.fields; | 1229 List<FieldElement> fields = holder.fields; |
| 5515 expect(fields, hasLength(2)); | 1230 expect(fields, hasLength(2)); |
| 5516 | 1231 |
| 5517 FieldElement firstField = fields[0]; | 1232 FieldElement firstField = fields[0]; |
| 5518 expect(firstField, isNotNull); | 1233 expect(firstField, isNotNull); |
| 5519 _assertHasDocRange(firstField, 50, 7); | 1234 _assertHasCodeRange(firstField, 50, 61); |
| 1235 expect(firstField.documentationComment, '/// aaa'); |
| 5520 expect(firstField.name, firstFieldName); | 1236 expect(firstField.name, firstFieldName); |
| 5521 expect(firstField.initializer, isNull); | 1237 expect(firstField.initializer, isNull); |
| 5522 expect(firstField.isConst, isFalse); | 1238 expect(firstField.isConst, isFalse); |
| 5523 expect(firstField.isFinal, isFalse); | 1239 expect(firstField.isFinal, isFalse); |
| 5524 expect(firstField.isSynthetic, isFalse); | 1240 expect(firstField.isSynthetic, isFalse); |
| 5525 | 1241 |
| 5526 FieldElement secondField = fields[1]; | 1242 FieldElement secondField = fields[1]; |
| 5527 expect(secondField, isNotNull); | 1243 expect(secondField, isNotNull); |
| 5528 _assertHasDocRange(secondField, 50, 7); | 1244 _assertHasCodeRange(secondField, 50, 61); |
| 1245 expect(secondField.documentationComment, '/// aaa'); |
| 5529 expect(secondField.name, secondFieldName); | 1246 expect(secondField.name, secondFieldName); |
| 5530 expect(secondField.initializer, isNull); | 1247 expect(secondField.initializer, isNull); |
| 5531 expect(secondField.isConst, isFalse); | 1248 expect(secondField.isConst, isFalse); |
| 5532 expect(secondField.isFinal, isFalse); | 1249 expect(secondField.isFinal, isFalse); |
| 5533 expect(secondField.isSynthetic, isFalse); | 1250 expect(secondField.isSynthetic, isFalse); |
| 5534 } | 1251 } |
| 5535 | 1252 |
| 5536 void test_visitFieldFormalParameter() { | 1253 void test_visitFieldFormalParameter() { |
| 5537 ElementHolder holder = new ElementHolder(); | 1254 ElementHolder holder = new ElementHolder(); |
| 5538 ElementBuilder builder = new ElementBuilder(holder); | 1255 ElementBuilder builder = _makeBuilder(holder); |
| 5539 String parameterName = "p"; | 1256 String parameterName = "p"; |
| 5540 FieldFormalParameter formalParameter = | 1257 FieldFormalParameter formalParameter = |
| 5541 AstFactory.fieldFormalParameter(null, null, parameterName); | 1258 AstFactory.fieldFormalParameter(null, null, parameterName); |
| 1259 formalParameter.beginToken.offset = 50; |
| 1260 formalParameter.endToken.offset = 80; |
| 5542 formalParameter.accept(builder); | 1261 formalParameter.accept(builder); |
| 5543 List<ParameterElement> parameters = holder.parameters; | 1262 List<ParameterElement> parameters = holder.parameters; |
| 5544 expect(parameters, hasLength(1)); | 1263 expect(parameters, hasLength(1)); |
| 5545 ParameterElement parameter = parameters[0]; | 1264 ParameterElement parameter = parameters[0]; |
| 5546 expect(parameter, isNotNull); | 1265 expect(parameter, isNotNull); |
| 1266 _assertHasCodeRange(parameter, 50, 31); |
| 5547 expect(parameter.name, parameterName); | 1267 expect(parameter.name, parameterName); |
| 5548 expect(parameter.initializer, isNull); | 1268 expect(parameter.initializer, isNull); |
| 5549 expect(parameter.isConst, isFalse); | 1269 expect(parameter.isConst, isFalse); |
| 5550 expect(parameter.isFinal, isFalse); | 1270 expect(parameter.isFinal, isFalse); |
| 5551 expect(parameter.isSynthetic, isFalse); | 1271 expect(parameter.isSynthetic, isFalse); |
| 5552 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 1272 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 5553 expect(parameter.parameters, hasLength(0)); | 1273 expect(parameter.parameters, hasLength(0)); |
| 5554 } | 1274 } |
| 5555 | 1275 |
| 5556 void test_visitFieldFormalParameter_funtionTyped() { | 1276 void test_visitFieldFormalParameter_functionTyped() { |
| 5557 ElementHolder holder = new ElementHolder(); | 1277 ElementHolder holder = new ElementHolder(); |
| 5558 ElementBuilder builder = new ElementBuilder(holder); | 1278 ElementBuilder builder = _makeBuilder(holder); |
| 5559 String parameterName = "p"; | 1279 String parameterName = "p"; |
| 5560 FieldFormalParameter formalParameter = AstFactory.fieldFormalParameter( | 1280 FieldFormalParameter formalParameter = AstFactory.fieldFormalParameter( |
| 5561 null, | 1281 null, |
| 5562 null, | 1282 null, |
| 5563 parameterName, | 1283 parameterName, |
| 5564 AstFactory | 1284 AstFactory |
| 5565 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); | 1285 .formalParameterList([AstFactory.simpleFormalParameter3("a")])); |
| 5566 formalParameter.accept(builder); | 1286 formalParameter.accept(builder); |
| 5567 List<ParameterElement> parameters = holder.parameters; | 1287 List<ParameterElement> parameters = holder.parameters; |
| 5568 expect(parameters, hasLength(1)); | 1288 expect(parameters, hasLength(1)); |
| 5569 ParameterElement parameter = parameters[0]; | 1289 ParameterElement parameter = parameters[0]; |
| 5570 expect(parameter, isNotNull); | 1290 expect(parameter, isNotNull); |
| 5571 expect(parameter.name, parameterName); | 1291 expect(parameter.name, parameterName); |
| 5572 expect(parameter.initializer, isNull); | 1292 expect(parameter.initializer, isNull); |
| 5573 expect(parameter.isConst, isFalse); | 1293 expect(parameter.isConst, isFalse); |
| 5574 expect(parameter.isFinal, isFalse); | 1294 expect(parameter.isFinal, isFalse); |
| 5575 expect(parameter.isSynthetic, isFalse); | 1295 expect(parameter.isSynthetic, isFalse); |
| 5576 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 1296 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 5577 expect(parameter.parameters, hasLength(1)); | 1297 expect(parameter.parameters, hasLength(1)); |
| 5578 } | 1298 } |
| 5579 | 1299 |
| 5580 void test_visitFormalParameterList() { | 1300 void test_visitFormalParameterList() { |
| 5581 ElementHolder holder = new ElementHolder(); | 1301 ElementHolder holder = new ElementHolder(); |
| 5582 ElementBuilder builder = new ElementBuilder(holder); | 1302 ElementBuilder builder = _makeBuilder(holder); |
| 5583 String firstParameterName = "a"; | 1303 String firstParameterName = "a"; |
| 5584 String secondParameterName = "b"; | 1304 String secondParameterName = "b"; |
| 5585 FormalParameterList parameterList = AstFactory.formalParameterList([ | 1305 FormalParameterList parameterList = AstFactory.formalParameterList([ |
| 5586 AstFactory.simpleFormalParameter3(firstParameterName), | 1306 AstFactory.simpleFormalParameter3(firstParameterName), |
| 5587 AstFactory.simpleFormalParameter3(secondParameterName) | 1307 AstFactory.simpleFormalParameter3(secondParameterName) |
| 5588 ]); | 1308 ]); |
| 5589 parameterList.accept(builder); | 1309 parameterList.accept(builder); |
| 5590 List<ParameterElement> parameters = holder.parameters; | 1310 List<ParameterElement> parameters = holder.parameters; |
| 5591 expect(parameters, hasLength(2)); | 1311 expect(parameters, hasLength(2)); |
| 5592 expect(parameters[0].name, firstParameterName); | 1312 expect(parameters[0].name, firstParameterName); |
| 5593 expect(parameters[1].name, secondParameterName); | 1313 expect(parameters[1].name, secondParameterName); |
| 5594 } | 1314 } |
| 5595 | 1315 |
| 5596 void test_visitFunctionDeclaration_external() { | 1316 void test_visitFunctionDeclaration_external() { |
| 5597 // external f(); | 1317 // external f(); |
| 5598 ElementHolder holder = new ElementHolder(); | 1318 ElementHolder holder = new ElementHolder(); |
| 5599 ElementBuilder builder = new ElementBuilder(holder); | 1319 ElementBuilder builder = _makeBuilder(holder); |
| 5600 String functionName = "f"; | 1320 String functionName = "f"; |
| 5601 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 1321 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
| 5602 null, | 1322 null, |
| 5603 null, | 1323 null, |
| 5604 functionName, | 1324 functionName, |
| 5605 AstFactory.functionExpression2( | 1325 AstFactory.functionExpression2( |
| 5606 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); | 1326 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody())); |
| 5607 declaration.externalKeyword = | 1327 declaration.externalKeyword = |
| 5608 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 1328 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 5609 declaration.accept(builder); | 1329 declaration.accept(builder); |
| 5610 | 1330 |
| 5611 List<FunctionElement> functions = holder.functions; | 1331 List<FunctionElement> functions = holder.functions; |
| 5612 expect(functions, hasLength(1)); | 1332 expect(functions, hasLength(1)); |
| 5613 FunctionElement function = functions[0]; | 1333 FunctionElement function = functions[0]; |
| 5614 expect(function, isNotNull); | 1334 expect(function, isNotNull); |
| 5615 expect(function.name, functionName); | 1335 expect(function.name, functionName); |
| 5616 expect(declaration.element, same(function)); | 1336 expect(declaration.element, same(function)); |
| 5617 expect(declaration.functionExpression.element, same(function)); | 1337 expect(declaration.functionExpression.element, same(function)); |
| 5618 expect(function.hasImplicitReturnType, isTrue); | 1338 expect(function.hasImplicitReturnType, isTrue); |
| 5619 expect(function.isExternal, isTrue); | 1339 expect(function.isExternal, isTrue); |
| 5620 expect(function.isSynthetic, isFalse); | 1340 expect(function.isSynthetic, isFalse); |
| 5621 expect(function.typeParameters, hasLength(0)); | 1341 expect(function.typeParameters, hasLength(0)); |
| 5622 } | 1342 } |
| 5623 | 1343 |
| 5624 void test_visitFunctionDeclaration_getter() { | 1344 void test_visitFunctionDeclaration_getter() { |
| 5625 // get f() {} | 1345 // get f() {} |
| 5626 ElementHolder holder = new ElementHolder(); | 1346 ElementHolder holder = new ElementHolder(); |
| 5627 ElementBuilder builder = new ElementBuilder(holder); | 1347 ElementBuilder builder = _makeBuilder(holder); |
| 5628 String functionName = "f"; | 1348 String functionName = "f"; |
| 5629 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 1349 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
| 5630 null, | 1350 null, |
| 5631 Keyword.GET, | 1351 Keyword.GET, |
| 5632 functionName, | 1352 functionName, |
| 5633 AstFactory.functionExpression2( | 1353 AstFactory.functionExpression2( |
| 5634 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 1354 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
| 5635 declaration.documentationComment = AstFactory.documentationComment( | 1355 declaration.documentationComment = AstFactory.documentationComment( |
| 5636 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1356 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1357 declaration.endToken.offset = 80; |
| 5637 declaration.accept(builder); | 1358 declaration.accept(builder); |
| 5638 | 1359 |
| 5639 List<PropertyAccessorElement> accessors = holder.accessors; | 1360 List<PropertyAccessorElement> accessors = holder.accessors; |
| 5640 expect(accessors, hasLength(1)); | 1361 expect(accessors, hasLength(1)); |
| 5641 PropertyAccessorElement accessor = accessors[0]; | 1362 PropertyAccessorElement accessor = accessors[0]; |
| 5642 expect(accessor, isNotNull); | 1363 expect(accessor, isNotNull); |
| 5643 _assertHasDocRange(accessor, 50, 7); | 1364 _assertHasCodeRange(accessor, 50, 31); |
| 1365 expect(accessor.documentationComment, '/// aaa'); |
| 5644 expect(accessor.name, functionName); | 1366 expect(accessor.name, functionName); |
| 5645 expect(declaration.element, same(accessor)); | 1367 expect(declaration.element, same(accessor)); |
| 5646 expect(declaration.functionExpression.element, same(accessor)); | 1368 expect(declaration.functionExpression.element, same(accessor)); |
| 5647 expect(accessor.hasImplicitReturnType, isTrue); | 1369 expect(accessor.hasImplicitReturnType, isTrue); |
| 5648 expect(accessor.isGetter, isTrue); | 1370 expect(accessor.isGetter, isTrue); |
| 5649 expect(accessor.isExternal, isFalse); | 1371 expect(accessor.isExternal, isFalse); |
| 5650 expect(accessor.isSetter, isFalse); | 1372 expect(accessor.isSetter, isFalse); |
| 5651 expect(accessor.isSynthetic, isFalse); | 1373 expect(accessor.isSynthetic, isFalse); |
| 5652 expect(accessor.typeParameters, hasLength(0)); | 1374 expect(accessor.typeParameters, hasLength(0)); |
| 5653 PropertyInducingElement variable = accessor.variable; | 1375 PropertyInducingElement variable = accessor.variable; |
| 5654 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, | 1376 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, |
| 5655 TopLevelVariableElement, variable); | 1377 TopLevelVariableElement, variable); |
| 5656 expect(variable.isSynthetic, isTrue); | 1378 expect(variable.isSynthetic, isTrue); |
| 5657 } | 1379 } |
| 5658 | 1380 |
| 5659 void test_visitFunctionDeclaration_plain() { | 1381 void test_visitFunctionDeclaration_plain() { |
| 5660 // T f() {} | 1382 // T f() {} |
| 5661 ElementHolder holder = new ElementHolder(); | 1383 ElementHolder holder = new ElementHolder(); |
| 5662 ElementBuilder builder = new ElementBuilder(holder); | 1384 ElementBuilder builder = _makeBuilder(holder); |
| 5663 String functionName = "f"; | 1385 String functionName = "f"; |
| 5664 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 1386 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
| 5665 AstFactory.typeName4('T'), | 1387 AstFactory.typeName4('T'), |
| 5666 null, | 1388 null, |
| 5667 functionName, | 1389 functionName, |
| 5668 AstFactory.functionExpression2( | 1390 AstFactory.functionExpression2( |
| 5669 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 1391 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
| 5670 declaration.documentationComment = AstFactory.documentationComment( | 1392 declaration.documentationComment = AstFactory.documentationComment( |
| 5671 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1393 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1394 declaration.endToken.offset = 80; |
| 5672 declaration.accept(builder); | 1395 declaration.accept(builder); |
| 5673 | 1396 |
| 5674 List<FunctionElement> functions = holder.functions; | 1397 List<FunctionElement> functions = holder.functions; |
| 5675 expect(functions, hasLength(1)); | 1398 expect(functions, hasLength(1)); |
| 5676 FunctionElement function = functions[0]; | 1399 FunctionElement function = functions[0]; |
| 5677 expect(function, isNotNull); | 1400 expect(function, isNotNull); |
| 5678 _assertHasDocRange(function, 50, 7); | 1401 _assertHasCodeRange(function, 50, 31); |
| 1402 expect(function.documentationComment, '/// aaa'); |
| 5679 expect(function.hasImplicitReturnType, isFalse); | 1403 expect(function.hasImplicitReturnType, isFalse); |
| 5680 expect(function.name, functionName); | 1404 expect(function.name, functionName); |
| 5681 expect(declaration.element, same(function)); | 1405 expect(declaration.element, same(function)); |
| 5682 expect(declaration.functionExpression.element, same(function)); | 1406 expect(declaration.functionExpression.element, same(function)); |
| 5683 expect(function.isExternal, isFalse); | 1407 expect(function.isExternal, isFalse); |
| 5684 expect(function.isSynthetic, isFalse); | 1408 expect(function.isSynthetic, isFalse); |
| 5685 expect(function.typeParameters, hasLength(0)); | 1409 expect(function.typeParameters, hasLength(0)); |
| 5686 } | 1410 } |
| 5687 | 1411 |
| 5688 void test_visitFunctionDeclaration_setter() { | 1412 void test_visitFunctionDeclaration_setter() { |
| 5689 // set f() {} | 1413 // set f() {} |
| 5690 ElementHolder holder = new ElementHolder(); | 1414 ElementHolder holder = new ElementHolder(); |
| 5691 ElementBuilder builder = new ElementBuilder(holder); | 1415 ElementBuilder builder = _makeBuilder(holder); |
| 5692 String functionName = "f"; | 1416 String functionName = "f"; |
| 5693 FunctionDeclaration declaration = AstFactory.functionDeclaration( | 1417 FunctionDeclaration declaration = AstFactory.functionDeclaration( |
| 5694 null, | 1418 null, |
| 5695 Keyword.SET, | 1419 Keyword.SET, |
| 5696 functionName, | 1420 functionName, |
| 5697 AstFactory.functionExpression2( | 1421 AstFactory.functionExpression2( |
| 5698 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); | 1422 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2())); |
| 5699 declaration.documentationComment = AstFactory.documentationComment( | 1423 declaration.documentationComment = AstFactory.documentationComment( |
| 5700 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1424 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1425 declaration.endToken.offset = 80; |
| 5701 declaration.accept(builder); | 1426 declaration.accept(builder); |
| 5702 | 1427 |
| 5703 List<PropertyAccessorElement> accessors = holder.accessors; | 1428 List<PropertyAccessorElement> accessors = holder.accessors; |
| 5704 expect(accessors, hasLength(1)); | 1429 expect(accessors, hasLength(1)); |
| 5705 PropertyAccessorElement accessor = accessors[0]; | 1430 PropertyAccessorElement accessor = accessors[0]; |
| 5706 expect(accessor, isNotNull); | 1431 expect(accessor, isNotNull); |
| 5707 _assertHasDocRange(accessor, 50, 7); | 1432 _assertHasCodeRange(accessor, 50, 31); |
| 5708 expect(accessor.hasImplicitReturnType, isFalse); | 1433 expect(accessor.documentationComment, '/// aaa'); |
| 1434 expect(accessor.hasImplicitReturnType, isTrue); |
| 5709 expect(accessor.name, "$functionName="); | 1435 expect(accessor.name, "$functionName="); |
| 5710 expect(declaration.element, same(accessor)); | 1436 expect(declaration.element, same(accessor)); |
| 5711 expect(declaration.functionExpression.element, same(accessor)); | 1437 expect(declaration.functionExpression.element, same(accessor)); |
| 5712 expect(accessor.isGetter, isFalse); | 1438 expect(accessor.isGetter, isFalse); |
| 5713 expect(accessor.isExternal, isFalse); | 1439 expect(accessor.isExternal, isFalse); |
| 5714 expect(accessor.isSetter, isTrue); | 1440 expect(accessor.isSetter, isTrue); |
| 5715 expect(accessor.isSynthetic, isFalse); | 1441 expect(accessor.isSynthetic, isFalse); |
| 5716 expect(accessor.typeParameters, hasLength(0)); | 1442 expect(accessor.typeParameters, hasLength(0)); |
| 5717 PropertyInducingElement variable = accessor.variable; | 1443 PropertyInducingElement variable = accessor.variable; |
| 5718 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, | 1444 EngineTestCase.assertInstanceOf((obj) => obj is TopLevelVariableElement, |
| 5719 TopLevelVariableElement, variable); | 1445 TopLevelVariableElement, variable); |
| 5720 expect(variable.isSynthetic, isTrue); | 1446 expect(variable.isSynthetic, isTrue); |
| 5721 } | 1447 } |
| 5722 | 1448 |
| 5723 void test_visitFunctionDeclaration_typeParameters() { | 1449 void test_visitFunctionDeclaration_typeParameters() { |
| 5724 // f<E>() {} | 1450 // f<E>() {} |
| 5725 ElementHolder holder = new ElementHolder(); | 1451 ElementHolder holder = new ElementHolder(); |
| 5726 ElementBuilder builder = new ElementBuilder(holder); | 1452 ElementBuilder builder = _makeBuilder(holder); |
| 5727 String functionName = 'f'; | 1453 String functionName = 'f'; |
| 5728 String typeParameterName = 'E'; | 1454 String typeParameterName = 'E'; |
| 5729 FunctionExpression expression = AstFactory.functionExpression3( | 1455 FunctionExpression expression = AstFactory.functionExpression3( |
| 5730 AstFactory.typeParameterList([typeParameterName]), | 1456 AstFactory.typeParameterList([typeParameterName]), |
| 5731 AstFactory.formalParameterList(), | 1457 AstFactory.formalParameterList(), |
| 5732 AstFactory.blockFunctionBody2()); | 1458 AstFactory.blockFunctionBody2()); |
| 5733 FunctionDeclaration declaration = | 1459 FunctionDeclaration declaration = |
| 5734 AstFactory.functionDeclaration(null, null, functionName, expression); | 1460 AstFactory.functionDeclaration(null, null, functionName, expression); |
| 5735 declaration.accept(builder); | 1461 declaration.accept(builder); |
| 5736 | 1462 |
| 5737 List<FunctionElement> functions = holder.functions; | 1463 List<FunctionElement> functions = holder.functions; |
| 5738 expect(functions, hasLength(1)); | 1464 expect(functions, hasLength(1)); |
| 5739 FunctionElement function = functions[0]; | 1465 FunctionElement function = functions[0]; |
| 5740 expect(function, isNotNull); | 1466 expect(function, isNotNull); |
| 5741 expect(function.hasImplicitReturnType, isTrue); | 1467 expect(function.hasImplicitReturnType, isTrue); |
| 5742 expect(function.name, functionName); | 1468 expect(function.name, functionName); |
| 5743 expect(function.isExternal, isFalse); | 1469 expect(function.isExternal, isFalse); |
| 5744 expect(function.isSynthetic, isFalse); | 1470 expect(function.isSynthetic, isFalse); |
| 5745 expect(declaration.element, same(function)); | 1471 expect(declaration.element, same(function)); |
| 5746 expect(expression.element, same(function)); | 1472 expect(expression.element, same(function)); |
| 5747 List<TypeParameterElement> typeParameters = function.typeParameters; | 1473 List<TypeParameterElement> typeParameters = function.typeParameters; |
| 5748 expect(typeParameters, hasLength(1)); | 1474 expect(typeParameters, hasLength(1)); |
| 5749 TypeParameterElement typeParameter = typeParameters[0]; | 1475 TypeParameterElement typeParameter = typeParameters[0]; |
| 5750 expect(typeParameter, isNotNull); | 1476 expect(typeParameter, isNotNull); |
| 5751 expect(typeParameter.name, typeParameterName); | 1477 expect(typeParameter.name, typeParameterName); |
| 5752 } | 1478 } |
| 5753 | 1479 |
| 5754 void test_visitFunctionExpression() { | 1480 void test_visitFunctionExpression() { |
| 5755 ElementHolder holder = new ElementHolder(); | 1481 ElementHolder holder = new ElementHolder(); |
| 5756 ElementBuilder builder = new ElementBuilder(holder); | 1482 ElementBuilder builder = _makeBuilder(holder); |
| 5757 FunctionExpression expression = AstFactory.functionExpression2( | 1483 FunctionExpression expression = AstFactory.functionExpression2( |
| 5758 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); | 1484 AstFactory.formalParameterList(), AstFactory.blockFunctionBody2()); |
| 5759 expression.accept(builder); | 1485 expression.accept(builder); |
| 5760 List<FunctionElement> functions = holder.functions; | 1486 List<FunctionElement> functions = holder.functions; |
| 5761 expect(functions, hasLength(1)); | 1487 expect(functions, hasLength(1)); |
| 5762 FunctionElement function = functions[0]; | 1488 FunctionElement function = functions[0]; |
| 5763 expect(function, isNotNull); | 1489 expect(function, isNotNull); |
| 5764 expect(expression.element, same(function)); | 1490 expect(expression.element, same(function)); |
| 5765 expect(function.hasImplicitReturnType, isTrue); | 1491 expect(function.hasImplicitReturnType, isTrue); |
| 5766 expect(function.isSynthetic, isFalse); | 1492 expect(function.isSynthetic, isFalse); |
| 5767 expect(function.typeParameters, hasLength(0)); | 1493 expect(function.typeParameters, hasLength(0)); |
| 5768 } | 1494 } |
| 5769 | 1495 |
| 5770 void test_visitFunctionTypeAlias() { | 1496 void test_visitFunctionTypeAlias() { |
| 5771 ElementHolder holder = new ElementHolder(); | 1497 ElementHolder holder = new ElementHolder(); |
| 5772 ElementBuilder builder = new ElementBuilder(holder); | 1498 ElementBuilder builder = _makeBuilder(holder); |
| 5773 String aliasName = "F"; | 1499 String aliasName = "F"; |
| 5774 String parameterName = "E"; | 1500 String parameterName = "E"; |
| 5775 FunctionTypeAlias aliasNode = AstFactory.typeAlias( | 1501 FunctionTypeAlias aliasNode = AstFactory.typeAlias( |
| 5776 null, aliasName, AstFactory.typeParameterList([parameterName]), null); | 1502 null, aliasName, AstFactory.typeParameterList([parameterName]), null); |
| 5777 aliasNode.documentationComment = AstFactory.documentationComment( | 1503 aliasNode.documentationComment = AstFactory.documentationComment( |
| 5778 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1504 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1505 aliasNode.endToken.offset = 80; |
| 5779 aliasNode.accept(builder); | 1506 aliasNode.accept(builder); |
| 5780 | 1507 |
| 5781 List<FunctionTypeAliasElement> aliases = holder.typeAliases; | 1508 List<FunctionTypeAliasElement> aliases = holder.typeAliases; |
| 5782 expect(aliases, hasLength(1)); | 1509 expect(aliases, hasLength(1)); |
| 5783 FunctionTypeAliasElement alias = aliases[0]; | 1510 FunctionTypeAliasElement alias = aliases[0]; |
| 5784 expect(alias, isNotNull); | 1511 expect(alias, isNotNull); |
| 5785 _assertHasDocRange(alias, 50, 7); | 1512 _assertHasCodeRange(alias, 50, 31); |
| 1513 expect(alias.documentationComment, '/// aaa'); |
| 5786 expect(alias.name, aliasName); | 1514 expect(alias.name, aliasName); |
| 5787 expect(alias.parameters, hasLength(0)); | 1515 expect(alias.parameters, hasLength(0)); |
| 5788 List<TypeParameterElement> typeParameters = alias.typeParameters; | 1516 List<TypeParameterElement> typeParameters = alias.typeParameters; |
| 5789 expect(typeParameters, hasLength(1)); | 1517 expect(typeParameters, hasLength(1)); |
| 5790 TypeParameterElement typeParameter = typeParameters[0]; | 1518 TypeParameterElement typeParameter = typeParameters[0]; |
| 5791 expect(typeParameter, isNotNull); | 1519 expect(typeParameter, isNotNull); |
| 5792 expect(typeParameter.name, parameterName); | 1520 expect(typeParameter.name, parameterName); |
| 5793 } | 1521 } |
| 5794 | 1522 |
| 5795 void test_visitFunctionTypedFormalParameter() { | 1523 void test_visitFunctionTypedFormalParameter() { |
| 5796 ElementHolder holder = new ElementHolder(); | 1524 ElementHolder holder = new ElementHolder(); |
| 5797 ElementBuilder builder = new ElementBuilder(holder); | 1525 ElementBuilder builder = _makeBuilder(holder); |
| 5798 String parameterName = "p"; | 1526 String parameterName = "p"; |
| 5799 FunctionTypedFormalParameter formalParameter = | 1527 FunctionTypedFormalParameter formalParameter = |
| 5800 AstFactory.functionTypedFormalParameter(null, parameterName); | 1528 AstFactory.functionTypedFormalParameter(null, parameterName); |
| 5801 _useParameterInMethod(formalParameter, 100, 110); | 1529 _useParameterInMethod(formalParameter, 100, 110); |
| 5802 formalParameter.accept(builder); | 1530 formalParameter.accept(builder); |
| 5803 List<ParameterElement> parameters = holder.parameters; | 1531 List<ParameterElement> parameters = holder.parameters; |
| 5804 expect(parameters, hasLength(1)); | 1532 expect(parameters, hasLength(1)); |
| 5805 ParameterElement parameter = parameters[0]; | 1533 ParameterElement parameter = parameters[0]; |
| 5806 expect(parameter, isNotNull); | 1534 expect(parameter, isNotNull); |
| 5807 expect(parameter.name, parameterName); | 1535 expect(parameter.name, parameterName); |
| 5808 expect(parameter.initializer, isNull); | 1536 expect(parameter.initializer, isNull); |
| 5809 expect(parameter.isConst, isFalse); | 1537 expect(parameter.isConst, isFalse); |
| 5810 expect(parameter.isFinal, isFalse); | 1538 expect(parameter.isFinal, isFalse); |
| 5811 expect(parameter.isSynthetic, isFalse); | 1539 expect(parameter.isSynthetic, isFalse); |
| 5812 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 1540 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 5813 SourceRange visibleRange = parameter.visibleRange; | 1541 _assertVisibleRange(parameter, 100, 110); |
| 5814 expect(100, visibleRange.offset); | |
| 5815 expect(110, visibleRange.end); | |
| 5816 } | 1542 } |
| 5817 | 1543 |
| 5818 void test_visitFunctionTypedFormalParameter_withTypeParameters() { | 1544 void test_visitFunctionTypedFormalParameter_withTypeParameters() { |
| 5819 ElementHolder holder = new ElementHolder(); | 1545 ElementHolder holder = new ElementHolder(); |
| 5820 ElementBuilder builder = new ElementBuilder(holder); | 1546 ElementBuilder builder = _makeBuilder(holder); |
| 5821 String parameterName = "p"; | 1547 String parameterName = "p"; |
| 5822 FunctionTypedFormalParameter formalParameter = | 1548 FunctionTypedFormalParameter formalParameter = |
| 5823 AstFactory.functionTypedFormalParameter(null, parameterName); | 1549 AstFactory.functionTypedFormalParameter(null, parameterName); |
| 5824 formalParameter.typeParameters = AstFactory.typeParameterList(['F']); | 1550 formalParameter.typeParameters = AstFactory.typeParameterList(['F']); |
| 5825 _useParameterInMethod(formalParameter, 100, 110); | 1551 _useParameterInMethod(formalParameter, 100, 110); |
| 5826 formalParameter.accept(builder); | 1552 formalParameter.accept(builder); |
| 5827 List<ParameterElement> parameters = holder.parameters; | 1553 List<ParameterElement> parameters = holder.parameters; |
| 5828 expect(parameters, hasLength(1)); | 1554 expect(parameters, hasLength(1)); |
| 5829 ParameterElement parameter = parameters[0]; | 1555 ParameterElement parameter = parameters[0]; |
| 5830 expect(parameter, isNotNull); | 1556 expect(parameter, isNotNull); |
| 5831 expect(parameter.name, parameterName); | 1557 expect(parameter.name, parameterName); |
| 5832 expect(parameter.initializer, isNull); | 1558 expect(parameter.initializer, isNull); |
| 5833 expect(parameter.isConst, isFalse); | 1559 expect(parameter.isConst, isFalse); |
| 5834 expect(parameter.isFinal, isFalse); | 1560 expect(parameter.isFinal, isFalse); |
| 5835 expect(parameter.isSynthetic, isFalse); | 1561 expect(parameter.isSynthetic, isFalse); |
| 5836 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 1562 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 5837 expect(parameter.typeParameters, hasLength(1)); | 1563 expect(parameter.typeParameters, hasLength(1)); |
| 5838 SourceRange visibleRange = parameter.visibleRange; | 1564 _assertVisibleRange(parameter, 100, 110); |
| 5839 expect(100, visibleRange.offset); | |
| 5840 expect(110, visibleRange.end); | |
| 5841 } | 1565 } |
| 5842 | 1566 |
| 5843 void test_visitLabeledStatement() { | 1567 void test_visitLabeledStatement() { |
| 5844 ElementHolder holder = new ElementHolder(); | 1568 ElementHolder holder = new ElementHolder(); |
| 5845 ElementBuilder builder = new ElementBuilder(holder); | 1569 ElementBuilder builder = _makeBuilder(holder); |
| 5846 String labelName = "l"; | 1570 String labelName = "l"; |
| 5847 LabeledStatement statement = AstFactory.labeledStatement( | 1571 LabeledStatement statement = AstFactory.labeledStatement( |
| 5848 [AstFactory.label2(labelName)], AstFactory.breakStatement()); | 1572 [AstFactory.label2(labelName)], AstFactory.breakStatement()); |
| 5849 statement.accept(builder); | 1573 statement.accept(builder); |
| 5850 List<LabelElement> labels = holder.labels; | 1574 List<LabelElement> labels = holder.labels; |
| 5851 expect(labels, hasLength(1)); | 1575 expect(labels, hasLength(1)); |
| 5852 LabelElement label = labels[0]; | 1576 LabelElement label = labels[0]; |
| 5853 expect(label, isNotNull); | 1577 expect(label, isNotNull); |
| 5854 expect(label.name, labelName); | 1578 expect(label.name, labelName); |
| 5855 expect(label.isSynthetic, isFalse); | 1579 expect(label.isSynthetic, isFalse); |
| 5856 } | 1580 } |
| 5857 | 1581 |
| 5858 void test_visitMethodDeclaration_abstract() { | 1582 void test_visitMethodDeclaration_abstract() { |
| 5859 // m(); | 1583 // m(); |
| 5860 ElementHolder holder = new ElementHolder(); | 1584 ElementHolder holder = new ElementHolder(); |
| 5861 ElementBuilder builder = new ElementBuilder(holder); | 1585 ElementBuilder builder = _makeBuilder(holder); |
| 5862 String methodName = "m"; | 1586 String methodName = "m"; |
| 5863 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1587 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 5864 null, | 1588 null, |
| 5865 null, | 1589 null, |
| 5866 null, | 1590 null, |
| 5867 null, | 1591 null, |
| 5868 AstFactory.identifier3(methodName), | 1592 AstFactory.identifier3(methodName), |
| 5869 AstFactory.formalParameterList(), | 1593 AstFactory.formalParameterList(), |
| 5870 AstFactory.emptyFunctionBody()); | 1594 AstFactory.emptyFunctionBody()); |
| 5871 methodDeclaration.accept(builder); | 1595 methodDeclaration.accept(builder); |
| 5872 | 1596 |
| 5873 List<MethodElement> methods = holder.methods; | 1597 List<MethodElement> methods = holder.methods; |
| 5874 expect(methods, hasLength(1)); | 1598 expect(methods, hasLength(1)); |
| 5875 MethodElement method = methods[0]; | 1599 MethodElement method = methods[0]; |
| 5876 expect(method, isNotNull); | 1600 expect(method, isNotNull); |
| 5877 expect(method.hasImplicitReturnType, isTrue); | 1601 expect(method.hasImplicitReturnType, isTrue); |
| 5878 expect(method.name, methodName); | 1602 expect(method.name, methodName); |
| 5879 expect(method.functions, hasLength(0)); | 1603 expect(method.functions, hasLength(0)); |
| 5880 expect(method.labels, hasLength(0)); | 1604 expect(method.labels, hasLength(0)); |
| 5881 expect(method.localVariables, hasLength(0)); | 1605 expect(method.localVariables, hasLength(0)); |
| 5882 expect(method.parameters, hasLength(0)); | 1606 expect(method.parameters, hasLength(0)); |
| 5883 expect(method.typeParameters, hasLength(0)); | 1607 expect(method.typeParameters, hasLength(0)); |
| 5884 expect(method.isAbstract, isTrue); | 1608 expect(method.isAbstract, isTrue); |
| 5885 expect(method.isExternal, isFalse); | 1609 expect(method.isExternal, isFalse); |
| 5886 expect(method.isStatic, isFalse); | 1610 expect(method.isStatic, isFalse); |
| 5887 expect(method.isSynthetic, isFalse); | 1611 expect(method.isSynthetic, isFalse); |
| 5888 } | 1612 } |
| 5889 | 1613 |
| 1614 void test_visitMethodDeclaration_duplicateField_synthetic() { |
| 1615 buildElementsForText(r''' |
| 1616 class A { |
| 1617 int f; |
| 1618 int get f => 42; |
| 1619 } |
| 1620 '''); |
| 1621 ClassDeclaration classNode = compilationUnit.declarations.single; |
| 1622 // ClassElement |
| 1623 ClassElement classElement = classNode.element; |
| 1624 expect(classElement.fields, hasLength(2)); |
| 1625 expect(classElement.accessors, hasLength(3)); |
| 1626 FieldElement notSyntheticFieldElement = classElement.fields |
| 1627 .singleWhere((f) => f.displayName == 'f' && !f.isSynthetic); |
| 1628 FieldElement syntheticFieldElement = classElement.fields |
| 1629 .singleWhere((f) => f.displayName == 'f' && f.isSynthetic); |
| 1630 PropertyAccessorElement syntheticGetterElement = classElement.accessors |
| 1631 .singleWhere( |
| 1632 (a) => a.displayName == 'f' && a.isGetter && a.isSynthetic); |
| 1633 PropertyAccessorElement syntheticSetterElement = classElement.accessors |
| 1634 .singleWhere( |
| 1635 (a) => a.displayName == 'f' && a.isSetter && a.isSynthetic); |
| 1636 PropertyAccessorElement notSyntheticGetterElement = classElement.accessors |
| 1637 .singleWhere( |
| 1638 (a) => a.displayName == 'f' && a.isGetter && !a.isSynthetic); |
| 1639 expect(notSyntheticFieldElement.getter, same(syntheticGetterElement)); |
| 1640 expect(notSyntheticFieldElement.setter, same(syntheticSetterElement)); |
| 1641 expect(syntheticFieldElement.getter, same(notSyntheticGetterElement)); |
| 1642 expect(syntheticFieldElement.setter, isNull); |
| 1643 // class members nodes and their elements |
| 1644 FieldDeclaration fieldDeclNode = classNode.members[0]; |
| 1645 VariableDeclaration fieldNode = fieldDeclNode.fields.variables.single; |
| 1646 MethodDeclaration getterNode = classNode.members[1]; |
| 1647 expect(fieldNode.element, notSyntheticFieldElement); |
| 1648 expect(getterNode.element, notSyntheticGetterElement); |
| 1649 } |
| 1650 |
| 5890 void test_visitMethodDeclaration_external() { | 1651 void test_visitMethodDeclaration_external() { |
| 5891 // external m(); | 1652 // external m(); |
| 5892 ElementHolder holder = new ElementHolder(); | 1653 ElementHolder holder = new ElementHolder(); |
| 5893 ElementBuilder builder = new ElementBuilder(holder); | 1654 ElementBuilder builder = _makeBuilder(holder); |
| 5894 String methodName = "m"; | 1655 String methodName = "m"; |
| 5895 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1656 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 5896 null, | 1657 null, |
| 5897 null, | 1658 null, |
| 5898 null, | 1659 null, |
| 5899 null, | 1660 null, |
| 5900 AstFactory.identifier3(methodName), | 1661 AstFactory.identifier3(methodName), |
| 5901 AstFactory.formalParameterList(), | 1662 AstFactory.formalParameterList(), |
| 5902 AstFactory.emptyFunctionBody()); | 1663 AstFactory.emptyFunctionBody()); |
| 5903 methodDeclaration.externalKeyword = | 1664 methodDeclaration.externalKeyword = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5917 expect(method.typeParameters, hasLength(0)); | 1678 expect(method.typeParameters, hasLength(0)); |
| 5918 expect(method.isAbstract, isFalse); | 1679 expect(method.isAbstract, isFalse); |
| 5919 expect(method.isExternal, isTrue); | 1680 expect(method.isExternal, isTrue); |
| 5920 expect(method.isStatic, isFalse); | 1681 expect(method.isStatic, isFalse); |
| 5921 expect(method.isSynthetic, isFalse); | 1682 expect(method.isSynthetic, isFalse); |
| 5922 } | 1683 } |
| 5923 | 1684 |
| 5924 void test_visitMethodDeclaration_getter() { | 1685 void test_visitMethodDeclaration_getter() { |
| 5925 // get m() {} | 1686 // get m() {} |
| 5926 ElementHolder holder = new ElementHolder(); | 1687 ElementHolder holder = new ElementHolder(); |
| 5927 ElementBuilder builder = new ElementBuilder(holder); | 1688 ElementBuilder builder = _makeBuilder(holder); |
| 5928 String methodName = "m"; | 1689 String methodName = "m"; |
| 5929 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1690 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 5930 null, | 1691 null, |
| 5931 null, | 1692 null, |
| 5932 Keyword.GET, | 1693 Keyword.GET, |
| 5933 null, | 1694 null, |
| 5934 AstFactory.identifier3(methodName), | 1695 AstFactory.identifier3(methodName), |
| 5935 AstFactory.formalParameterList(), | 1696 AstFactory.formalParameterList(), |
| 5936 AstFactory.blockFunctionBody2()); | 1697 AstFactory.blockFunctionBody2()); |
| 5937 methodDeclaration.documentationComment = AstFactory.documentationComment( | 1698 methodDeclaration.documentationComment = AstFactory.documentationComment( |
| 5938 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1699 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1700 methodDeclaration.endToken.offset = 80; |
| 5939 methodDeclaration.accept(builder); | 1701 methodDeclaration.accept(builder); |
| 5940 | 1702 |
| 5941 List<FieldElement> fields = holder.fields; | 1703 List<FieldElement> fields = holder.fields; |
| 5942 expect(fields, hasLength(1)); | 1704 expect(fields, hasLength(1)); |
| 5943 FieldElement field = fields[0]; | 1705 FieldElement field = fields[0]; |
| 5944 expect(field, isNotNull); | 1706 expect(field, isNotNull); |
| 5945 expect(field.name, methodName); | 1707 expect(field.name, methodName); |
| 5946 expect(field.isSynthetic, isTrue); | 1708 expect(field.isSynthetic, isTrue); |
| 5947 expect(field.setter, isNull); | 1709 expect(field.setter, isNull); |
| 5948 PropertyAccessorElement getter = field.getter; | 1710 PropertyAccessorElement getter = field.getter; |
| 5949 expect(getter, isNotNull); | 1711 expect(getter, isNotNull); |
| 5950 _assertHasDocRange(getter, 50, 7); | 1712 _assertHasCodeRange(getter, 50, 31); |
| 1713 expect(getter.documentationComment, '/// aaa'); |
| 5951 expect(getter.hasImplicitReturnType, isTrue); | 1714 expect(getter.hasImplicitReturnType, isTrue); |
| 5952 expect(getter.isAbstract, isFalse); | 1715 expect(getter.isAbstract, isFalse); |
| 5953 expect(getter.isExternal, isFalse); | 1716 expect(getter.isExternal, isFalse); |
| 5954 expect(getter.isGetter, isTrue); | 1717 expect(getter.isGetter, isTrue); |
| 5955 expect(getter.isSynthetic, isFalse); | 1718 expect(getter.isSynthetic, isFalse); |
| 5956 expect(getter.name, methodName); | 1719 expect(getter.name, methodName); |
| 5957 expect(getter.variable, field); | 1720 expect(getter.variable, field); |
| 5958 expect(getter.functions, hasLength(0)); | 1721 expect(getter.functions, hasLength(0)); |
| 5959 expect(getter.labels, hasLength(0)); | 1722 expect(getter.labels, hasLength(0)); |
| 5960 expect(getter.localVariables, hasLength(0)); | 1723 expect(getter.localVariables, hasLength(0)); |
| 5961 expect(getter.parameters, hasLength(0)); | 1724 expect(getter.parameters, hasLength(0)); |
| 5962 } | 1725 } |
| 5963 | 1726 |
| 5964 void test_visitMethodDeclaration_getter_abstract() { | 1727 void test_visitMethodDeclaration_getter_abstract() { |
| 5965 // get m(); | 1728 // get m(); |
| 5966 ElementHolder holder = new ElementHolder(); | 1729 ElementHolder holder = new ElementHolder(); |
| 5967 ElementBuilder builder = new ElementBuilder(holder); | 1730 ElementBuilder builder = _makeBuilder(holder); |
| 5968 String methodName = "m"; | 1731 String methodName = "m"; |
| 5969 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1732 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 5970 null, | 1733 null, |
| 5971 null, | 1734 null, |
| 5972 Keyword.GET, | 1735 Keyword.GET, |
| 5973 null, | 1736 null, |
| 5974 AstFactory.identifier3(methodName), | 1737 AstFactory.identifier3(methodName), |
| 5975 AstFactory.formalParameterList(), | 1738 AstFactory.formalParameterList(), |
| 5976 AstFactory.emptyFunctionBody()); | 1739 AstFactory.emptyFunctionBody()); |
| 5977 methodDeclaration.accept(builder); | 1740 methodDeclaration.accept(builder); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 5994 expect(getter.variable, field); | 1757 expect(getter.variable, field); |
| 5995 expect(getter.functions, hasLength(0)); | 1758 expect(getter.functions, hasLength(0)); |
| 5996 expect(getter.labels, hasLength(0)); | 1759 expect(getter.labels, hasLength(0)); |
| 5997 expect(getter.localVariables, hasLength(0)); | 1760 expect(getter.localVariables, hasLength(0)); |
| 5998 expect(getter.parameters, hasLength(0)); | 1761 expect(getter.parameters, hasLength(0)); |
| 5999 } | 1762 } |
| 6000 | 1763 |
| 6001 void test_visitMethodDeclaration_getter_external() { | 1764 void test_visitMethodDeclaration_getter_external() { |
| 6002 // external get m(); | 1765 // external get m(); |
| 6003 ElementHolder holder = new ElementHolder(); | 1766 ElementHolder holder = new ElementHolder(); |
| 6004 ElementBuilder builder = new ElementBuilder(holder); | 1767 ElementBuilder builder = _makeBuilder(holder); |
| 6005 String methodName = "m"; | 1768 String methodName = "m"; |
| 6006 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( | 1769 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( |
| 6007 null, | 1770 null, |
| 6008 null, | 1771 null, |
| 6009 Keyword.GET, | 1772 Keyword.GET, |
| 6010 null, | 1773 null, |
| 6011 AstFactory.identifier3(methodName), | 1774 AstFactory.identifier3(methodName), |
| 6012 AstFactory.formalParameterList()); | 1775 AstFactory.formalParameterList()); |
| 6013 methodDeclaration.externalKeyword = | 1776 methodDeclaration.externalKeyword = |
| 6014 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 1777 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 6032 expect(getter.variable, field); | 1795 expect(getter.variable, field); |
| 6033 expect(getter.functions, hasLength(0)); | 1796 expect(getter.functions, hasLength(0)); |
| 6034 expect(getter.labels, hasLength(0)); | 1797 expect(getter.labels, hasLength(0)); |
| 6035 expect(getter.localVariables, hasLength(0)); | 1798 expect(getter.localVariables, hasLength(0)); |
| 6036 expect(getter.parameters, hasLength(0)); | 1799 expect(getter.parameters, hasLength(0)); |
| 6037 } | 1800 } |
| 6038 | 1801 |
| 6039 void test_visitMethodDeclaration_minimal() { | 1802 void test_visitMethodDeclaration_minimal() { |
| 6040 // T m() {} | 1803 // T m() {} |
| 6041 ElementHolder holder = new ElementHolder(); | 1804 ElementHolder holder = new ElementHolder(); |
| 6042 ElementBuilder builder = new ElementBuilder(holder); | 1805 ElementBuilder builder = _makeBuilder(holder); |
| 6043 String methodName = "m"; | 1806 String methodName = "m"; |
| 6044 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1807 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6045 null, | 1808 null, |
| 6046 AstFactory.typeName4('T'), | 1809 AstFactory.typeName4('T'), |
| 6047 null, | 1810 null, |
| 6048 null, | 1811 null, |
| 6049 AstFactory.identifier3(methodName), | 1812 AstFactory.identifier3(methodName), |
| 6050 AstFactory.formalParameterList(), | 1813 AstFactory.formalParameterList(), |
| 6051 AstFactory.blockFunctionBody2()); | 1814 AstFactory.blockFunctionBody2()); |
| 6052 methodDeclaration.documentationComment = AstFactory.documentationComment( | 1815 methodDeclaration.documentationComment = AstFactory.documentationComment( |
| 6053 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1816 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1817 methodDeclaration.endToken.offset = 80; |
| 6054 methodDeclaration.accept(builder); | 1818 methodDeclaration.accept(builder); |
| 6055 | 1819 |
| 6056 List<MethodElement> methods = holder.methods; | 1820 List<MethodElement> methods = holder.methods; |
| 6057 expect(methods, hasLength(1)); | 1821 expect(methods, hasLength(1)); |
| 6058 MethodElement method = methods[0]; | 1822 MethodElement method = methods[0]; |
| 6059 expect(method, isNotNull); | 1823 expect(method, isNotNull); |
| 6060 _assertHasDocRange(method, 50, 7); | 1824 _assertHasCodeRange(method, 50, 31); |
| 1825 expect(method.documentationComment, '/// aaa'); |
| 6061 expect(method.hasImplicitReturnType, isFalse); | 1826 expect(method.hasImplicitReturnType, isFalse); |
| 6062 expect(method.name, methodName); | 1827 expect(method.name, methodName); |
| 6063 expect(method.functions, hasLength(0)); | 1828 expect(method.functions, hasLength(0)); |
| 6064 expect(method.labels, hasLength(0)); | 1829 expect(method.labels, hasLength(0)); |
| 6065 expect(method.localVariables, hasLength(0)); | 1830 expect(method.localVariables, hasLength(0)); |
| 6066 expect(method.parameters, hasLength(0)); | 1831 expect(method.parameters, hasLength(0)); |
| 6067 expect(method.typeParameters, hasLength(0)); | 1832 expect(method.typeParameters, hasLength(0)); |
| 6068 expect(method.isAbstract, isFalse); | 1833 expect(method.isAbstract, isFalse); |
| 6069 expect(method.isExternal, isFalse); | 1834 expect(method.isExternal, isFalse); |
| 6070 expect(method.isStatic, isFalse); | 1835 expect(method.isStatic, isFalse); |
| 6071 expect(method.isSynthetic, isFalse); | 1836 expect(method.isSynthetic, isFalse); |
| 6072 } | 1837 } |
| 6073 | 1838 |
| 6074 void test_visitMethodDeclaration_operator() { | 1839 void test_visitMethodDeclaration_operator() { |
| 6075 // operator +(addend) {} | 1840 // operator +(addend) {} |
| 6076 ElementHolder holder = new ElementHolder(); | 1841 ElementHolder holder = new ElementHolder(); |
| 6077 ElementBuilder builder = new ElementBuilder(holder); | 1842 ElementBuilder builder = _makeBuilder(holder); |
| 6078 String methodName = "+"; | 1843 String methodName = "+"; |
| 6079 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1844 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6080 null, | 1845 null, |
| 6081 null, | 1846 null, |
| 6082 null, | 1847 null, |
| 6083 Keyword.OPERATOR, | 1848 Keyword.OPERATOR, |
| 6084 AstFactory.identifier3(methodName), | 1849 AstFactory.identifier3(methodName), |
| 6085 AstFactory | 1850 AstFactory |
| 6086 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), | 1851 .formalParameterList([AstFactory.simpleFormalParameter3("addend")]), |
| 6087 AstFactory.blockFunctionBody2()); | 1852 AstFactory.blockFunctionBody2()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6100 expect(method.typeParameters, hasLength(0)); | 1865 expect(method.typeParameters, hasLength(0)); |
| 6101 expect(method.isAbstract, isFalse); | 1866 expect(method.isAbstract, isFalse); |
| 6102 expect(method.isExternal, isFalse); | 1867 expect(method.isExternal, isFalse); |
| 6103 expect(method.isStatic, isFalse); | 1868 expect(method.isStatic, isFalse); |
| 6104 expect(method.isSynthetic, isFalse); | 1869 expect(method.isSynthetic, isFalse); |
| 6105 } | 1870 } |
| 6106 | 1871 |
| 6107 void test_visitMethodDeclaration_setter() { | 1872 void test_visitMethodDeclaration_setter() { |
| 6108 // set m() {} | 1873 // set m() {} |
| 6109 ElementHolder holder = new ElementHolder(); | 1874 ElementHolder holder = new ElementHolder(); |
| 6110 ElementBuilder builder = new ElementBuilder(holder); | 1875 ElementBuilder builder = _makeBuilder(holder); |
| 6111 String methodName = "m"; | 1876 String methodName = "m"; |
| 6112 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1877 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6113 null, | 1878 null, |
| 6114 null, | 1879 null, |
| 6115 Keyword.SET, | 1880 Keyword.SET, |
| 6116 null, | 1881 null, |
| 6117 AstFactory.identifier3(methodName), | 1882 AstFactory.identifier3(methodName), |
| 6118 AstFactory.formalParameterList(), | 1883 AstFactory.formalParameterList(), |
| 6119 AstFactory.blockFunctionBody2()); | 1884 AstFactory.blockFunctionBody2()); |
| 6120 methodDeclaration.documentationComment = AstFactory.documentationComment( | 1885 methodDeclaration.documentationComment = AstFactory.documentationComment( |
| 6121 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 1886 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 1887 methodDeclaration.endToken.offset = 80; |
| 6122 methodDeclaration.accept(builder); | 1888 methodDeclaration.accept(builder); |
| 6123 | 1889 |
| 6124 List<FieldElement> fields = holder.fields; | 1890 List<FieldElement> fields = holder.fields; |
| 6125 expect(fields, hasLength(1)); | 1891 expect(fields, hasLength(1)); |
| 6126 FieldElement field = fields[0]; | 1892 FieldElement field = fields[0]; |
| 6127 expect(field, isNotNull); | 1893 expect(field, isNotNull); |
| 6128 expect(field.name, methodName); | 1894 expect(field.name, methodName); |
| 6129 expect(field.isSynthetic, isTrue); | 1895 expect(field.isSynthetic, isTrue); |
| 6130 expect(field.getter, isNull); | 1896 expect(field.getter, isNull); |
| 6131 | 1897 |
| 6132 PropertyAccessorElement setter = field.setter; | 1898 PropertyAccessorElement setter = field.setter; |
| 6133 expect(setter, isNotNull); | 1899 expect(setter, isNotNull); |
| 6134 _assertHasDocRange(setter, 50, 7); | 1900 _assertHasCodeRange(setter, 50, 31); |
| 6135 expect(setter.hasImplicitReturnType, isFalse); | 1901 expect(setter.documentationComment, '/// aaa'); |
| 1902 expect(setter.hasImplicitReturnType, isTrue); |
| 6136 expect(setter.isAbstract, isFalse); | 1903 expect(setter.isAbstract, isFalse); |
| 6137 expect(setter.isExternal, isFalse); | 1904 expect(setter.isExternal, isFalse); |
| 6138 expect(setter.isSetter, isTrue); | 1905 expect(setter.isSetter, isTrue); |
| 6139 expect(setter.isSynthetic, isFalse); | 1906 expect(setter.isSynthetic, isFalse); |
| 6140 expect(setter.name, "$methodName="); | 1907 expect(setter.name, "$methodName="); |
| 6141 expect(setter.displayName, methodName); | 1908 expect(setter.displayName, methodName); |
| 6142 expect(setter.variable, field); | 1909 expect(setter.variable, field); |
| 6143 expect(setter.functions, hasLength(0)); | 1910 expect(setter.functions, hasLength(0)); |
| 6144 expect(setter.labels, hasLength(0)); | 1911 expect(setter.labels, hasLength(0)); |
| 6145 expect(setter.localVariables, hasLength(0)); | 1912 expect(setter.localVariables, hasLength(0)); |
| 6146 expect(setter.parameters, hasLength(0)); | 1913 expect(setter.parameters, hasLength(0)); |
| 6147 } | 1914 } |
| 6148 | 1915 |
| 6149 void test_visitMethodDeclaration_setter_abstract() { | 1916 void test_visitMethodDeclaration_setter_abstract() { |
| 6150 // set m(); | 1917 // set m(); |
| 6151 ElementHolder holder = new ElementHolder(); | 1918 ElementHolder holder = new ElementHolder(); |
| 6152 ElementBuilder builder = new ElementBuilder(holder); | 1919 ElementBuilder builder = _makeBuilder(holder); |
| 6153 String methodName = "m"; | 1920 String methodName = "m"; |
| 6154 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1921 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6155 null, | 1922 null, |
| 6156 null, | 1923 null, |
| 6157 Keyword.SET, | 1924 Keyword.SET, |
| 6158 null, | 1925 null, |
| 6159 AstFactory.identifier3(methodName), | 1926 AstFactory.identifier3(methodName), |
| 6160 AstFactory.formalParameterList(), | 1927 AstFactory.formalParameterList(), |
| 6161 AstFactory.emptyFunctionBody()); | 1928 AstFactory.emptyFunctionBody()); |
| 6162 methodDeclaration.accept(builder); | 1929 methodDeclaration.accept(builder); |
| 6163 | 1930 |
| 6164 List<FieldElement> fields = holder.fields; | 1931 List<FieldElement> fields = holder.fields; |
| 6165 expect(fields, hasLength(1)); | 1932 expect(fields, hasLength(1)); |
| 6166 FieldElement field = fields[0]; | 1933 FieldElement field = fields[0]; |
| 6167 expect(field, isNotNull); | 1934 expect(field, isNotNull); |
| 6168 expect(field.name, methodName); | 1935 expect(field.name, methodName); |
| 6169 expect(field.isSynthetic, isTrue); | 1936 expect(field.isSynthetic, isTrue); |
| 6170 expect(field.getter, isNull); | 1937 expect(field.getter, isNull); |
| 6171 PropertyAccessorElement setter = field.setter; | 1938 PropertyAccessorElement setter = field.setter; |
| 6172 expect(setter, isNotNull); | 1939 expect(setter, isNotNull); |
| 6173 expect(setter.hasImplicitReturnType, isFalse); | 1940 expect(setter.hasImplicitReturnType, isTrue); |
| 6174 expect(setter.isAbstract, isTrue); | 1941 expect(setter.isAbstract, isTrue); |
| 6175 expect(setter.isExternal, isFalse); | 1942 expect(setter.isExternal, isFalse); |
| 6176 expect(setter.isSetter, isTrue); | 1943 expect(setter.isSetter, isTrue); |
| 6177 expect(setter.isSynthetic, isFalse); | 1944 expect(setter.isSynthetic, isFalse); |
| 6178 expect(setter.name, "$methodName="); | 1945 expect(setter.name, "$methodName="); |
| 6179 expect(setter.displayName, methodName); | 1946 expect(setter.displayName, methodName); |
| 6180 expect(setter.variable, field); | 1947 expect(setter.variable, field); |
| 6181 expect(setter.functions, hasLength(0)); | 1948 expect(setter.functions, hasLength(0)); |
| 6182 expect(setter.labels, hasLength(0)); | 1949 expect(setter.labels, hasLength(0)); |
| 6183 expect(setter.localVariables, hasLength(0)); | 1950 expect(setter.localVariables, hasLength(0)); |
| 6184 expect(setter.parameters, hasLength(0)); | 1951 expect(setter.parameters, hasLength(0)); |
| 6185 } | 1952 } |
| 6186 | 1953 |
| 6187 void test_visitMethodDeclaration_setter_external() { | 1954 void test_visitMethodDeclaration_setter_external() { |
| 6188 // external m(); | 1955 // external m(); |
| 6189 ElementHolder holder = new ElementHolder(); | 1956 ElementHolder holder = new ElementHolder(); |
| 6190 ElementBuilder builder = new ElementBuilder(holder); | 1957 ElementBuilder builder = _makeBuilder(holder); |
| 6191 String methodName = "m"; | 1958 String methodName = "m"; |
| 6192 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( | 1959 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration( |
| 6193 null, | 1960 null, |
| 6194 null, | 1961 null, |
| 6195 Keyword.SET, | 1962 Keyword.SET, |
| 6196 null, | 1963 null, |
| 6197 AstFactory.identifier3(methodName), | 1964 AstFactory.identifier3(methodName), |
| 6198 AstFactory.formalParameterList()); | 1965 AstFactory.formalParameterList()); |
| 6199 methodDeclaration.externalKeyword = | 1966 methodDeclaration.externalKeyword = |
| 6200 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); | 1967 TokenFactory.tokenFromKeyword(Keyword.EXTERNAL); |
| 6201 methodDeclaration.accept(builder); | 1968 methodDeclaration.accept(builder); |
| 6202 | 1969 |
| 6203 List<FieldElement> fields = holder.fields; | 1970 List<FieldElement> fields = holder.fields; |
| 6204 expect(fields, hasLength(1)); | 1971 expect(fields, hasLength(1)); |
| 6205 FieldElement field = fields[0]; | 1972 FieldElement field = fields[0]; |
| 6206 expect(field, isNotNull); | 1973 expect(field, isNotNull); |
| 6207 expect(field.name, methodName); | 1974 expect(field.name, methodName); |
| 6208 expect(field.isSynthetic, isTrue); | 1975 expect(field.isSynthetic, isTrue); |
| 6209 expect(field.getter, isNull); | 1976 expect(field.getter, isNull); |
| 6210 PropertyAccessorElement setter = field.setter; | 1977 PropertyAccessorElement setter = field.setter; |
| 6211 expect(setter, isNotNull); | 1978 expect(setter, isNotNull); |
| 6212 expect(setter.hasImplicitReturnType, isFalse); | 1979 expect(setter.hasImplicitReturnType, isTrue); |
| 6213 expect(setter.isAbstract, isFalse); | 1980 expect(setter.isAbstract, isFalse); |
| 6214 expect(setter.isExternal, isTrue); | 1981 expect(setter.isExternal, isTrue); |
| 6215 expect(setter.isSetter, isTrue); | 1982 expect(setter.isSetter, isTrue); |
| 6216 expect(setter.isSynthetic, isFalse); | 1983 expect(setter.isSynthetic, isFalse); |
| 6217 expect(setter.name, "$methodName="); | 1984 expect(setter.name, "$methodName="); |
| 6218 expect(setter.displayName, methodName); | 1985 expect(setter.displayName, methodName); |
| 6219 expect(setter.variable, field); | 1986 expect(setter.variable, field); |
| 6220 expect(setter.functions, hasLength(0)); | 1987 expect(setter.functions, hasLength(0)); |
| 6221 expect(setter.labels, hasLength(0)); | 1988 expect(setter.labels, hasLength(0)); |
| 6222 expect(setter.localVariables, hasLength(0)); | 1989 expect(setter.localVariables, hasLength(0)); |
| 6223 expect(setter.parameters, hasLength(0)); | 1990 expect(setter.parameters, hasLength(0)); |
| 6224 } | 1991 } |
| 6225 | 1992 |
| 6226 void test_visitMethodDeclaration_static() { | 1993 void test_visitMethodDeclaration_static() { |
| 6227 // static m() {} | 1994 // static m() {} |
| 6228 ElementHolder holder = new ElementHolder(); | 1995 ElementHolder holder = new ElementHolder(); |
| 6229 ElementBuilder builder = new ElementBuilder(holder); | 1996 ElementBuilder builder = _makeBuilder(holder); |
| 6230 String methodName = "m"; | 1997 String methodName = "m"; |
| 6231 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 1998 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6232 Keyword.STATIC, | 1999 Keyword.STATIC, |
| 6233 null, | 2000 null, |
| 6234 null, | 2001 null, |
| 6235 null, | 2002 null, |
| 6236 AstFactory.identifier3(methodName), | 2003 AstFactory.identifier3(methodName), |
| 6237 AstFactory.formalParameterList(), | 2004 AstFactory.formalParameterList(), |
| 6238 AstFactory.blockFunctionBody2()); | 2005 AstFactory.blockFunctionBody2()); |
| 6239 methodDeclaration.accept(builder); | 2006 methodDeclaration.accept(builder); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6250 expect(method.typeParameters, hasLength(0)); | 2017 expect(method.typeParameters, hasLength(0)); |
| 6251 expect(method.isAbstract, isFalse); | 2018 expect(method.isAbstract, isFalse); |
| 6252 expect(method.isExternal, isFalse); | 2019 expect(method.isExternal, isFalse); |
| 6253 expect(method.isStatic, isTrue); | 2020 expect(method.isStatic, isTrue); |
| 6254 expect(method.isSynthetic, isFalse); | 2021 expect(method.isSynthetic, isFalse); |
| 6255 } | 2022 } |
| 6256 | 2023 |
| 6257 void test_visitMethodDeclaration_typeParameters() { | 2024 void test_visitMethodDeclaration_typeParameters() { |
| 6258 // m<E>() {} | 2025 // m<E>() {} |
| 6259 ElementHolder holder = new ElementHolder(); | 2026 ElementHolder holder = new ElementHolder(); |
| 6260 ElementBuilder builder = new ElementBuilder(holder); | 2027 ElementBuilder builder = _makeBuilder(holder); |
| 6261 String methodName = "m"; | 2028 String methodName = "m"; |
| 6262 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 2029 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6263 null, | 2030 null, |
| 6264 null, | 2031 null, |
| 6265 null, | 2032 null, |
| 6266 null, | 2033 null, |
| 6267 AstFactory.identifier3(methodName), | 2034 AstFactory.identifier3(methodName), |
| 6268 AstFactory.formalParameterList(), | 2035 AstFactory.formalParameterList(), |
| 6269 AstFactory.blockFunctionBody2()); | 2036 AstFactory.blockFunctionBody2()); |
| 6270 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); | 2037 methodDeclaration.typeParameters = AstFactory.typeParameterList(['E']); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6283 expect(method.typeParameters, hasLength(1)); | 2050 expect(method.typeParameters, hasLength(1)); |
| 6284 expect(method.isAbstract, isFalse); | 2051 expect(method.isAbstract, isFalse); |
| 6285 expect(method.isExternal, isFalse); | 2052 expect(method.isExternal, isFalse); |
| 6286 expect(method.isStatic, isFalse); | 2053 expect(method.isStatic, isFalse); |
| 6287 expect(method.isSynthetic, isFalse); | 2054 expect(method.isSynthetic, isFalse); |
| 6288 } | 2055 } |
| 6289 | 2056 |
| 6290 void test_visitMethodDeclaration_withMembers() { | 2057 void test_visitMethodDeclaration_withMembers() { |
| 6291 // m(p) { var v; try { l: return; } catch (e) {} } | 2058 // m(p) { var v; try { l: return; } catch (e) {} } |
| 6292 ElementHolder holder = new ElementHolder(); | 2059 ElementHolder holder = new ElementHolder(); |
| 6293 ElementBuilder builder = new ElementBuilder(holder); | 2060 ElementBuilder builder = _makeBuilder(holder); |
| 6294 String methodName = "m"; | 2061 String methodName = "m"; |
| 6295 String parameterName = "p"; | 2062 String parameterName = "p"; |
| 6296 String localVariableName = "v"; | 2063 String localVariableName = "v"; |
| 6297 String labelName = "l"; | 2064 String labelName = "l"; |
| 6298 String exceptionParameterName = "e"; | 2065 String exceptionParameterName = "e"; |
| 6299 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 2066 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
| 6300 null, | 2067 null, |
| 6301 null, | 2068 null, |
| 6302 null, | 2069 null, |
| 6303 null, | 2070 null, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6346 isTrue); | 2113 isTrue); |
| 6347 List<LabelElement> labels = method.labels; | 2114 List<LabelElement> labels = method.labels; |
| 6348 expect(labels, hasLength(1)); | 2115 expect(labels, hasLength(1)); |
| 6349 LabelElement label = labels[0]; | 2116 LabelElement label = labels[0]; |
| 6350 expect(label, isNotNull); | 2117 expect(label, isNotNull); |
| 6351 expect(label.name, labelName); | 2118 expect(label.name, labelName); |
| 6352 } | 2119 } |
| 6353 | 2120 |
| 6354 void test_visitNamedFormalParameter() { | 2121 void test_visitNamedFormalParameter() { |
| 6355 ElementHolder holder = new ElementHolder(); | 2122 ElementHolder holder = new ElementHolder(); |
| 6356 ElementBuilder builder = new ElementBuilder(holder); | 2123 ElementBuilder builder = _makeBuilder(holder); |
| 6357 String parameterName = "p"; | 2124 String parameterName = "p"; |
| 6358 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( | 2125 DefaultFormalParameter formalParameter = AstFactory.namedFormalParameter( |
| 6359 AstFactory.simpleFormalParameter3(parameterName), | 2126 AstFactory.simpleFormalParameter3(parameterName), |
| 6360 AstFactory.identifier3("42")); | 2127 AstFactory.identifier3("42")); |
| 6361 _useParameterInMethod(formalParameter, 100, 110); | 2128 _useParameterInMethod(formalParameter, 100, 110); |
| 2129 formalParameter.beginToken.offset = 50; |
| 2130 formalParameter.endToken.offset = 80; |
| 6362 formalParameter.accept(builder); | 2131 formalParameter.accept(builder); |
| 6363 List<ParameterElement> parameters = holder.parameters; | 2132 List<ParameterElement> parameters = holder.parameters; |
| 6364 expect(parameters, hasLength(1)); | 2133 expect(parameters, hasLength(1)); |
| 6365 ParameterElement parameter = parameters[0]; | 2134 ParameterElement parameter = parameters[0]; |
| 6366 expect(parameter, isNotNull); | 2135 expect(parameter, isNotNull); |
| 2136 _assertHasCodeRange(parameter, 50, 32); |
| 6367 expect(parameter.name, parameterName); | 2137 expect(parameter.name, parameterName); |
| 6368 expect(parameter.isConst, isFalse); | 2138 expect(parameter.isConst, isFalse); |
| 6369 expect(parameter.isFinal, isFalse); | 2139 expect(parameter.isFinal, isFalse); |
| 6370 expect(parameter.isSynthetic, isFalse); | 2140 expect(parameter.isSynthetic, isFalse); |
| 6371 expect(parameter.parameterKind, ParameterKind.NAMED); | 2141 expect(parameter.parameterKind, ParameterKind.NAMED); |
| 6372 { | 2142 _assertVisibleRange(parameter, 100, 110); |
| 6373 SourceRange visibleRange = parameter.visibleRange; | |
| 6374 expect(100, visibleRange.offset); | |
| 6375 expect(110, visibleRange.end); | |
| 6376 } | |
| 6377 expect(parameter.defaultValueCode, "42"); | 2143 expect(parameter.defaultValueCode, "42"); |
| 6378 FunctionElement initializer = parameter.initializer; | 2144 FunctionElement initializer = parameter.initializer; |
| 6379 expect(initializer, isNotNull); | 2145 expect(initializer, isNotNull); |
| 6380 expect(initializer.isSynthetic, isTrue); | 2146 expect(initializer.isSynthetic, isTrue); |
| 2147 expect(initializer.hasImplicitReturnType, isTrue); |
| 6381 } | 2148 } |
| 6382 | 2149 |
| 6383 void test_visitSimpleFormalParameter_noType() { | 2150 void test_visitSimpleFormalParameter_noType() { |
| 6384 // p | 2151 // p |
| 6385 ElementHolder holder = new ElementHolder(); | 2152 ElementHolder holder = new ElementHolder(); |
| 6386 ElementBuilder builder = new ElementBuilder(holder); | 2153 ElementBuilder builder = _makeBuilder(holder); |
| 6387 String parameterName = "p"; | 2154 String parameterName = "p"; |
| 6388 SimpleFormalParameter formalParameter = | 2155 SimpleFormalParameter formalParameter = |
| 6389 AstFactory.simpleFormalParameter3(parameterName); | 2156 AstFactory.simpleFormalParameter3(parameterName); |
| 6390 _useParameterInMethod(formalParameter, 100, 110); | 2157 _useParameterInMethod(formalParameter, 100, 110); |
| 6391 formalParameter.accept(builder); | 2158 formalParameter.accept(builder); |
| 6392 List<ParameterElement> parameters = holder.parameters; | 2159 List<ParameterElement> parameters = holder.parameters; |
| 6393 expect(parameters, hasLength(1)); | 2160 expect(parameters, hasLength(1)); |
| 6394 ParameterElement parameter = parameters[0]; | 2161 ParameterElement parameter = parameters[0]; |
| 6395 expect(parameter, isNotNull); | 2162 expect(parameter, isNotNull); |
| 6396 expect(parameter.hasImplicitType, isTrue); | 2163 expect(parameter.hasImplicitType, isTrue); |
| 6397 expect(parameter.initializer, isNull); | 2164 expect(parameter.initializer, isNull); |
| 6398 expect(parameter.isConst, isFalse); | 2165 expect(parameter.isConst, isFalse); |
| 6399 expect(parameter.isFinal, isFalse); | 2166 expect(parameter.isFinal, isFalse); |
| 6400 expect(parameter.isSynthetic, isFalse); | 2167 expect(parameter.isSynthetic, isFalse); |
| 6401 expect(parameter.name, parameterName); | 2168 expect(parameter.name, parameterName); |
| 6402 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 2169 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 6403 { | 2170 _assertVisibleRange(parameter, 100, 110); |
| 6404 SourceRange visibleRange = parameter.visibleRange; | |
| 6405 expect(100, visibleRange.offset); | |
| 6406 expect(110, visibleRange.end); | |
| 6407 } | |
| 6408 } | 2171 } |
| 6409 | 2172 |
| 6410 void test_visitSimpleFormalParameter_type() { | 2173 void test_visitSimpleFormalParameter_type() { |
| 6411 // T p | 2174 // T p |
| 6412 ElementHolder holder = new ElementHolder(); | 2175 ElementHolder holder = new ElementHolder(); |
| 6413 ElementBuilder builder = new ElementBuilder(holder); | 2176 ElementBuilder builder = _makeBuilder(holder); |
| 6414 String parameterName = "p"; | 2177 String parameterName = "p"; |
| 6415 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4( | 2178 SimpleFormalParameter formalParameter = AstFactory.simpleFormalParameter4( |
| 6416 AstFactory.typeName4('T'), parameterName); | 2179 AstFactory.typeName4('T'), parameterName); |
| 6417 _useParameterInMethod(formalParameter, 100, 110); | 2180 _useParameterInMethod(formalParameter, 100, 110); |
| 6418 formalParameter.accept(builder); | 2181 formalParameter.accept(builder); |
| 6419 List<ParameterElement> parameters = holder.parameters; | 2182 List<ParameterElement> parameters = holder.parameters; |
| 6420 expect(parameters, hasLength(1)); | 2183 expect(parameters, hasLength(1)); |
| 6421 ParameterElement parameter = parameters[0]; | 2184 ParameterElement parameter = parameters[0]; |
| 6422 expect(parameter, isNotNull); | 2185 expect(parameter, isNotNull); |
| 6423 expect(parameter.hasImplicitType, isFalse); | 2186 expect(parameter.hasImplicitType, isFalse); |
| 6424 expect(parameter.initializer, isNull); | 2187 expect(parameter.initializer, isNull); |
| 6425 expect(parameter.isConst, isFalse); | 2188 expect(parameter.isConst, isFalse); |
| 6426 expect(parameter.isFinal, isFalse); | 2189 expect(parameter.isFinal, isFalse); |
| 6427 expect(parameter.isSynthetic, isFalse); | 2190 expect(parameter.isSynthetic, isFalse); |
| 6428 expect(parameter.name, parameterName); | 2191 expect(parameter.name, parameterName); |
| 6429 expect(parameter.parameterKind, ParameterKind.REQUIRED); | 2192 expect(parameter.parameterKind, ParameterKind.REQUIRED); |
| 6430 { | 2193 _assertVisibleRange(parameter, 100, 110); |
| 6431 SourceRange visibleRange = parameter.visibleRange; | |
| 6432 expect(100, visibleRange.offset); | |
| 6433 expect(110, visibleRange.end); | |
| 6434 } | |
| 6435 } | 2194 } |
| 6436 | 2195 |
| 6437 void test_visitTypeAlias_minimal() { | 2196 void test_visitTypeAlias_minimal() { |
| 6438 ElementHolder holder = new ElementHolder(); | 2197 ElementHolder holder = new ElementHolder(); |
| 6439 ElementBuilder builder = new ElementBuilder(holder); | 2198 ElementBuilder builder = _makeBuilder(holder); |
| 6440 String aliasName = "F"; | 2199 String aliasName = "F"; |
| 6441 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); | 2200 TypeAlias typeAlias = AstFactory.typeAlias(null, aliasName, null, null); |
| 6442 typeAlias.accept(builder); | 2201 typeAlias.accept(builder); |
| 6443 List<FunctionTypeAliasElement> aliases = holder.typeAliases; | 2202 List<FunctionTypeAliasElement> aliases = holder.typeAliases; |
| 6444 expect(aliases, hasLength(1)); | 2203 expect(aliases, hasLength(1)); |
| 6445 FunctionTypeAliasElement alias = aliases[0]; | 2204 FunctionTypeAliasElement alias = aliases[0]; |
| 6446 expect(alias, isNotNull); | 2205 expect(alias, isNotNull); |
| 6447 expect(alias.name, aliasName); | 2206 expect(alias.name, aliasName); |
| 6448 expect(alias.type, isNotNull); | 2207 expect(alias.type, isNotNull); |
| 6449 expect(alias.isSynthetic, isFalse); | 2208 expect(alias.isSynthetic, isFalse); |
| 6450 } | 2209 } |
| 6451 | 2210 |
| 6452 void test_visitTypeAlias_withFormalParameters() { | 2211 void test_visitTypeAlias_withFormalParameters() { |
| 6453 ElementHolder holder = new ElementHolder(); | 2212 ElementHolder holder = new ElementHolder(); |
| 6454 ElementBuilder builder = new ElementBuilder(holder); | 2213 ElementBuilder builder = _makeBuilder(holder); |
| 6455 String aliasName = "F"; | 2214 String aliasName = "F"; |
| 6456 String firstParameterName = "x"; | 2215 String firstParameterName = "x"; |
| 6457 String secondParameterName = "y"; | 2216 String secondParameterName = "y"; |
| 6458 TypeAlias typeAlias = AstFactory.typeAlias( | 2217 TypeAlias typeAlias = AstFactory.typeAlias( |
| 6459 null, | 2218 null, |
| 6460 aliasName, | 2219 aliasName, |
| 6461 AstFactory.typeParameterList(), | 2220 AstFactory.typeParameterList(), |
| 6462 AstFactory.formalParameterList([ | 2221 AstFactory.formalParameterList([ |
| 6463 AstFactory.simpleFormalParameter3(firstParameterName), | 2222 AstFactory.simpleFormalParameter3(firstParameterName), |
| 6464 AstFactory.simpleFormalParameter3(secondParameterName) | 2223 AstFactory.simpleFormalParameter3(secondParameterName) |
| 6465 ])); | 2224 ])); |
| 2225 typeAlias.beginToken.offset = 50; |
| 2226 typeAlias.endToken.offset = 80; |
| 6466 typeAlias.accept(builder); | 2227 typeAlias.accept(builder); |
| 6467 List<FunctionTypeAliasElement> aliases = holder.typeAliases; | 2228 List<FunctionTypeAliasElement> aliases = holder.typeAliases; |
| 6468 expect(aliases, hasLength(1)); | 2229 expect(aliases, hasLength(1)); |
| 6469 FunctionTypeAliasElement alias = aliases[0]; | 2230 FunctionTypeAliasElement alias = aliases[0]; |
| 6470 expect(alias, isNotNull); | 2231 expect(alias, isNotNull); |
| 2232 _assertHasCodeRange(alias, 50, 31); |
| 6471 expect(alias.name, aliasName); | 2233 expect(alias.name, aliasName); |
| 6472 expect(alias.type, isNotNull); | 2234 expect(alias.type, isNotNull); |
| 6473 expect(alias.isSynthetic, isFalse); | 2235 expect(alias.isSynthetic, isFalse); |
| 6474 List<VariableElement> parameters = alias.parameters; | 2236 List<VariableElement> parameters = alias.parameters; |
| 6475 expect(parameters, hasLength(2)); | 2237 expect(parameters, hasLength(2)); |
| 6476 expect(parameters[0].name, firstParameterName); | 2238 expect(parameters[0].name, firstParameterName); |
| 6477 expect(parameters[1].name, secondParameterName); | 2239 expect(parameters[1].name, secondParameterName); |
| 6478 List<TypeParameterElement> typeParameters = alias.typeParameters; | 2240 List<TypeParameterElement> typeParameters = alias.typeParameters; |
| 6479 expect(typeParameters, isNotNull); | 2241 expect(typeParameters, isNotNull); |
| 6480 expect(typeParameters, hasLength(0)); | 2242 expect(typeParameters, hasLength(0)); |
| 6481 } | 2243 } |
| 6482 | 2244 |
| 6483 void test_visitTypeAlias_withTypeParameters() { | 2245 void test_visitTypeAlias_withTypeParameters() { |
| 6484 ElementHolder holder = new ElementHolder(); | 2246 ElementHolder holder = new ElementHolder(); |
| 6485 ElementBuilder builder = new ElementBuilder(holder); | 2247 ElementBuilder builder = _makeBuilder(holder); |
| 6486 String aliasName = "F"; | 2248 String aliasName = "F"; |
| 6487 String firstTypeParameterName = "A"; | 2249 String firstTypeParameterName = "A"; |
| 6488 String secondTypeParameterName = "B"; | 2250 String secondTypeParameterName = "B"; |
| 6489 TypeAlias typeAlias = AstFactory.typeAlias( | 2251 TypeAlias typeAlias = AstFactory.typeAlias( |
| 6490 null, | 2252 null, |
| 6491 aliasName, | 2253 aliasName, |
| 6492 AstFactory.typeParameterList( | 2254 AstFactory.typeParameterList( |
| 6493 [firstTypeParameterName, secondTypeParameterName]), | 2255 [firstTypeParameterName, secondTypeParameterName]), |
| 6494 AstFactory.formalParameterList()); | 2256 AstFactory.formalParameterList()); |
| 6495 typeAlias.accept(builder); | 2257 typeAlias.accept(builder); |
| 6496 List<FunctionTypeAliasElement> aliases = holder.typeAliases; | 2258 List<FunctionTypeAliasElement> aliases = holder.typeAliases; |
| 6497 expect(aliases, hasLength(1)); | 2259 expect(aliases, hasLength(1)); |
| 6498 FunctionTypeAliasElement alias = aliases[0]; | 2260 FunctionTypeAliasElement alias = aliases[0]; |
| 6499 expect(alias, isNotNull); | 2261 expect(alias, isNotNull); |
| 6500 expect(alias.name, aliasName); | 2262 expect(alias.name, aliasName); |
| 6501 expect(alias.type, isNotNull); | 2263 expect(alias.type, isNotNull); |
| 6502 expect(alias.isSynthetic, isFalse); | 2264 expect(alias.isSynthetic, isFalse); |
| 6503 List<VariableElement> parameters = alias.parameters; | 2265 List<VariableElement> parameters = alias.parameters; |
| 6504 expect(parameters, isNotNull); | 2266 expect(parameters, isNotNull); |
| 6505 expect(parameters, hasLength(0)); | 2267 expect(parameters, hasLength(0)); |
| 6506 List<TypeParameterElement> typeParameters = alias.typeParameters; | 2268 List<TypeParameterElement> typeParameters = alias.typeParameters; |
| 6507 expect(typeParameters, hasLength(2)); | 2269 expect(typeParameters, hasLength(2)); |
| 6508 expect(typeParameters[0].name, firstTypeParameterName); | 2270 expect(typeParameters[0].name, firstTypeParameterName); |
| 6509 expect(typeParameters[1].name, secondTypeParameterName); | 2271 expect(typeParameters[1].name, secondTypeParameterName); |
| 6510 } | 2272 } |
| 6511 | 2273 |
| 6512 void test_visitTypeParameter() { | 2274 void test_visitTypeParameter() { |
| 6513 ElementHolder holder = new ElementHolder(); | 2275 ElementHolder holder = new ElementHolder(); |
| 6514 ElementBuilder builder = new ElementBuilder(holder); | 2276 ElementBuilder builder = _makeBuilder(holder); |
| 6515 String parameterName = "E"; | 2277 String parameterName = "E"; |
| 6516 TypeParameter typeParameter = AstFactory.typeParameter(parameterName); | 2278 TypeParameter typeParameter = AstFactory.typeParameter(parameterName); |
| 2279 typeParameter.beginToken.offset = 50; |
| 6517 typeParameter.accept(builder); | 2280 typeParameter.accept(builder); |
| 6518 List<TypeParameterElement> typeParameters = holder.typeParameters; | 2281 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 6519 expect(typeParameters, hasLength(1)); | 2282 expect(typeParameters, hasLength(1)); |
| 6520 TypeParameterElement typeParameterElement = typeParameters[0]; | 2283 TypeParameterElement typeParameterElement = typeParameters[0]; |
| 6521 expect(typeParameterElement, isNotNull); | 2284 expect(typeParameterElement, isNotNull); |
| 2285 _assertHasCodeRange(typeParameterElement, 50, 1); |
| 6522 expect(typeParameterElement.name, parameterName); | 2286 expect(typeParameterElement.name, parameterName); |
| 6523 expect(typeParameterElement.bound, isNull); | 2287 expect(typeParameterElement.bound, isNull); |
| 6524 expect(typeParameterElement.isSynthetic, isFalse); | 2288 expect(typeParameterElement.isSynthetic, isFalse); |
| 6525 } | 2289 } |
| 6526 | 2290 |
| 6527 void test_visitVariableDeclaration_inConstructor() { | 2291 void test_visitVariableDeclaration_inConstructor() { |
| 6528 ElementHolder holder = new ElementHolder(); | 2292 ElementHolder holder = new ElementHolder(); |
| 6529 ElementBuilder builder = new ElementBuilder(holder); | 2293 ElementBuilder builder = _makeBuilder(holder); |
| 6530 // | 2294 // |
| 6531 // C() {var v;} | 2295 // C() {var v;} |
| 6532 // | 2296 // |
| 6533 String variableName = "v"; | 2297 String variableName = "v"; |
| 6534 VariableDeclaration variable = | 2298 VariableDeclaration variable = |
| 6535 AstFactory.variableDeclaration2(variableName, null); | 2299 AstFactory.variableDeclaration2(variableName, null); |
| 6536 Statement statement = | 2300 VariableDeclarationStatement statement = |
| 6537 AstFactory.variableDeclarationStatement2(null, [variable]); | 2301 AstFactory.variableDeclarationStatement2(Keyword.VAR, [variable]); |
| 6538 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2( | 2302 ConstructorDeclaration constructor = AstFactory.constructorDeclaration2( |
| 6539 null, | 2303 null, |
| 6540 null, | 2304 null, |
| 6541 AstFactory.identifier3("C"), | 2305 AstFactory.identifier3("C"), |
| 6542 "C", | 2306 "C", |
| 6543 AstFactory.formalParameterList(), | 2307 AstFactory.formalParameterList(), |
| 6544 null, | 2308 null, |
| 6545 AstFactory.blockFunctionBody2([statement])); | 2309 AstFactory.blockFunctionBody2([statement])); |
| 2310 statement.beginToken.offset = 50; |
| 2311 statement.endToken.offset = 80; |
| 2312 _setBlockBodySourceRange(constructor.body, 100, 110); |
| 6546 constructor.accept(builder); | 2313 constructor.accept(builder); |
| 6547 | 2314 |
| 6548 List<ConstructorElement> constructors = holder.constructors; | 2315 List<ConstructorElement> constructors = holder.constructors; |
| 6549 expect(constructors, hasLength(1)); | 2316 expect(constructors, hasLength(1)); |
| 6550 List<LocalVariableElement> variableElements = | 2317 List<LocalVariableElement> variableElements = |
| 6551 constructors[0].localVariables; | 2318 constructors[0].localVariables; |
| 6552 expect(variableElements, hasLength(1)); | 2319 expect(variableElements, hasLength(1)); |
| 6553 LocalVariableElement variableElement = variableElements[0]; | 2320 LocalVariableElement variableElement = variableElements[0]; |
| 2321 _assertHasCodeRange(variableElement, 50, 31); |
| 6554 expect(variableElement.hasImplicitType, isTrue); | 2322 expect(variableElement.hasImplicitType, isTrue); |
| 6555 expect(variableElement.name, variableName); | 2323 expect(variableElement.name, variableName); |
| 2324 _assertVisibleRange(variableElement, 100, 110); |
| 2325 } |
| 2326 |
| 2327 void test_visitVariableDeclaration_inForEachStatement() { |
| 2328 ElementHolder holder = new ElementHolder(); |
| 2329 ElementBuilder builder = _makeBuilder(holder); |
| 2330 // |
| 2331 // m() { for (var v in []) } |
| 2332 // |
| 2333 String variableName = "v"; |
| 2334 Statement statement = AstFactory.forEachStatement( |
| 2335 AstFactory.declaredIdentifier3('v'), |
| 2336 AstFactory.listLiteral(), |
| 2337 AstFactory.block()); |
| 2338 _setNodeSourceRange(statement, 100, 110); |
| 2339 MethodDeclaration method = AstFactory.methodDeclaration2( |
| 2340 null, |
| 2341 null, |
| 2342 null, |
| 2343 null, |
| 2344 AstFactory.identifier3("m"), |
| 2345 AstFactory.formalParameterList(), |
| 2346 AstFactory.blockFunctionBody2([statement])); |
| 2347 _setBlockBodySourceRange(method.body, 200, 220); |
| 2348 method.accept(builder); |
| 2349 |
| 2350 List<MethodElement> methods = holder.methods; |
| 2351 expect(methods, hasLength(1)); |
| 2352 List<LocalVariableElement> variableElements = methods[0].localVariables; |
| 2353 expect(variableElements, hasLength(1)); |
| 2354 LocalVariableElement variableElement = variableElements[0]; |
| 2355 expect(variableElement.name, variableName); |
| 2356 _assertVisibleRange(variableElement, 100, 110); |
| 2357 } |
| 2358 |
| 2359 void test_visitVariableDeclaration_inForStatement() { |
| 2360 ElementHolder holder = new ElementHolder(); |
| 2361 ElementBuilder builder = _makeBuilder(holder); |
| 2362 // |
| 2363 // m() { for (T v;;) } |
| 2364 // |
| 2365 String variableName = "v"; |
| 2366 ForStatement statement = AstFactory.forStatement2( |
| 2367 AstFactory.variableDeclarationList(null, AstFactory.typeName4('T'), |
| 2368 [AstFactory.variableDeclaration('v')]), |
| 2369 null, |
| 2370 null, |
| 2371 AstFactory.block()); |
| 2372 _setNodeSourceRange(statement, 100, 110); |
| 2373 MethodDeclaration method = AstFactory.methodDeclaration2( |
| 2374 null, |
| 2375 null, |
| 2376 null, |
| 2377 null, |
| 2378 AstFactory.identifier3("m"), |
| 2379 AstFactory.formalParameterList(), |
| 2380 AstFactory.blockFunctionBody2([statement])); |
| 2381 _setBlockBodySourceRange(method.body, 200, 220); |
| 2382 method.accept(builder); |
| 2383 |
| 2384 List<MethodElement> methods = holder.methods; |
| 2385 expect(methods, hasLength(1)); |
| 2386 List<LocalVariableElement> variableElements = methods[0].localVariables; |
| 2387 expect(variableElements, hasLength(1)); |
| 2388 LocalVariableElement variableElement = variableElements[0]; |
| 2389 expect(variableElement.name, variableName); |
| 2390 _assertVisibleRange(variableElement, 100, 110); |
| 6556 } | 2391 } |
| 6557 | 2392 |
| 6558 void test_visitVariableDeclaration_inMethod() { | 2393 void test_visitVariableDeclaration_inMethod() { |
| 6559 ElementHolder holder = new ElementHolder(); | 2394 ElementHolder holder = new ElementHolder(); |
| 6560 ElementBuilder builder = new ElementBuilder(holder); | 2395 ElementBuilder builder = _makeBuilder(holder); |
| 6561 // | 2396 // |
| 6562 // m() {T v;} | 2397 // m() {T v;} |
| 6563 // | 2398 // |
| 6564 String variableName = "v"; | 2399 String variableName = "v"; |
| 6565 VariableDeclaration variable = | 2400 VariableDeclaration variable = |
| 6566 AstFactory.variableDeclaration2(variableName, null); | 2401 AstFactory.variableDeclaration2(variableName, null); |
| 6567 Statement statement = AstFactory.variableDeclarationStatement( | 2402 Statement statement = AstFactory.variableDeclarationStatement( |
| 6568 null, AstFactory.typeName4('T'), [variable]); | 2403 null, AstFactory.typeName4('T'), [variable]); |
| 6569 MethodDeclaration method = AstFactory.methodDeclaration2( | 2404 MethodDeclaration method = AstFactory.methodDeclaration2( |
| 6570 null, | 2405 null, |
| 6571 null, | 2406 null, |
| 6572 null, | 2407 null, |
| 6573 null, | 2408 null, |
| 6574 AstFactory.identifier3("m"), | 2409 AstFactory.identifier3("m"), |
| 6575 AstFactory.formalParameterList(), | 2410 AstFactory.formalParameterList(), |
| 6576 AstFactory.blockFunctionBody2([statement])); | 2411 AstFactory.blockFunctionBody2([statement])); |
| 2412 _setBlockBodySourceRange(method.body, 100, 110); |
| 6577 method.accept(builder); | 2413 method.accept(builder); |
| 6578 | 2414 |
| 6579 List<MethodElement> methods = holder.methods; | 2415 List<MethodElement> methods = holder.methods; |
| 6580 expect(methods, hasLength(1)); | 2416 expect(methods, hasLength(1)); |
| 6581 List<LocalVariableElement> variableElements = methods[0].localVariables; | 2417 List<LocalVariableElement> variableElements = methods[0].localVariables; |
| 6582 expect(variableElements, hasLength(1)); | 2418 expect(variableElements, hasLength(1)); |
| 6583 LocalVariableElement variableElement = variableElements[0]; | 2419 LocalVariableElement variableElement = variableElements[0]; |
| 6584 expect(variableElement.hasImplicitType, isFalse); | 2420 expect(variableElement.hasImplicitType, isFalse); |
| 6585 expect(variableElement.name, variableName); | 2421 expect(variableElement.name, variableName); |
| 2422 _assertVisibleRange(variableElement, 100, 110); |
| 6586 } | 2423 } |
| 6587 | 2424 |
| 6588 void test_visitVariableDeclaration_localNestedInFunction() { | 2425 void test_visitVariableDeclaration_localNestedInFunction() { |
| 6589 ElementHolder holder = new ElementHolder(); | 2426 ElementHolder holder = new ElementHolder(); |
| 6590 ElementBuilder builder = new ElementBuilder(holder); | 2427 ElementBuilder builder = _makeBuilder(holder); |
| 6591 // | 2428 // |
| 6592 // var f = () {var v;}; | 2429 // var f = () {var v;}; |
| 6593 // | 2430 // |
| 6594 String variableName = "v"; | 2431 String variableName = "v"; |
| 6595 VariableDeclaration variable = | 2432 VariableDeclaration variable = |
| 6596 AstFactory.variableDeclaration2(variableName, null); | 2433 AstFactory.variableDeclaration2(variableName, null); |
| 6597 Statement statement = | 2434 Statement statement = |
| 6598 AstFactory.variableDeclarationStatement2(null, [variable]); | 2435 AstFactory.variableDeclarationStatement2(null, [variable]); |
| 6599 Expression initializer = AstFactory.functionExpression2( | 2436 Expression initializer = AstFactory.functionExpression2( |
| 6600 AstFactory.formalParameterList(), | 2437 AstFactory.formalParameterList(), |
| 6601 AstFactory.blockFunctionBody2([statement])); | 2438 AstFactory.blockFunctionBody2([statement])); |
| 6602 String fieldName = "f"; | 2439 String fieldName = "f"; |
| 6603 VariableDeclaration field = | 2440 VariableDeclaration field = |
| 6604 AstFactory.variableDeclaration2(fieldName, initializer); | 2441 AstFactory.variableDeclaration2(fieldName, initializer); |
| 6605 FieldDeclaration fieldDeclaration = | 2442 FieldDeclaration fieldDeclaration = |
| 6606 AstFactory.fieldDeclaration2(false, null, [field]); | 2443 AstFactory.fieldDeclaration2(false, null, [field]); |
| 6607 fieldDeclaration.accept(builder); | 2444 fieldDeclaration.accept(builder); |
| 6608 | 2445 |
| 6609 List<FieldElement> variables = holder.fields; | 2446 List<FieldElement> variables = holder.fields; |
| 6610 expect(variables, hasLength(1)); | 2447 expect(variables, hasLength(1)); |
| 6611 FieldElement fieldElement = variables[0]; | 2448 FieldElement fieldElement = variables[0]; |
| 6612 expect(fieldElement, isNotNull); | 2449 expect(fieldElement, isNotNull); |
| 6613 FunctionElement initializerElement = fieldElement.initializer; | 2450 FunctionElement initializerElement = fieldElement.initializer; |
| 6614 expect(initializerElement, isNotNull); | 2451 expect(initializerElement, isNotNull); |
| 2452 expect(initializerElement.hasImplicitReturnType, isTrue); |
| 6615 List<FunctionElement> functionElements = initializerElement.functions; | 2453 List<FunctionElement> functionElements = initializerElement.functions; |
| 6616 expect(functionElements, hasLength(1)); | 2454 expect(functionElements, hasLength(1)); |
| 6617 List<LocalVariableElement> variableElements = | 2455 List<LocalVariableElement> variableElements = |
| 6618 functionElements[0].localVariables; | 2456 functionElements[0].localVariables; |
| 6619 expect(variableElements, hasLength(1)); | 2457 expect(variableElements, hasLength(1)); |
| 6620 LocalVariableElement variableElement = variableElements[0]; | 2458 LocalVariableElement variableElement = variableElements[0]; |
| 6621 expect(variableElement.hasImplicitType, isTrue); | 2459 expect(variableElement.hasImplicitType, isTrue); |
| 6622 expect(variableElement.isConst, isFalse); | 2460 expect(variableElement.isConst, isFalse); |
| 6623 expect(variableElement.isFinal, isFalse); | 2461 expect(variableElement.isFinal, isFalse); |
| 6624 expect(variableElement.isSynthetic, isFalse); | 2462 expect(variableElement.isSynthetic, isFalse); |
| 6625 expect(variableElement.name, variableName); | 2463 expect(variableElement.name, variableName); |
| 6626 } | 2464 } |
| 6627 | 2465 |
| 6628 void test_visitVariableDeclaration_noInitializer() { | 2466 void test_visitVariableDeclaration_noInitializer() { |
| 6629 // var v; | 2467 // var v; |
| 6630 ElementHolder holder = new ElementHolder(); | 2468 ElementHolder holder = new ElementHolder(); |
| 6631 ElementBuilder builder = new ElementBuilder(holder); | 2469 ElementBuilder builder = _makeBuilder(holder); |
| 6632 String variableName = "v"; | 2470 String variableName = "v"; |
| 6633 VariableDeclaration variableDeclaration = | 2471 VariableDeclaration variableDeclaration = |
| 6634 AstFactory.variableDeclaration2(variableName, null); | 2472 AstFactory.variableDeclaration2(variableName, null); |
| 6635 AstFactory.variableDeclarationList2(null, [variableDeclaration]); | 2473 AstFactory.variableDeclarationList2(null, [variableDeclaration]); |
| 6636 variableDeclaration.accept(builder); | 2474 variableDeclaration.accept(builder); |
| 6637 | 2475 |
| 6638 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 2476 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
| 6639 expect(variables, hasLength(1)); | 2477 expect(variables, hasLength(1)); |
| 6640 TopLevelVariableElement variable = variables[0]; | 2478 TopLevelVariableElement variable = variables[0]; |
| 6641 expect(variable, isNotNull); | 2479 expect(variable, isNotNull); |
| 6642 expect(variable.hasImplicitType, isTrue); | 2480 expect(variable.hasImplicitType, isTrue); |
| 6643 expect(variable.initializer, isNull); | 2481 expect(variable.initializer, isNull); |
| 6644 expect(variable.name, variableName); | 2482 expect(variable.name, variableName); |
| 6645 expect(variable.isConst, isFalse); | 2483 expect(variable.isConst, isFalse); |
| 6646 expect(variable.isFinal, isFalse); | 2484 expect(variable.isFinal, isFalse); |
| 6647 expect(variable.isSynthetic, isFalse); | 2485 expect(variable.isSynthetic, isFalse); |
| 6648 expect(variable.getter, isNotNull); | 2486 expect(variable.getter, isNotNull); |
| 6649 expect(variable.setter, isNotNull); | 2487 expect(variable.setter, isNotNull); |
| 6650 } | 2488 } |
| 6651 | 2489 |
| 6652 void test_visitVariableDeclaration_top_const_hasInitializer() { | 2490 void test_visitVariableDeclaration_top() { |
| 6653 // const v = 42; | |
| 6654 ElementHolder holder = new ElementHolder(); | |
| 6655 ElementBuilder builder = new ElementBuilder(holder); | |
| 6656 String variableName = "v"; | |
| 6657 VariableDeclaration variableDeclaration = | |
| 6658 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); | |
| 6659 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); | |
| 6660 variableDeclaration.accept(builder); | |
| 6661 | |
| 6662 List<TopLevelVariableElement> variables = holder.topLevelVariables; | |
| 6663 expect(variables, hasLength(1)); | |
| 6664 TopLevelVariableElement variable = variables[0]; | |
| 6665 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); | |
| 6666 expect(variable.initializer, isNotNull); | |
| 6667 expect(variable.name, variableName); | |
| 6668 expect(variable.hasImplicitType, isTrue); | |
| 6669 expect(variable.isConst, isTrue); | |
| 6670 expect(variable.isFinal, isFalse); | |
| 6671 expect(variable.isSynthetic, isFalse); | |
| 6672 expect(variable.getter, isNotNull); | |
| 6673 expect(variable.setter, isNull); | |
| 6674 } | |
| 6675 | |
| 6676 void test_visitVariableDeclaration_top_docRange() { | |
| 6677 // final a, b; | 2491 // final a, b; |
| 6678 ElementHolder holder = new ElementHolder(); | 2492 ElementHolder holder = new ElementHolder(); |
| 6679 ElementBuilder builder = new ElementBuilder(holder); | 2493 ElementBuilder builder = _makeBuilder(holder); |
| 6680 VariableDeclaration variableDeclaration1 = | 2494 VariableDeclaration variableDeclaration1 = |
| 6681 AstFactory.variableDeclaration('a'); | 2495 AstFactory.variableDeclaration('a'); |
| 6682 VariableDeclaration variableDeclaration2 = | 2496 VariableDeclaration variableDeclaration2 = |
| 6683 AstFactory.variableDeclaration('b'); | 2497 AstFactory.variableDeclaration('b'); |
| 6684 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory | 2498 TopLevelVariableDeclaration topLevelVariableDeclaration = AstFactory |
| 6685 .topLevelVariableDeclaration( | 2499 .topLevelVariableDeclaration( |
| 6686 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]); | 2500 Keyword.FINAL, null, [variableDeclaration1, variableDeclaration2]); |
| 6687 topLevelVariableDeclaration.documentationComment = AstFactory | 2501 topLevelVariableDeclaration.documentationComment = AstFactory |
| 6688 .documentationComment( | 2502 .documentationComment( |
| 6689 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); | 2503 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 6690 | 2504 |
| 6691 topLevelVariableDeclaration.accept(builder); | 2505 topLevelVariableDeclaration.accept(builder); |
| 6692 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 2506 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
| 6693 expect(variables, hasLength(2)); | 2507 expect(variables, hasLength(2)); |
| 6694 | 2508 |
| 6695 TopLevelVariableElement variable1 = variables[0]; | 2509 TopLevelVariableElement variable1 = variables[0]; |
| 6696 expect(variable1, isNotNull); | 2510 expect(variable1, isNotNull); |
| 6697 _assertHasDocRange(variable1, 50, 7); | 2511 expect(variable1.documentationComment, '/// aaa'); |
| 6698 | 2512 |
| 6699 TopLevelVariableElement variable2 = variables[1]; | 2513 TopLevelVariableElement variable2 = variables[1]; |
| 6700 expect(variable2, isNotNull); | 2514 expect(variable2, isNotNull); |
| 6701 _assertHasDocRange(variable2, 50, 7); | 2515 expect(variable2.documentationComment, '/// aaa'); |
| 2516 } |
| 2517 |
| 2518 void test_visitVariableDeclaration_top_const_hasInitializer() { |
| 2519 // const v = 42; |
| 2520 ElementHolder holder = new ElementHolder(); |
| 2521 ElementBuilder builder = _makeBuilder(holder); |
| 2522 String variableName = "v"; |
| 2523 VariableDeclaration variableDeclaration = |
| 2524 AstFactory.variableDeclaration2(variableName, AstFactory.integer(42)); |
| 2525 AstFactory.variableDeclarationList2(Keyword.CONST, [variableDeclaration]); |
| 2526 variableDeclaration.accept(builder); |
| 2527 |
| 2528 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
| 2529 expect(variables, hasLength(1)); |
| 2530 TopLevelVariableElement variable = variables[0]; |
| 2531 expect(variable, new isInstanceOf<ConstTopLevelVariableElementImpl>()); |
| 2532 expect(variable.initializer, isNotNull); |
| 2533 expect(variable.initializer.type, isNotNull); |
| 2534 expect(variable.initializer.hasImplicitReturnType, isTrue); |
| 2535 expect(variable.name, variableName); |
| 2536 expect(variable.hasImplicitType, isTrue); |
| 2537 expect(variable.isConst, isTrue); |
| 2538 expect(variable.isFinal, isFalse); |
| 2539 expect(variable.isSynthetic, isFalse); |
| 2540 expect(variable.getter, isNotNull); |
| 2541 expect(variable.setter, isNull); |
| 6702 } | 2542 } |
| 6703 | 2543 |
| 6704 void test_visitVariableDeclaration_top_final() { | 2544 void test_visitVariableDeclaration_top_final() { |
| 6705 // final v; | 2545 // final v; |
| 6706 ElementHolder holder = new ElementHolder(); | 2546 ElementHolder holder = new ElementHolder(); |
| 6707 ElementBuilder builder = new ElementBuilder(holder); | 2547 ElementBuilder builder = _makeBuilder(holder); |
| 6708 String variableName = "v"; | 2548 String variableName = "v"; |
| 6709 VariableDeclaration variableDeclaration = | 2549 VariableDeclaration variableDeclaration = |
| 6710 AstFactory.variableDeclaration2(variableName, null); | 2550 AstFactory.variableDeclaration2(variableName, null); |
| 6711 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); | 2551 AstFactory.variableDeclarationList2(Keyword.FINAL, [variableDeclaration]); |
| 6712 variableDeclaration.accept(builder); | 2552 variableDeclaration.accept(builder); |
| 6713 List<TopLevelVariableElement> variables = holder.topLevelVariables; | 2553 List<TopLevelVariableElement> variables = holder.topLevelVariables; |
| 6714 expect(variables, hasLength(1)); | 2554 expect(variables, hasLength(1)); |
| 6715 TopLevelVariableElement variable = variables[0]; | 2555 TopLevelVariableElement variable = variables[0]; |
| 6716 expect(variable, isNotNull); | 2556 expect(variable, isNotNull); |
| 6717 expect(variable.hasImplicitType, isTrue); | 2557 expect(variable.hasImplicitType, isTrue); |
| 6718 expect(variable.initializer, isNull); | 2558 expect(variable.initializer, isNull); |
| 6719 expect(variable.name, variableName); | 2559 expect(variable.name, variableName); |
| 6720 expect(variable.isConst, isFalse); | 2560 expect(variable.isConst, isFalse); |
| 6721 expect(variable.isFinal, isTrue); | 2561 expect(variable.isFinal, isTrue); |
| 6722 expect(variable.isSynthetic, isFalse); | 2562 expect(variable.isSynthetic, isFalse); |
| 6723 expect(variable.getter, isNotNull); | 2563 expect(variable.getter, isNotNull); |
| 6724 expect(variable.setter, isNull); | 2564 expect(variable.setter, isNull); |
| 6725 } | 2565 } |
| 6726 | 2566 |
| 6727 void _assertHasDocRange( | 2567 void _assertHasCodeRange(Element element, int offset, int length) { |
| 6728 Element element, int expectedOffset, int expectedLength) { | 2568 ElementImpl elementImpl = element; |
| 6729 SourceRange docRange = element.docRange; | 2569 expect(elementImpl.codeOffset, offset); |
| 6730 expect(docRange, isNotNull); | 2570 expect(elementImpl.codeLength, length); |
| 6731 expect(docRange.offset, expectedOffset); | 2571 } |
| 6732 expect(docRange.length, expectedLength); | 2572 |
| 2573 void _assertVisibleRange(LocalElement element, int offset, int end) { |
| 2574 SourceRange visibleRange = element.visibleRange; |
| 2575 expect(visibleRange.offset, offset); |
| 2576 expect(visibleRange.end, end); |
| 2577 } |
| 2578 |
| 2579 ElementBuilder _makeBuilder(ElementHolder holder) => |
| 2580 new ElementBuilder(holder, new CompilationUnitElementImpl('test.dart')); |
| 2581 |
| 2582 void _setBlockBodySourceRange(BlockFunctionBody body, int offset, int end) { |
| 2583 _setNodeSourceRange(body.block, offset, end); |
| 2584 } |
| 2585 |
| 2586 void _setNodeSourceRange(AstNode node, int offset, int end) { |
| 2587 node.beginToken.offset = offset; |
| 2588 Token endToken = node.endToken; |
| 2589 endToken.offset = end - endToken.length; |
| 6733 } | 2590 } |
| 6734 | 2591 |
| 6735 void _useParameterInMethod( | 2592 void _useParameterInMethod( |
| 6736 FormalParameter formalParameter, int blockOffset, int blockEnd) { | 2593 FormalParameter formalParameter, int blockOffset, int blockEnd) { |
| 6737 Block block = AstFactory.block(); | 2594 Block block = AstFactory.block(); |
| 6738 block.leftBracket.offset = blockOffset; | 2595 block.leftBracket.offset = blockOffset; |
| 6739 block.rightBracket.offset = blockEnd - 1; | 2596 block.rightBracket.offset = blockEnd - 1; |
| 6740 BlockFunctionBody body = AstFactory.blockFunctionBody(block); | 2597 BlockFunctionBody body = AstFactory.blockFunctionBody(block); |
| 6741 AstFactory.methodDeclaration2( | 2598 AstFactory.methodDeclaration2( |
| 6742 null, | 2599 null, |
| 6743 null, | 2600 null, |
| 6744 null, | 2601 null, |
| 6745 null, | 2602 null, |
| 6746 AstFactory.identifier3("main"), | 2603 AstFactory.identifier3("main"), |
| 6747 AstFactory.formalParameterList([formalParameter]), | 2604 AstFactory.formalParameterList([formalParameter]), |
| 6748 body); | 2605 body); |
| 6749 } | 2606 } |
| 6750 } | 2607 } |
| 6751 | 2608 |
| 6752 @reflectiveTest | 2609 @reflectiveTest |
| 6753 class ElementLocatorTest extends ResolverTestCase { | 2610 class ElementLocatorTest extends ResolverTestCase { |
| 6754 void fail_locate_ExportDirective() { | |
| 6755 AstNode id = _findNodeIn("export", "export 'dart:core';"); | |
| 6756 Element element = ElementLocator.locate(id); | |
| 6757 EngineTestCase.assertInstanceOf( | |
| 6758 (obj) => obj is ImportElement, ImportElement, element); | |
| 6759 } | |
| 6760 | |
| 6761 void fail_locate_Identifier_libraryDirective() { | |
| 6762 AstNode id = _findNodeIn("foo", "library foo.bar;"); | |
| 6763 Element element = ElementLocator.locate(id); | |
| 6764 EngineTestCase.assertInstanceOf( | |
| 6765 (obj) => obj is LibraryElement, LibraryElement, element); | |
| 6766 } | |
| 6767 | |
| 6768 void fail_locate_Identifier_partOfDirective() { | 2611 void fail_locate_Identifier_partOfDirective() { |
| 6769 // Can't resolve the library element without the library declaration. | 2612 // Can't resolve the library element without the library declaration. |
| 6770 // AstNode id = findNodeIn("foo", "part of foo.bar;"); | 2613 // AstNode id = findNodeIn("foo", "part of foo.bar;"); |
| 6771 // Element element = ElementLocator.locate(id); | 2614 // Element element = ElementLocator.locate(id); |
| 6772 // assertInstanceOf(LibraryElement.class, element); | 2615 // assertInstanceOf(LibraryElement.class, element); |
| 6773 fail("Test this case"); | 2616 fail("Test this case"); |
| 6774 } | 2617 } |
| 6775 | 2618 |
| 6776 @override | 2619 @override |
| 6777 void reset() { | 2620 void reset() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6822 class A { | 2665 class A { |
| 6823 A.bar() {} | 2666 A.bar() {} |
| 6824 }'''); | 2667 }'''); |
| 6825 ConstructorDeclaration declaration = | 2668 ConstructorDeclaration declaration = |
| 6826 id.getAncestor((node) => node is ConstructorDeclaration); | 2669 id.getAncestor((node) => node is ConstructorDeclaration); |
| 6827 Element element = ElementLocator.locate(declaration); | 2670 Element element = ElementLocator.locate(declaration); |
| 6828 EngineTestCase.assertInstanceOf( | 2671 EngineTestCase.assertInstanceOf( |
| 6829 (obj) => obj is ConstructorElement, ConstructorElement, element); | 2672 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 6830 } | 2673 } |
| 6831 | 2674 |
| 2675 void test_locate_ExportDirective() { |
| 2676 AstNode id = _findNodeIn("export", "export 'dart:core';"); |
| 2677 Element element = ElementLocator.locate(id); |
| 2678 EngineTestCase.assertInstanceOf( |
| 2679 (obj) => obj is ExportElement, ExportElement, element); |
| 2680 } |
| 2681 |
| 6832 void test_locate_FunctionDeclaration() { | 2682 void test_locate_FunctionDeclaration() { |
| 6833 AstNode id = _findNodeIn("f", "int f() => 3;"); | 2683 AstNode id = _findNodeIn("f", "int f() => 3;"); |
| 6834 FunctionDeclaration declaration = | 2684 FunctionDeclaration declaration = |
| 6835 id.getAncestor((node) => node is FunctionDeclaration); | 2685 id.getAncestor((node) => node is FunctionDeclaration); |
| 6836 Element element = ElementLocator.locate(declaration); | 2686 Element element = ElementLocator.locate(declaration); |
| 6837 EngineTestCase.assertInstanceOf( | 2687 EngineTestCase.assertInstanceOf( |
| 6838 (obj) => obj is FunctionElement, FunctionElement, element); | 2688 (obj) => obj is FunctionElement, FunctionElement, element); |
| 6839 } | 2689 } |
| 6840 | 2690 |
| 6841 void test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPa
rameter() { | 2691 void |
| 2692 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { |
| 6842 AstNode id = _findNodeIndexedIn( | 2693 AstNode id = _findNodeIndexedIn( |
| 6843 "Class", | 2694 "Class", |
| 6844 2, | 2695 2, |
| 6845 r''' | 2696 r''' |
| 6846 class Class { | 2697 class Class { |
| 6847 const Class.name(); | 2698 const Class.name(); |
| 6848 } | 2699 } |
| 6849 void main(@Class.name() parameter) { | 2700 void main(@Class.name() parameter) { |
| 6850 }'''); | 2701 }'''); |
| 6851 Element element = ElementLocator.locate(id); | 2702 Element element = ElementLocator.locate(id); |
| 6852 EngineTestCase.assertInstanceOf( | 2703 EngineTestCase.assertInstanceOf( |
| 6853 (obj) => obj is ClassElement, ClassElement, element); | 2704 (obj) => obj is ClassElement, ClassElement, element); |
| 6854 } | 2705 } |
| 6855 | 2706 |
| 6856 void test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormal
Parameter() { | 2707 void |
| 2708 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { |
| 6857 AstNode id = _findNodeIndexedIn( | 2709 AstNode id = _findNodeIndexedIn( |
| 6858 "Class", | 2710 "Class", |
| 6859 2, | 2711 2, |
| 6860 r''' | 2712 r''' |
| 6861 class Class { | 2713 class Class { |
| 6862 const Class(); | 2714 const Class(); |
| 6863 } | 2715 } |
| 6864 void main(@Class() parameter) { | 2716 void main(@Class() parameter) { |
| 6865 }'''); | 2717 }'''); |
| 6866 Element element = ElementLocator.locate(id); | 2718 Element element = ElementLocator.locate(id); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6901 (obj) => obj is ConstructorElement, ConstructorElement, element); | 2753 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 6902 } | 2754 } |
| 6903 | 2755 |
| 6904 void test_locate_Identifier_fieldName() { | 2756 void test_locate_Identifier_fieldName() { |
| 6905 AstNode id = _findNodeIn("x", "class A { var x; }"); | 2757 AstNode id = _findNodeIn("x", "class A { var x; }"); |
| 6906 Element element = ElementLocator.locate(id); | 2758 Element element = ElementLocator.locate(id); |
| 6907 EngineTestCase.assertInstanceOf( | 2759 EngineTestCase.assertInstanceOf( |
| 6908 (obj) => obj is FieldElement, FieldElement, element); | 2760 (obj) => obj is FieldElement, FieldElement, element); |
| 6909 } | 2761 } |
| 6910 | 2762 |
| 6911 void test_locate_Identifier_propertAccess() { | 2763 void test_locate_Identifier_libraryDirective() { |
| 2764 AstNode id = _findNodeIn("foo", "library foo.bar;"); |
| 2765 Element element = ElementLocator.locate(id); |
| 2766 EngineTestCase.assertInstanceOf( |
| 2767 (obj) => obj is LibraryElement, LibraryElement, element); |
| 2768 } |
| 2769 |
| 2770 void test_locate_Identifier_propertyAccess() { |
| 6912 AstNode id = _findNodeIn( | 2771 AstNode id = _findNodeIn( |
| 6913 "length", | 2772 "length", |
| 6914 r''' | 2773 r''' |
| 6915 void main() { | 2774 void main() { |
| 6916 int x = 'foo'.length; | 2775 int x = 'foo'.length; |
| 6917 }'''); | 2776 }'''); |
| 6918 Element element = ElementLocator.locate(id); | 2777 Element element = ElementLocator.locate(id); |
| 6919 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, | 2778 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, |
| 6920 PropertyAccessorElement, element); | 2779 PropertyAccessorElement, element); |
| 6921 } | 2780 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6953 Element element = ElementLocator.locate(node); | 2812 Element element = ElementLocator.locate(node); |
| 6954 EngineTestCase.assertInstanceOf( | 2813 EngineTestCase.assertInstanceOf( |
| 6955 (obj) => obj is ConstructorElement, ConstructorElement, element); | 2814 (obj) => obj is ConstructorElement, ConstructorElement, element); |
| 6956 } | 2815 } |
| 6957 | 2816 |
| 6958 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { | 2817 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { |
| 6959 // prepare: new pref.A() | 2818 // prepare: new pref.A() |
| 6960 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 2819 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6961 PrefixedIdentifier prefixedIdentifier = | 2820 PrefixedIdentifier prefixedIdentifier = |
| 6962 AstFactory.identifier4("pref", identifier); | 2821 AstFactory.identifier4("pref", identifier); |
| 6963 InstanceCreationExpression creation = AstFactory | 2822 InstanceCreationExpression creation = |
| 6964 .instanceCreationExpression2( | 2823 AstFactory.instanceCreationExpression2( |
| 6965 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); | 2824 Keyword.NEW, AstFactory.typeName3(prefixedIdentifier)); |
| 6966 // set ClassElement | 2825 // set ClassElement |
| 6967 ClassElement classElement = ElementFactory.classElement2("A"); | 2826 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6968 identifier.staticElement = classElement; | 2827 identifier.staticElement = classElement; |
| 6969 // set ConstructorElement | 2828 // set ConstructorElement |
| 6970 ConstructorElement constructorElement = | 2829 ConstructorElement constructorElement = |
| 6971 ElementFactory.constructorElement2(classElement, null); | 2830 ElementFactory.constructorElement2(classElement, null); |
| 6972 creation.constructorName.staticElement = constructorElement; | 2831 creation.constructorName.staticElement = constructorElement; |
| 6973 // verify that "A" is resolved to ConstructorElement | 2832 // verify that "A" is resolved to ConstructorElement |
| 6974 Element element = ElementLocator.locate(identifier); | 2833 Element element = ElementLocator.locate(identifier); |
| 6975 expect(element, same(classElement)); | 2834 expect(element, same(classElement)); |
| 6976 } | 2835 } |
| 6977 | 2836 |
| 6978 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { | 2837 void test_locate_InstanceCreationExpression_type_simpleIdentifier() { |
| 6979 // prepare: new A() | 2838 // prepare: new A() |
| 6980 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 2839 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| 6981 InstanceCreationExpression creation = AstFactory | 2840 InstanceCreationExpression creation = |
| 6982 .instanceCreationExpression2( | 2841 AstFactory.instanceCreationExpression2( |
| 6983 Keyword.NEW, AstFactory.typeName3(identifier)); | 2842 Keyword.NEW, AstFactory.typeName3(identifier)); |
| 6984 // set ClassElement | 2843 // set ClassElement |
| 6985 ClassElement classElement = ElementFactory.classElement2("A"); | 2844 ClassElement classElement = ElementFactory.classElement2("A"); |
| 6986 identifier.staticElement = classElement; | 2845 identifier.staticElement = classElement; |
| 6987 // set ConstructorElement | 2846 // set ConstructorElement |
| 6988 ConstructorElement constructorElement = | 2847 ConstructorElement constructorElement = |
| 6989 ElementFactory.constructorElement2(classElement, null); | 2848 ElementFactory.constructorElement2(classElement, null); |
| 6990 creation.constructorName.staticElement = constructorElement; | 2849 creation.constructorName.staticElement = constructorElement; |
| 6991 // verify that "A" is resolved to ConstructorElement | 2850 // verify that "A" is resolved to ConstructorElement |
| 6992 Element element = ElementLocator.locate(identifier); | 2851 Element element = ElementLocator.locate(identifier); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7157 CompilationUnit cu = _resolveContents(code); | 3016 CompilationUnit cu = _resolveContents(code); |
| 7158 int start = _getOffsetOfMatch(code, nodePattern, index); | 3017 int start = _getOffsetOfMatch(code, nodePattern, index); |
| 7159 int end = start + nodePattern.length; | 3018 int end = start + nodePattern.length; |
| 7160 return new NodeLocator(start, end).searchWithin(cu); | 3019 return new NodeLocator(start, end).searchWithin(cu); |
| 7161 } | 3020 } |
| 7162 | 3021 |
| 7163 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { | 3022 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { |
| 7164 if (matchIndex == 0) { | 3023 if (matchIndex == 0) { |
| 7165 return contents.indexOf(pattern); | 3024 return contents.indexOf(pattern); |
| 7166 } | 3025 } |
| 7167 JavaPatternMatcher matcher = | 3026 Iterable<Match> matches = new RegExp(pattern).allMatches(contents); |
| 7168 new JavaPatternMatcher(new RegExp(pattern), contents); | 3027 Match match = matches.toList()[matchIndex]; |
| 7169 int count = 0; | 3028 return match.start; |
| 7170 while (matcher.find()) { | |
| 7171 if (count == matchIndex) { | |
| 7172 return matcher.start(); | |
| 7173 } | |
| 7174 ++count; | |
| 7175 } | |
| 7176 return -1; | |
| 7177 } | 3029 } |
| 7178 | 3030 |
| 7179 /** | 3031 /** |
| 7180 * Parse, resolve and verify the given source lines to produce a fully | 3032 * Parse, resolve and verify the given source lines to produce a fully |
| 7181 * resolved AST. | 3033 * resolved AST. |
| 7182 * | 3034 * |
| 7183 * [code] the code to resolve. | 3035 * [code] the code to resolve. |
| 7184 * | 3036 * |
| 7185 * Returns the result of resolving the AST structure representing the content | 3037 * Returns the result of resolving the AST structure representing the content |
| 7186 * of the source. | 3038 * of the source. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7228 expect(constant.name, thirdName); | 3080 expect(constant.name, thirdName); |
| 7229 expect(constant.isStatic, isTrue); | 3081 expect(constant.isStatic, isTrue); |
| 7230 expect((constant as FieldElementImpl).evaluationResult, isNotNull); | 3082 expect((constant as FieldElementImpl).evaluationResult, isNotNull); |
| 7231 _assertGetter(constant); | 3083 _assertGetter(constant); |
| 7232 } | 3084 } |
| 7233 | 3085 |
| 7234 void test_visitEnumDeclaration_single() { | 3086 void test_visitEnumDeclaration_single() { |
| 7235 String firstName = "ONE"; | 3087 String firstName = "ONE"; |
| 7236 EnumDeclaration enumDeclaration = | 3088 EnumDeclaration enumDeclaration = |
| 7237 AstFactory.enumDeclaration2("E", [firstName]); | 3089 AstFactory.enumDeclaration2("E", [firstName]); |
| 3090 enumDeclaration.constants[0].documentationComment = AstFactory |
| 3091 .documentationComment( |
| 3092 [TokenFactory.tokenFromString('/// aaa')..offset = 50], []); |
| 7238 | 3093 |
| 7239 ClassElement enumElement = _buildElement(enumDeclaration); | 3094 ClassElement enumElement = _buildElement(enumDeclaration); |
| 7240 List<FieldElement> fields = enumElement.fields; | 3095 List<FieldElement> fields = enumElement.fields; |
| 7241 expect(fields, hasLength(3)); | 3096 expect(fields, hasLength(3)); |
| 7242 | 3097 |
| 7243 FieldElement field = fields[0]; | 3098 FieldElement field = fields[0]; |
| 7244 expect(field, isNotNull); | 3099 expect(field, isNotNull); |
| 7245 expect(field.name, "index"); | 3100 expect(field.name, "index"); |
| 7246 expect(field.isStatic, isFalse); | 3101 expect(field.isStatic, isFalse); |
| 7247 expect(field.isSynthetic, isTrue); | 3102 expect(field.isSynthetic, isTrue); |
| 7248 _assertGetter(field); | 3103 _assertGetter(field); |
| 7249 | 3104 |
| 7250 field = fields[1]; | 3105 field = fields[1]; |
| 7251 expect(field, isNotNull); | 3106 expect(field, isNotNull); |
| 7252 expect(field.name, "values"); | 3107 expect(field.name, "values"); |
| 7253 expect(field.isStatic, isTrue); | 3108 expect(field.isStatic, isTrue); |
| 7254 expect(field.isSynthetic, isTrue); | 3109 expect(field.isSynthetic, isTrue); |
| 7255 expect((field as FieldElementImpl).evaluationResult, isNotNull); | 3110 expect((field as FieldElementImpl).evaluationResult, isNotNull); |
| 7256 _assertGetter(field); | 3111 _assertGetter(field); |
| 7257 | 3112 |
| 7258 FieldElement constant = fields[2]; | 3113 FieldElement constant = fields[2]; |
| 7259 expect(constant, isNotNull); | 3114 expect(constant, isNotNull); |
| 7260 expect(constant.name, firstName); | 3115 expect(constant.name, firstName); |
| 7261 expect(constant.isStatic, isTrue); | 3116 expect(constant.isStatic, isTrue); |
| 7262 expect((constant as FieldElementImpl).evaluationResult, isNotNull); | 3117 expect((constant as FieldElementImpl).evaluationResult, isNotNull); |
| 3118 expect(constant.documentationComment, '/// aaa'); |
| 7263 _assertGetter(constant); | 3119 _assertGetter(constant); |
| 7264 } | 3120 } |
| 7265 | 3121 |
| 7266 void _assertGetter(FieldElement field) { | 3122 void _assertGetter(FieldElement field) { |
| 7267 PropertyAccessorElement getter = field.getter; | 3123 PropertyAccessorElement getter = field.getter; |
| 7268 expect(getter, isNotNull); | 3124 expect(getter, isNotNull); |
| 7269 expect(getter.variable, same(field)); | 3125 expect(getter.variable, same(field)); |
| 7270 expect(getter.type, isNotNull); | 3126 expect(getter.type, isNotNull); |
| 7271 } | 3127 } |
| 7272 | 3128 |
| 7273 ClassElement _buildElement(EnumDeclaration enumDeclaration) { | 3129 ClassElement _buildElement(EnumDeclaration enumDeclaration) { |
| 7274 ElementHolder holder = new ElementHolder(); | 3130 ElementHolder holder = new ElementHolder(); |
| 7275 ElementBuilder elementBuilder = new ElementBuilder(holder); | 3131 ElementBuilder elementBuilder = _makeBuilder(holder); |
| 7276 enumDeclaration.accept(elementBuilder); | 3132 enumDeclaration.accept(elementBuilder); |
| 7277 EnumMemberBuilder memberBuilder = | 3133 EnumMemberBuilder memberBuilder = |
| 7278 new EnumMemberBuilder(new TestTypeProvider()); | 3134 new EnumMemberBuilder(new TestTypeProvider()); |
| 7279 enumDeclaration.accept(memberBuilder); | 3135 enumDeclaration.accept(memberBuilder); |
| 7280 List<ClassElement> enums = holder.enums; | 3136 List<ClassElement> enums = holder.enums; |
| 7281 expect(enums, hasLength(1)); | 3137 expect(enums, hasLength(1)); |
| 7282 return enums[0]; | 3138 return enums[0]; |
| 7283 } | 3139 } |
| 3140 |
| 3141 ElementBuilder _makeBuilder(ElementHolder holder) => |
| 3142 new ElementBuilder(holder, new CompilationUnitElementImpl('test.dart')); |
| 7284 } | 3143 } |
| 7285 | 3144 |
| 7286 @reflectiveTest | 3145 @reflectiveTest |
| 7287 class ErrorReporterTest extends EngineTestCase { | 3146 class ErrorReporterTest extends EngineTestCase { |
| 7288 /** | 3147 /** |
| 7289 * Create a type with the given name in a compilation unit with the given name
. | 3148 * Create a type with the given name in a compilation unit with the given name
. |
| 7290 * | 3149 * |
| 7291 * @param fileName the name of the compilation unit containing the class | 3150 * @param fileName the name of the compilation unit containing the class |
| 7292 * @param typeName the name of the type to be created | 3151 * @param typeName the name of the type to be created |
| 7293 * @return the type that was created | 3152 * @return the type that was created |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7327 new NonExistingSource( | 3186 new NonExistingSource( |
| 7328 '/test.dart', toUri('/test.dart'), UriKind.FILE_URI)); | 3187 '/test.dart', toUri('/test.dart'), UriKind.FILE_URI)); |
| 7329 reporter.reportErrorForElement( | 3188 reporter.reportErrorForElement( |
| 7330 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, | 3189 StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_MEMBER, |
| 7331 element, | 3190 element, |
| 7332 ['A']); | 3191 ['A']); |
| 7333 AnalysisError error = listener.errors[0]; | 3192 AnalysisError error = listener.errors[0]; |
| 7334 expect(error.offset, element.nameOffset); | 3193 expect(error.offset, element.nameOffset); |
| 7335 } | 3194 } |
| 7336 | 3195 |
| 3196 void test_reportErrorForSpan() { |
| 3197 GatheringErrorListener listener = new GatheringErrorListener(); |
| 3198 ErrorReporter reporter = new ErrorReporter(listener, new TestSource()); |
| 3199 |
| 3200 var src = ''' |
| 3201 foo: bar |
| 3202 zap: baz |
| 3203 '''; |
| 3204 |
| 3205 int offset = src.indexOf('baz'); |
| 3206 int length = 'baz'.length; |
| 3207 |
| 3208 SourceSpan span = new SourceFile(src).span(offset, offset + length); |
| 3209 |
| 3210 reporter.reportErrorForSpan( |
| 3211 AnalysisOptionsWarningCode.UNSUPPORTED_OPTION_WITH_LEGAL_VALUE, |
| 3212 span, |
| 3213 ['test', 'zip', 'zap']); |
| 3214 expect(listener.errors, hasLength(1)); |
| 3215 expect(listener.errors.first.offset, offset); |
| 3216 expect(listener.errors.first.length, length); |
| 3217 } |
| 3218 |
| 7337 void test_reportTypeErrorForNode_differentNames() { | 3219 void test_reportTypeErrorForNode_differentNames() { |
| 7338 DartType firstType = createType("/test1.dart", "A"); | 3220 DartType firstType = createType("/test1.dart", "A"); |
| 7339 DartType secondType = createType("/test2.dart", "B"); | 3221 DartType secondType = createType("/test2.dart", "B"); |
| 7340 GatheringErrorListener listener = new GatheringErrorListener(); | 3222 GatheringErrorListener listener = new GatheringErrorListener(); |
| 7341 ErrorReporter reporter = | 3223 ErrorReporter reporter = |
| 7342 new ErrorReporter(listener, firstType.element.source); | 3224 new ErrorReporter(listener, firstType.element.source); |
| 7343 reporter.reportTypeErrorForNode( | 3225 reporter.reportTypeErrorForNode( |
| 7344 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, | 3226 StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, |
| 7345 AstFactory.identifier3("x"), | 3227 AstFactory.identifier3("x"), |
| 7346 [firstType, secondType]); | 3228 [firstType, secondType]); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7412 } | 3294 } |
| 7413 } | 3295 } |
| 7414 | 3296 |
| 7415 /** | 3297 /** |
| 7416 * Tests for the [ExitDetector] that do not require that the AST be resolved. | 3298 * Tests for the [ExitDetector] that do not require that the AST be resolved. |
| 7417 * | 3299 * |
| 7418 * See [ExitDetectorTest2] for tests that require the AST to be resolved. | 3300 * See [ExitDetectorTest2] for tests that require the AST to be resolved. |
| 7419 */ | 3301 */ |
| 7420 @reflectiveTest | 3302 @reflectiveTest |
| 7421 class ExitDetectorTest extends ParserTestCase { | 3303 class ExitDetectorTest extends ParserTestCase { |
| 7422 void fail_doStatement_continue_with_label() { | |
| 7423 _assertFalse("{ x: do { continue x; } while(true); }"); | |
| 7424 } | |
| 7425 | |
| 7426 void fail_whileStatement_continue_with_label() { | |
| 7427 _assertFalse("{ x: while (true) { continue x; } }"); | |
| 7428 } | |
| 7429 | |
| 7430 void fail_whileStatement_doStatement_scopeRequired() { | |
| 7431 _assertTrue("{ while (true) { x: do { continue x; } while(true); }"); | |
| 7432 } | |
| 7433 | |
| 7434 void test_asExpression() { | 3304 void test_asExpression() { |
| 7435 _assertFalse("a as Object;"); | 3305 _assertFalse("a as Object;"); |
| 7436 } | 3306 } |
| 7437 | 3307 |
| 7438 void test_asExpression_throw() { | 3308 void test_asExpression_throw() { |
| 7439 _assertTrue("throw '' as Object;"); | 3309 _assertTrue("throw '' as Object;"); |
| 7440 } | 3310 } |
| 7441 | 3311 |
| 7442 void test_assertStatement() { | 3312 void test_assertStatement() { |
| 7443 _assertFalse("assert(a);"); | 3313 _assertFalse("assert(a);"); |
| 7444 } | 3314 } |
| 7445 | 3315 |
| 7446 void test_assertStatement_throw() { | 3316 void test_assertStatement_throw() { |
| 7447 _assertFalse("assert((throw 0));"); | 3317 _assertFalse("assert((throw 0));"); |
| 7448 } | 3318 } |
| 7449 | 3319 |
| 7450 void test_assignmentExpression() { | 3320 void test_assignmentExpression() { |
| 7451 _assertFalse("v = 1;"); | 3321 _assertFalse("v = 1;"); |
| 7452 } | 3322 } |
| 7453 | 3323 |
| 3324 void test_assignmentExpression_compound_lazy() { |
| 3325 enableLazyAssignmentOperators = true; |
| 3326 _assertFalse("v ||= false;"); |
| 3327 } |
| 3328 |
| 7454 void test_assignmentExpression_lhs_throw() { | 3329 void test_assignmentExpression_lhs_throw() { |
| 7455 _assertTrue("a[throw ''] = 0;"); | 3330 _assertTrue("a[throw ''] = 0;"); |
| 7456 } | 3331 } |
| 7457 | 3332 |
| 7458 void test_assignmentExpression_rhs_throw() { | 3333 void test_assignmentExpression_rhs_throw() { |
| 7459 _assertTrue("v = throw '';"); | 3334 _assertTrue("v = throw '';"); |
| 7460 } | 3335 } |
| 7461 | 3336 |
| 7462 void test_await_false() { | 3337 void test_await_false() { |
| 7463 _assertFalse("await x;"); | 3338 _assertFalse("await x;"); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7624 } | 3499 } |
| 7625 | 3500 |
| 7626 void test_conditionalCall_rhs2() { | 3501 void test_conditionalCall_rhs2() { |
| 7627 _assertFalse("null?.b(throw '');"); | 3502 _assertFalse("null?.b(throw '');"); |
| 7628 } | 3503 } |
| 7629 | 3504 |
| 7630 void test_creation() { | 3505 void test_creation() { |
| 7631 expect(new ExitDetector(), isNotNull); | 3506 expect(new ExitDetector(), isNotNull); |
| 7632 } | 3507 } |
| 7633 | 3508 |
| 3509 void test_doStatement_break_and_throw() { |
| 3510 _assertFalse("{ do { if (1==1) break; throw 'T'; } while (0==1); }"); |
| 3511 } |
| 3512 |
| 3513 void test_doStatement_continue_and_throw() { |
| 3514 _assertFalse("{ do { if (1==1) continue; throw 'T'; } while (0==1); }"); |
| 3515 } |
| 3516 |
| 3517 void test_doStatement_continueDoInSwitch_and_throw() { |
| 3518 _assertFalse(''' |
| 3519 { |
| 3520 D: do { |
| 3521 switch (1) { |
| 3522 L: case 0: continue D; |
| 3523 M: case 1: break; |
| 3524 } |
| 3525 throw 'T'; |
| 3526 } while (0 == 1); |
| 3527 }'''); |
| 3528 } |
| 3529 |
| 3530 void test_doStatement_continueInSwitch_and_throw() { |
| 3531 _assertFalse(''' |
| 3532 { |
| 3533 do { |
| 3534 switch (1) { |
| 3535 L: case 0: continue; |
| 3536 M: case 1: break; |
| 3537 } |
| 3538 throw 'T'; |
| 3539 } while (0 == 1); |
| 3540 }'''); |
| 3541 } |
| 3542 |
| 3543 void test_doStatement_return() { |
| 3544 _assertTrue("{ do { return null; } while (1 == 2); }"); |
| 3545 } |
| 3546 |
| 7634 void test_doStatement_throwCondition() { | 3547 void test_doStatement_throwCondition() { |
| 7635 _assertTrue("{ do {} while (throw ''); }"); | 3548 _assertTrue("{ do {} while (throw ''); }"); |
| 7636 } | 3549 } |
| 7637 | 3550 |
| 7638 void test_doStatement_true_break() { | 3551 void test_doStatement_true_break() { |
| 7639 _assertFalse("{ do { break; } while (true); }"); | 3552 _assertFalse("{ do { break; } while (true); }"); |
| 7640 } | 3553 } |
| 7641 | 3554 |
| 7642 void test_doStatement_true_continue() { | 3555 void test_doStatement_true_continue() { |
| 7643 _assertTrue("{ do { continue; } while (true); }"); | 3556 _assertTrue("{ do { continue; } while (true); }"); |
| 7644 } | 3557 } |
| 7645 | 3558 |
| 3559 void test_doStatement_true_continueWithLabel() { |
| 3560 _assertTrue("{ x: do { continue x; } while (true); }"); |
| 3561 } |
| 3562 |
| 7646 void test_doStatement_true_if_return() { | 3563 void test_doStatement_true_if_return() { |
| 7647 _assertTrue("{ do { if (true) {return null;} } while (true); }"); | 3564 _assertTrue("{ do { if (true) {return null;} } while (true); }"); |
| 7648 } | 3565 } |
| 7649 | 3566 |
| 7650 void test_doStatement_true_noBreak() { | 3567 void test_doStatement_true_noBreak() { |
| 7651 _assertTrue("{ do {} while (true); }"); | 3568 _assertTrue("{ do {} while (true); }"); |
| 7652 } | 3569 } |
| 7653 | 3570 |
| 7654 void test_doStatement_true_return() { | 3571 void test_doStatement_true_return() { |
| 7655 _assertTrue("{ do { return null; } while (true); }"); | 3572 _assertTrue("{ do { return null; } while (true); }"); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 7672 } | 3589 } |
| 7673 | 3590 |
| 7674 void test_forStatement_implicitTrue() { | 3591 void test_forStatement_implicitTrue() { |
| 7675 _assertTrue("for (;;) {}"); | 3592 _assertTrue("for (;;) {}"); |
| 7676 } | 3593 } |
| 7677 | 3594 |
| 7678 void test_forStatement_implicitTrue_break() { | 3595 void test_forStatement_implicitTrue_break() { |
| 7679 _assertFalse("for (;;) { break; }"); | 3596 _assertFalse("for (;;) { break; }"); |
| 7680 } | 3597 } |
| 7681 | 3598 |
| 3599 void test_forStatement_implicitTrue_if_break() { |
| 3600 _assertFalse("{ for (;;) { if (1==2) { var a = 1; } else { break; } } }"); |
| 3601 } |
| 3602 |
| 7682 void test_forStatement_initialization() { | 3603 void test_forStatement_initialization() { |
| 7683 _assertTrue("for (i = throw 0;;) {}"); | 3604 _assertTrue("for (i = throw 0;;) {}"); |
| 7684 } | 3605 } |
| 7685 | 3606 |
| 7686 void test_forStatement_true() { | 3607 void test_forStatement_true() { |
| 7687 _assertTrue("for (; true; ) {}"); | 3608 _assertTrue("for (; true; ) {}"); |
| 7688 } | 3609 } |
| 7689 | 3610 |
| 7690 void test_forStatement_true_break() { | 3611 void test_forStatement_true_break() { |
| 7691 _assertFalse("{ for (; true; ) { break; } }"); | 3612 _assertFalse("{ for (; true; ) { break; } }"); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7896 } | 3817 } |
| 7897 | 3818 |
| 7898 void test_switch_fallThroughToNotReturn() { | 3819 void test_switch_fallThroughToNotReturn() { |
| 7899 _assertFalse("switch (i) { case 0: case 1: break; default: return 1; }"); | 3820 _assertFalse("switch (i) { case 0: case 1: break; default: return 1; }"); |
| 7900 } | 3821 } |
| 7901 | 3822 |
| 7902 void test_switch_fallThroughToReturn() { | 3823 void test_switch_fallThroughToReturn() { |
| 7903 _assertTrue("switch (i) { case 0: case 1: return 0; default: return 1; }"); | 3824 _assertTrue("switch (i) { case 0: case 1: return 0; default: return 1; }"); |
| 7904 } | 3825 } |
| 7905 | 3826 |
| 3827 // The ExitDetector could conceivably follow switch continue labels and |
| 3828 // determine that `case 0` exits, `case 1` continues to an exiting case, and |
| 3829 // `default` exits, so the switch exits. |
| 3830 @failingTest |
| 3831 void test_switch_includesContinue() { |
| 3832 _assertTrue(''' |
| 3833 switch (i) { |
| 3834 zero: case 0: return 0; |
| 3835 case 1: continue zero; |
| 3836 default: return 1; |
| 3837 }'''); |
| 3838 } |
| 3839 |
| 7906 void test_switch_noDefault() { | 3840 void test_switch_noDefault() { |
| 7907 _assertFalse("switch (i) { case 0: return 0; }"); | 3841 _assertFalse("switch (i) { case 0: return 0; }"); |
| 7908 } | 3842 } |
| 7909 | 3843 |
| 7910 void test_switch_nonReturn() { | 3844 void test_switch_nonReturn() { |
| 7911 _assertFalse("switch (i) { case 0: i++; default: return 1; }"); | 3845 _assertFalse("switch (i) { case 0: i++; default: return 1; }"); |
| 7912 } | 3846 } |
| 7913 | 3847 |
| 7914 void test_thisExpression() { | 3848 void test_thisExpression() { |
| 7915 _assertFalse("this.a;"); | 3849 _assertFalse("this.a;"); |
| 7916 } | 3850 } |
| 7917 | 3851 |
| 7918 void test_throwExpression() { | 3852 void test_throwExpression() { |
| 7919 _assertTrue("throw new Object();"); | 3853 _assertTrue("throw new Object();"); |
| 7920 } | 3854 } |
| 7921 | 3855 |
| 7922 void test_tryStatement_noReturn() { | 3856 void test_tryStatement_noReturn() { |
| 7923 _assertFalse("try {} catch (e, s) {} finally {}"); | 3857 _assertFalse("try {} catch (e, s) {} finally {}"); |
| 7924 } | 3858 } |
| 7925 | 3859 |
| 3860 void test_tryStatement_noReturn_noFinally() { |
| 3861 _assertFalse("try {} catch (e, s) {}"); |
| 3862 } |
| 3863 |
| 7926 void test_tryStatement_return_catch() { | 3864 void test_tryStatement_return_catch() { |
| 7927 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); | 3865 _assertFalse("try {} catch (e, s) { return 1; } finally {}"); |
| 7928 } | 3866 } |
| 7929 | 3867 |
| 3868 void test_tryStatement_return_catch_noFinally() { |
| 3869 _assertFalse("try {} catch (e, s) { return 1; }"); |
| 3870 } |
| 3871 |
| 7930 void test_tryStatement_return_finally() { | 3872 void test_tryStatement_return_finally() { |
| 7931 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); | 3873 _assertTrue("try {} catch (e, s) {} finally { return 1; }"); |
| 7932 } | 3874 } |
| 7933 | 3875 |
| 7934 void test_tryStatement_return_try() { | 3876 void test_tryStatement_return_try_noCatch() { |
| 7935 _assertTrue("try { return 1; } catch (e, s) {} finally {}"); | 3877 _assertTrue("try { return 1; } finally {}"); |
| 3878 } |
| 3879 |
| 3880 void test_tryStatement_return_try_oneCatchDoesNotExit() { |
| 3881 _assertFalse("try { return 1; } catch (e, s) {} finally {}"); |
| 3882 } |
| 3883 |
| 3884 void test_tryStatement_return_try_oneCatchDoesNotExit_noFinally() { |
| 3885 _assertFalse("try { return 1; } catch (e, s) {}"); |
| 3886 } |
| 3887 |
| 3888 void test_tryStatement_return_try_oneCatchExits() { |
| 3889 _assertTrue("try { return 1; } catch (e, s) { return 1; } finally {}"); |
| 3890 } |
| 3891 |
| 3892 void test_tryStatement_return_try_oneCatchExits_noFinally() { |
| 3893 _assertTrue("try { return 1; } catch (e, s) { return 1; }"); |
| 3894 } |
| 3895 |
| 3896 void test_tryStatement_return_try_twoCatchesDoExit() { |
| 3897 _assertTrue(''' |
| 3898 try { return 1; } |
| 3899 on int catch (e, s) { return 1; } |
| 3900 on String catch (e, s) { return 1; } |
| 3901 finally {}'''); |
| 3902 } |
| 3903 |
| 3904 void test_tryStatement_return_try_twoCatchesDoExit_noFinally() { |
| 3905 _assertTrue(''' |
| 3906 try { return 1; } |
| 3907 on int catch (e, s) { return 1; } |
| 3908 on String catch (e, s) { return 1; }'''); |
| 3909 } |
| 3910 |
| 3911 void test_tryStatement_return_try_twoCatchesDoNotExit() { |
| 3912 _assertFalse(''' |
| 3913 try { return 1; } |
| 3914 on int catch (e, s) {} |
| 3915 on String catch (e, s) {} |
| 3916 finally {}'''); |
| 3917 } |
| 3918 |
| 3919 void test_tryStatement_return_try_twoCatchesDoNotExit_noFinally() { |
| 3920 _assertFalse(''' |
| 3921 try { return 1; } |
| 3922 on int catch (e, s) {} |
| 3923 on String catch (e, s) {}'''); |
| 3924 } |
| 3925 |
| 3926 void test_tryStatement_return_try_twoCatchesMixed() { |
| 3927 _assertFalse(''' |
| 3928 try { return 1; } |
| 3929 on int catch (e, s) {} |
| 3930 on String catch (e, s) { return 1; } |
| 3931 finally {}'''); |
| 3932 } |
| 3933 |
| 3934 void test_tryStatement_return_try_twoCatchesMixed_noFinally() { |
| 3935 _assertFalse(''' |
| 3936 try { return 1; } |
| 3937 on int catch (e, s) {} |
| 3938 on String catch (e, s) { return 1; }'''); |
| 7936 } | 3939 } |
| 7937 | 3940 |
| 7938 void test_variableDeclarationStatement_noInitializer() { | 3941 void test_variableDeclarationStatement_noInitializer() { |
| 7939 _assertFalse("int i;"); | 3942 _assertFalse("int i;"); |
| 7940 } | 3943 } |
| 7941 | 3944 |
| 7942 void test_variableDeclarationStatement_noThrow() { | 3945 void test_variableDeclarationStatement_noThrow() { |
| 7943 _assertFalse("int i = 0;"); | 3946 _assertFalse("int i = 0;"); |
| 7944 } | 3947 } |
| 7945 | 3948 |
| 7946 void test_variableDeclarationStatement_throw() { | 3949 void test_variableDeclarationStatement_throw() { |
| 7947 _assertTrue("int i = throw new Object();"); | 3950 _assertTrue("int i = throw new Object();"); |
| 7948 } | 3951 } |
| 7949 | 3952 |
| 7950 void test_whileStatement_false_nonReturn() { | 3953 void test_whileStatement_false_nonReturn() { |
| 7951 _assertFalse("{ while (false) {} }"); | 3954 _assertFalse("{ while (false) {} }"); |
| 7952 } | 3955 } |
| 7953 | 3956 |
| 7954 void test_whileStatement_throwCondition() { | 3957 void test_whileStatement_throwCondition() { |
| 7955 _assertTrue("{ while (throw '') {} }"); | 3958 _assertTrue("{ while (throw '') {} }"); |
| 7956 } | 3959 } |
| 7957 | 3960 |
| 7958 void test_whileStatement_true_break() { | 3961 void test_whileStatement_true_break() { |
| 7959 _assertFalse("{ while (true) { break; } }"); | 3962 _assertFalse("{ while (true) { break; } }"); |
| 7960 } | 3963 } |
| 7961 | 3964 |
| 3965 void test_whileStatement_true_break_and_throw() { |
| 3966 _assertFalse("{ while (true) { if (1==1) break; throw 'T'; } }"); |
| 3967 } |
| 3968 |
| 7962 void test_whileStatement_true_continue() { | 3969 void test_whileStatement_true_continue() { |
| 7963 _assertTrue("{ while (true) { continue; } }"); | 3970 _assertTrue("{ while (true) { continue; } }"); |
| 7964 } | 3971 } |
| 7965 | 3972 |
| 3973 void test_whileStatement_true_continueWithLabel() { |
| 3974 _assertTrue("{ x: while (true) { continue x; } }"); |
| 3975 } |
| 3976 |
| 3977 void test_whileStatement_true_doStatement_scopeRequired() { |
| 3978 _assertTrue("{ while (true) { x: do { continue x; } while (true); } }"); |
| 3979 } |
| 3980 |
| 7966 void test_whileStatement_true_if_return() { | 3981 void test_whileStatement_true_if_return() { |
| 7967 _assertTrue("{ while (true) { if (true) {return null;} } }"); | 3982 _assertTrue("{ while (true) { if (true) {return null;} } }"); |
| 7968 } | 3983 } |
| 7969 | 3984 |
| 7970 void test_whileStatement_true_noBreak() { | 3985 void test_whileStatement_true_noBreak() { |
| 7971 _assertTrue("{ while (true) {} }"); | 3986 _assertTrue("{ while (true) {} }"); |
| 7972 } | 3987 } |
| 7973 | 3988 |
| 7974 void test_whileStatement_true_return() { | 3989 void test_whileStatement_true_return() { |
| 7975 _assertTrue("{ while (true) { return null; } }"); | 3990 _assertTrue("{ while (true) { return null; } }"); |
| 7976 } | 3991 } |
| 7977 | 3992 |
| 7978 void test_whileStatement_true_throw() { | 3993 void test_whileStatement_true_throw() { |
| 7979 _assertTrue("{ while (true) { throw ''; } }"); | 3994 _assertTrue("{ while (true) { throw ''; } }"); |
| 7980 } | 3995 } |
| 7981 | 3996 |
| 7982 void _assertFalse(String source) { | 3997 void _assertFalse(String source) { |
| 7983 _assertHasReturn(false, source); | 3998 _assertHasReturn(false, source); |
| 7984 } | 3999 } |
| 7985 | 4000 |
| 7986 void _assertHasReturn(bool expectedResult, String source) { | 4001 void _assertHasReturn(bool expectedResult, String source) { |
| 7987 Statement statement = ParserTestCase.parseStatement(source); | 4002 Statement statement = ParserTestCase.parseStatement( |
| 4003 source, [], enableLazyAssignmentOperators); |
| 7988 expect(ExitDetector.exits(statement), expectedResult); | 4004 expect(ExitDetector.exits(statement), expectedResult); |
| 7989 } | 4005 } |
| 7990 | 4006 |
| 7991 void _assertTrue(String source) { | 4007 void _assertTrue(String source) { |
| 7992 _assertHasReturn(true, source); | 4008 _assertHasReturn(true, source); |
| 7993 } | 4009 } |
| 7994 } | 4010 } |
| 7995 | 4011 |
| 7996 /** | 4012 /** |
| 7997 * Tests for the [ExitDetector] that require that the AST be resolved. | 4013 * Tests for the [ExitDetector] that require that the AST be resolved. |
| 7998 * | 4014 * |
| 7999 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. | 4015 * See [ExitDetectorTest] for tests that do not require the AST to be resolved. |
| 8000 */ | 4016 */ |
| 8001 @reflectiveTest | 4017 @reflectiveTest |
| 8002 class ExitDetectorTest2 extends ResolverTestCase { | 4018 class ExitDetectorTest2 extends ResolverTestCase { |
| 4019 void test_forStatement_implicitTrue_breakWithLabel() { |
| 4020 Source source = addSource(r''' |
| 4021 void f() { |
| 4022 x: for (;;) { |
| 4023 if (1 < 2) { |
| 4024 break x; |
| 4025 } |
| 4026 return; |
| 4027 } |
| 4028 } |
| 4029 '''); |
| 4030 _assertNthStatementDoesNotExit(source, 0); |
| 4031 } |
| 4032 |
| 8003 void test_switch_withEnum_false_noDefault() { | 4033 void test_switch_withEnum_false_noDefault() { |
| 8004 Source source = addSource(r''' | 4034 Source source = addSource(r''' |
| 8005 enum E { A, B } | 4035 enum E { A, B } |
| 8006 String f(E e) { | 4036 String f(E e) { |
| 8007 var x; | 4037 var x; |
| 8008 switch (e) { | 4038 switch (e) { |
| 8009 case A: | 4039 case A: |
| 8010 x = 'A'; | 4040 x = 'A'; |
| 8011 case B: | 4041 case B: |
| 8012 x = 'B'; | 4042 x = 'B'; |
| 8013 } | 4043 } |
| 8014 return x; | 4044 return x; |
| 8015 } | 4045 } |
| 8016 '''); | 4046 '''); |
| 8017 LibraryElement element = resolve2(source); | 4047 _assertNthStatementDoesNotExit(source, 1); |
| 8018 CompilationUnit unit = resolveCompilationUnit(source, element); | |
| 8019 FunctionDeclaration function = unit.declarations.last; | |
| 8020 BlockFunctionBody body = function.functionExpression.body; | |
| 8021 Statement statement = body.block.statements[1]; | |
| 8022 expect(ExitDetector.exits(statement), false); | |
| 8023 } | 4048 } |
| 8024 | 4049 |
| 8025 void test_switch_withEnum_false_withDefault() { | 4050 void test_switch_withEnum_false_withDefault() { |
| 8026 Source source = addSource(r''' | 4051 Source source = addSource(r''' |
| 8027 enum E { A, B } | 4052 enum E { A, B } |
| 8028 String f(E e) { | 4053 String f(E e) { |
| 8029 var x; | 4054 var x; |
| 8030 switch (e) { | 4055 switch (e) { |
| 8031 case A: | 4056 case A: |
| 8032 x = 'A'; | 4057 x = 'A'; |
| 8033 default: | 4058 default: |
| 8034 x = '?'; | 4059 x = '?'; |
| 8035 } | 4060 } |
| 8036 return x; | 4061 return x; |
| 8037 } | 4062 } |
| 8038 '''); | 4063 '''); |
| 8039 LibraryElement element = resolve2(source); | 4064 _assertNthStatementDoesNotExit(source, 1); |
| 8040 CompilationUnit unit = resolveCompilationUnit(source, element); | |
| 8041 FunctionDeclaration function = unit.declarations.last; | |
| 8042 BlockFunctionBody body = function.functionExpression.body; | |
| 8043 Statement statement = body.block.statements[1]; | |
| 8044 expect(ExitDetector.exits(statement), false); | |
| 8045 } | 4065 } |
| 8046 | 4066 |
| 8047 void test_switch_withEnum_true_noDefault() { | 4067 void test_switch_withEnum_true_noDefault() { |
| 8048 Source source = addSource(r''' | 4068 Source source = addSource(r''' |
| 8049 enum E { A, B } | 4069 enum E { A, B } |
| 8050 String f(E e) { | 4070 String f(E e) { |
| 8051 switch (e) { | 4071 switch (e) { |
| 8052 case A: | 4072 case A: |
| 8053 return 'A'; | 4073 return 'A'; |
| 8054 case B: | 4074 case B: |
| 8055 return 'B'; | 4075 return 'B'; |
| 8056 } | 4076 } |
| 8057 } | 4077 } |
| 8058 '''); | 4078 '''); |
| 8059 LibraryElement element = resolve2(source); | 4079 _assertNthStatementDoesNotExit(source, 0); |
| 8060 CompilationUnit unit = resolveCompilationUnit(source, element); | 4080 } |
| 8061 FunctionDeclaration function = unit.declarations.last; | 4081 |
| 8062 BlockFunctionBody body = function.functionExpression.body; | 4082 void test_switch_withEnum_true_withExitingDefault() { |
| 8063 Statement statement = body.block.statements[0]; | |
| 8064 expect(ExitDetector.exits(statement), true); | |
| 8065 } | |
| 8066 | |
| 8067 void test_switch_withEnum_true_withDefault() { | |
| 8068 Source source = addSource(r''' | 4083 Source source = addSource(r''' |
| 8069 enum E { A, B } | 4084 enum E { A, B } |
| 8070 String f(E e) { | 4085 String f(E e) { |
| 8071 switch (e) { | 4086 switch (e) { |
| 8072 case A: | 4087 case A: |
| 8073 return 'A'; | 4088 return 'A'; |
| 8074 default: | 4089 default: |
| 8075 return '?'; | 4090 return '?'; |
| 8076 } | 4091 } |
| 8077 } | 4092 } |
| 8078 '''); | 4093 '''); |
| 4094 _assertNthStatementExits(source, 0); |
| 4095 } |
| 4096 |
| 4097 void test_switch_withEnum_true_withNonExitingDefault() { |
| 4098 Source source = addSource(r''' |
| 4099 enum E { A, B } |
| 4100 String f(E e) { |
| 4101 var x; |
| 4102 switch (e) { |
| 4103 case A: |
| 4104 return 'A'; |
| 4105 default: |
| 4106 x = '?'; |
| 4107 } |
| 4108 } |
| 4109 '''); |
| 4110 _assertNthStatementDoesNotExit(source, 1); |
| 4111 } |
| 4112 |
| 4113 void test_whileStatement_breakWithLabel() { |
| 4114 Source source = addSource(r''' |
| 4115 void f() { |
| 4116 x: while (true) { |
| 4117 if (1 < 2) { |
| 4118 break x; |
| 4119 } |
| 4120 return; |
| 4121 } |
| 4122 } |
| 4123 '''); |
| 4124 _assertNthStatementDoesNotExit(source, 0); |
| 4125 } |
| 4126 |
| 4127 void test_whileStatement_breakWithLabel_afterExiting() { |
| 4128 Source source = addSource(r''' |
| 4129 void f() { |
| 4130 x: while (true) { |
| 4131 return; |
| 4132 if (1 < 2) { |
| 4133 break x; |
| 4134 } |
| 4135 } |
| 4136 } |
| 4137 '''); |
| 4138 _assertNthStatementExits(source, 0); |
| 4139 } |
| 4140 |
| 4141 void test_whileStatement_switchWithBreakWithLabel() { |
| 4142 Source source = addSource(r''' |
| 4143 void f() { |
| 4144 x: while (true) { |
| 4145 switch (true) { |
| 4146 case false: break; |
| 4147 case true: break x; |
| 4148 } |
| 4149 } |
| 4150 } |
| 4151 '''); |
| 4152 _assertNthStatementDoesNotExit(source, 0); |
| 4153 } |
| 4154 |
| 4155 void test_yieldStatement_plain() { |
| 4156 Source source = addSource(r''' |
| 4157 void f() sync* { |
| 4158 yield 1; |
| 4159 } |
| 4160 '''); |
| 4161 _assertNthStatementDoesNotExit(source, 0); |
| 4162 } |
| 4163 |
| 4164 void test_yieldStatement_star_plain() { |
| 4165 Source source = addSource(r''' |
| 4166 void f() sync* { |
| 4167 yield* 1; |
| 4168 } |
| 4169 '''); |
| 4170 _assertNthStatementDoesNotExit(source, 0); |
| 4171 } |
| 4172 |
| 4173 void test_yieldStatement_star_throw() { |
| 4174 Source source = addSource(r''' |
| 4175 void f() sync* { |
| 4176 yield* throw ''; |
| 4177 } |
| 4178 '''); |
| 4179 _assertNthStatementExits(source, 0); |
| 4180 } |
| 4181 |
| 4182 void test_yieldStatement_throw() { |
| 4183 Source source = addSource(r''' |
| 4184 void f() sync* { |
| 4185 yield throw ''; |
| 4186 } |
| 4187 '''); |
| 4188 _assertNthStatementExits(source, 0); |
| 4189 } |
| 4190 |
| 4191 void _assertHasReturn(bool expectedResult, Source source, int n) { |
| 8079 LibraryElement element = resolve2(source); | 4192 LibraryElement element = resolve2(source); |
| 8080 CompilationUnit unit = resolveCompilationUnit(source, element); | 4193 CompilationUnit unit = resolveCompilationUnit(source, element); |
| 8081 FunctionDeclaration function = unit.declarations.last; | 4194 FunctionDeclaration function = unit.declarations.last; |
| 8082 BlockFunctionBody body = function.functionExpression.body; | 4195 BlockFunctionBody body = function.functionExpression.body; |
| 8083 Statement statement = body.block.statements[0]; | 4196 Statement statement = body.block.statements[n]; |
| 8084 expect(ExitDetector.exits(statement), true); | 4197 expect(ExitDetector.exits(statement), expectedResult); |
| 4198 } |
| 4199 |
| 4200 // Assert that the [n]th statement in the last function declaration of |
| 4201 // [source] exits. |
| 4202 void _assertNthStatementDoesNotExit(Source source, int n) { |
| 4203 _assertHasReturn(false, source, n); |
| 4204 } |
| 4205 |
| 4206 // Assert that the [n]th statement in the last function declaration of |
| 4207 // [source] does not exit. |
| 4208 void _assertNthStatementExits(Source source, int n) { |
| 4209 _assertHasReturn(true, source, n); |
| 8085 } | 4210 } |
| 8086 } | 4211 } |
| 8087 | 4212 |
| 8088 @reflectiveTest | 4213 @reflectiveTest |
| 8089 class FileBasedSourceTest { | 4214 class FileBasedSourceTest { |
| 8090 void test_equals_false_differentFiles() { | 4215 void test_equals_false_differentFiles() { |
| 8091 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); | 4216 JavaFile file1 = FileUtilities2.createFile("/does/not/exist1.dart"); |
| 8092 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); | 4217 JavaFile file2 = FileUtilities2.createFile("/does/not/exist2.dart"); |
| 8093 FileBasedSource source1 = new FileBasedSource(file1); | 4218 FileBasedSource source1 = new FileBasedSource(file1); |
| 8094 FileBasedSource source2 = new FileBasedSource(file2); | 4219 FileBasedSource source2 = new FileBasedSource(file2); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8145 | 4270 |
| 8146 // '\r' -> '\n' as first, last and only character | 4271 // '\r' -> '\n' as first, last and only character |
| 8147 expect(FileBasedSource.fileReadMode('\r'), '\n'); | 4272 expect(FileBasedSource.fileReadMode('\r'), '\n'); |
| 8148 expect(FileBasedSource.fileReadMode('a\r'), 'a\n'); | 4273 expect(FileBasedSource.fileReadMode('a\r'), 'a\n'); |
| 8149 expect(FileBasedSource.fileReadMode('\ra'), '\na'); | 4274 expect(FileBasedSource.fileReadMode('\ra'), '\na'); |
| 8150 | 4275 |
| 8151 FileBasedSource.fileReadMode = (String s) => s; | 4276 FileBasedSource.fileReadMode = (String s) => s; |
| 8152 } | 4277 } |
| 8153 | 4278 |
| 8154 void test_getEncoding() { | 4279 void test_getEncoding() { |
| 8155 SourceFactory factory = new SourceFactory([new FileUriResolver()]); | 4280 SourceFactory factory = new SourceFactory( |
| 4281 [new ResourceUriResolver(PhysicalResourceProvider.INSTANCE)]); |
| 8156 String fullPath = "/does/not/exist.dart"; | 4282 String fullPath = "/does/not/exist.dart"; |
| 8157 JavaFile file = FileUtilities2.createFile(fullPath); | 4283 JavaFile file = FileUtilities2.createFile(fullPath); |
| 8158 FileBasedSource source = new FileBasedSource(file); | 4284 FileBasedSource source = new FileBasedSource(file); |
| 8159 expect(factory.fromEncoding(source.encoding), source); | 4285 expect(factory.fromEncoding(source.encoding), source); |
| 8160 } | 4286 } |
| 8161 | 4287 |
| 8162 void test_getFullName() { | 4288 void test_getFullName() { |
| 8163 String fullPath = "/does/not/exist.dart"; | 4289 String fullPath = "/does/not/exist.dart"; |
| 8164 JavaFile file = FileUtilities2.createFile(fullPath); | 4290 JavaFile file = FileUtilities2.createFile(fullPath); |
| 8165 FileBasedSource source = new FileBasedSource(file); | 4291 FileBasedSource source = new FileBasedSource(file); |
| 8166 expect(source.fullName, file.getAbsolutePath()); | 4292 expect(source.fullName, file.getAbsolutePath()); |
| 8167 } | 4293 } |
| 8168 | 4294 |
| 8169 void test_getShortName() { | 4295 void test_getShortName() { |
| 8170 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 4296 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 8171 FileBasedSource source = new FileBasedSource(file); | 4297 FileBasedSource source = new FileBasedSource(file); |
| 8172 expect(source.shortName, "exist.dart"); | 4298 expect(source.shortName, "exist.dart"); |
| 8173 } | 4299 } |
| 8174 | 4300 |
| 8175 void test_hashCode() { | 4301 void test_hashCode() { |
| 8176 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); | 4302 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 8177 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); | 4303 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); |
| 8178 FileBasedSource source1 = new FileBasedSource(file1); | 4304 FileBasedSource source1 = new FileBasedSource(file1); |
| 8179 FileBasedSource source2 = new FileBasedSource(file2); | 4305 FileBasedSource source2 = new FileBasedSource(file2); |
| 8180 expect(source2.hashCode, source1.hashCode); | 4306 expect(source2.hashCode, source1.hashCode); |
| 8181 } | 4307 } |
| 8182 | 4308 |
| 8183 void test_isInSystemLibrary_contagious() { | 4309 void test_isInSystemLibrary_contagious() { |
| 8184 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 4310 DartSdk sdk = _createSdk(); |
| 8185 expect(sdkDirectory, isNotNull); | |
| 8186 DartSdk sdk = new DirectoryBasedDartSdk(sdkDirectory); | |
| 8187 UriResolver resolver = new DartUriResolver(sdk); | 4311 UriResolver resolver = new DartUriResolver(sdk); |
| 8188 SourceFactory factory = new SourceFactory([resolver]); | 4312 SourceFactory factory = new SourceFactory([resolver]); |
| 8189 // resolve dart:core | 4313 // resolve dart:core |
| 8190 Source result = | 4314 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); |
| 8191 resolver.resolveAbsolute(parseUriWithException("dart:core")); | |
| 8192 expect(result, isNotNull); | 4315 expect(result, isNotNull); |
| 8193 expect(result.isInSystemLibrary, isTrue); | 4316 expect(result.isInSystemLibrary, isTrue); |
| 8194 // system libraries reference only other system libraries | 4317 // system libraries reference only other system libraries |
| 8195 Source partSource = factory.resolveUri(result, "num.dart"); | 4318 Source partSource = factory.resolveUri(result, "num.dart"); |
| 8196 expect(partSource, isNotNull); | 4319 expect(partSource, isNotNull); |
| 8197 expect(partSource.isInSystemLibrary, isTrue); | 4320 expect(partSource.isInSystemLibrary, isTrue); |
| 8198 } | 4321 } |
| 8199 | 4322 |
| 8200 void test_isInSystemLibrary_false() { | 4323 void test_isInSystemLibrary_false() { |
| 8201 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 4324 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 8202 FileBasedSource source = new FileBasedSource(file); | 4325 FileBasedSource source = new FileBasedSource(file); |
| 8203 expect(source, isNotNull); | 4326 expect(source, isNotNull); |
| 8204 expect(source.fullName, file.getAbsolutePath()); | 4327 expect(source.fullName, file.getAbsolutePath()); |
| 8205 expect(source.isInSystemLibrary, isFalse); | 4328 expect(source.isInSystemLibrary, isFalse); |
| 8206 } | 4329 } |
| 8207 | 4330 |
| 8208 void test_issue14500() { | 4331 void test_issue14500() { |
| 8209 // see https://code.google.com/p/dart/issues/detail?id=14500 | 4332 // see https://code.google.com/p/dart/issues/detail?id=14500 |
| 8210 FileBasedSource source = new FileBasedSource( | 4333 FileBasedSource source = new FileBasedSource( |
| 8211 FileUtilities2.createFile("/some/packages/foo:bar.dart")); | 4334 FileUtilities2.createFile("/some/packages/foo:bar.dart")); |
| 8212 expect(source, isNotNull); | 4335 expect(source, isNotNull); |
| 8213 expect(source.exists(), isFalse); | 4336 expect(source.exists(), isFalse); |
| 8214 } | 4337 } |
| 8215 | 4338 |
| 8216 void test_resolveRelative_dart_fileName() { | |
| 8217 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8218 FileBasedSource source = | |
| 8219 new FileBasedSource(file, parseUriWithException("dart:test")); | |
| 8220 expect(source, isNotNull); | |
| 8221 Uri relative = source.resolveRelativeUri(parseUriWithException("lib.dart")); | |
| 8222 expect(relative, isNotNull); | |
| 8223 expect(relative.toString(), "dart:test/lib.dart"); | |
| 8224 } | |
| 8225 | |
| 8226 void test_resolveRelative_dart_filePath() { | |
| 8227 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8228 FileBasedSource source = | |
| 8229 new FileBasedSource(file, parseUriWithException("dart:test")); | |
| 8230 expect(source, isNotNull); | |
| 8231 Uri relative = | |
| 8232 source.resolveRelativeUri(parseUriWithException("c/lib.dart")); | |
| 8233 expect(relative, isNotNull); | |
| 8234 expect(relative.toString(), "dart:test/c/lib.dart"); | |
| 8235 } | |
| 8236 | |
| 8237 void test_resolveRelative_dart_filePathWithParent() { | |
| 8238 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8239 FileBasedSource source = new FileBasedSource( | |
| 8240 file, parseUriWithException("dart:test/b/test.dart")); | |
| 8241 expect(source, isNotNull); | |
| 8242 Uri relative = | |
| 8243 source.resolveRelativeUri(parseUriWithException("../c/lib.dart")); | |
| 8244 expect(relative, isNotNull); | |
| 8245 expect(relative.toString(), "dart:test/c/lib.dart"); | |
| 8246 } | |
| 8247 | |
| 8248 void test_resolveRelative_file_fileName() { | 4339 void test_resolveRelative_file_fileName() { |
| 8249 if (OSUtilities.isWindows()) { | 4340 if (OSUtilities.isWindows()) { |
| 8250 // On Windows, the URI that is produced includes a drive letter, | 4341 // On Windows, the URI that is produced includes a drive letter, |
| 8251 // which I believe is not consistent across all machines that might run | 4342 // which I believe is not consistent across all machines that might run |
| 8252 // this test. | 4343 // this test. |
| 8253 return; | 4344 return; |
| 8254 } | 4345 } |
| 8255 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 4346 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 8256 FileBasedSource source = new FileBasedSource(file); | 4347 FileBasedSource source = new FileBasedSource(file); |
| 8257 expect(source, isNotNull); | 4348 expect(source, isNotNull); |
| 8258 Uri relative = source.resolveRelativeUri(parseUriWithException("lib.dart")); | 4349 Uri relative = resolveRelativeUri(source.uri, Uri.parse("lib.dart")); |
| 8259 expect(relative, isNotNull); | 4350 expect(relative, isNotNull); |
| 8260 expect(relative.toString(), "file:///a/b/lib.dart"); | 4351 expect(relative.toString(), "file:///a/b/lib.dart"); |
| 8261 } | 4352 } |
| 8262 | 4353 |
| 8263 void test_resolveRelative_file_filePath() { | 4354 void test_resolveRelative_file_filePath() { |
| 8264 if (OSUtilities.isWindows()) { | 4355 if (OSUtilities.isWindows()) { |
| 8265 // On Windows, the URI that is produced includes a drive letter, | 4356 // On Windows, the URI that is produced includes a drive letter, |
| 8266 // which I believe is not consistent across all machines that might run | 4357 // which I believe is not consistent across all machines that might run |
| 8267 // this test. | 4358 // this test. |
| 8268 return; | 4359 return; |
| 8269 } | 4360 } |
| 8270 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 4361 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 8271 FileBasedSource source = new FileBasedSource(file); | 4362 FileBasedSource source = new FileBasedSource(file); |
| 8272 expect(source, isNotNull); | 4363 expect(source, isNotNull); |
| 8273 Uri relative = | 4364 Uri relative = resolveRelativeUri(source.uri, Uri.parse("c/lib.dart")); |
| 8274 source.resolveRelativeUri(parseUriWithException("c/lib.dart")); | |
| 8275 expect(relative, isNotNull); | 4365 expect(relative, isNotNull); |
| 8276 expect(relative.toString(), "file:///a/b/c/lib.dart"); | 4366 expect(relative.toString(), "file:///a/b/c/lib.dart"); |
| 8277 } | 4367 } |
| 8278 | 4368 |
| 8279 void test_resolveRelative_file_filePathWithParent() { | 4369 void test_resolveRelative_file_filePathWithParent() { |
| 8280 if (OSUtilities.isWindows()) { | 4370 if (OSUtilities.isWindows()) { |
| 8281 // On Windows, the URI that is produced includes a drive letter, which I | 4371 // On Windows, the URI that is produced includes a drive letter, which I |
| 8282 // believe is not consistent across all machines that might run this test. | 4372 // believe is not consistent across all machines that might run this test. |
| 8283 return; | 4373 return; |
| 8284 } | 4374 } |
| 8285 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | 4375 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); |
| 8286 FileBasedSource source = new FileBasedSource(file); | 4376 FileBasedSource source = new FileBasedSource(file); |
| 8287 expect(source, isNotNull); | 4377 expect(source, isNotNull); |
| 8288 Uri relative = | 4378 Uri relative = resolveRelativeUri(source.uri, Uri.parse("../c/lib.dart")); |
| 8289 source.resolveRelativeUri(parseUriWithException("../c/lib.dart")); | |
| 8290 expect(relative, isNotNull); | 4379 expect(relative, isNotNull); |
| 8291 expect(relative.toString(), "file:///a/c/lib.dart"); | 4380 expect(relative.toString(), "file:///a/c/lib.dart"); |
| 8292 } | 4381 } |
| 8293 | 4382 |
| 8294 void test_resolveRelative_package_fileName() { | |
| 8295 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8296 FileBasedSource source = | |
| 8297 new FileBasedSource(file, parseUriWithException("package:b/test.dart")); | |
| 8298 expect(source, isNotNull); | |
| 8299 Uri relative = source.resolveRelativeUri(parseUriWithException("lib.dart")); | |
| 8300 expect(relative, isNotNull); | |
| 8301 expect(relative.toString(), "package:b/lib.dart"); | |
| 8302 } | |
| 8303 | |
| 8304 void test_resolveRelative_package_fileNameWithoutPackageName() { | |
| 8305 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8306 FileBasedSource source = | |
| 8307 new FileBasedSource(file, parseUriWithException("package:test.dart")); | |
| 8308 expect(source, isNotNull); | |
| 8309 Uri relative = source.resolveRelativeUri(parseUriWithException("lib.dart")); | |
| 8310 expect(relative, isNotNull); | |
| 8311 expect(relative.toString(), "package:lib.dart"); | |
| 8312 } | |
| 8313 | |
| 8314 void test_resolveRelative_package_filePath() { | |
| 8315 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8316 FileBasedSource source = | |
| 8317 new FileBasedSource(file, parseUriWithException("package:b/test.dart")); | |
| 8318 expect(source, isNotNull); | |
| 8319 Uri relative = | |
| 8320 source.resolveRelativeUri(parseUriWithException("c/lib.dart")); | |
| 8321 expect(relative, isNotNull); | |
| 8322 expect(relative.toString(), "package:b/c/lib.dart"); | |
| 8323 } | |
| 8324 | |
| 8325 void test_resolveRelative_package_filePathWithParent() { | |
| 8326 JavaFile file = FileUtilities2.createFile("/a/b/test.dart"); | |
| 8327 FileBasedSource source = new FileBasedSource( | |
| 8328 file, parseUriWithException("package:a/b/test.dart")); | |
| 8329 expect(source, isNotNull); | |
| 8330 Uri relative = | |
| 8331 source.resolveRelativeUri(parseUriWithException("../c/lib.dart")); | |
| 8332 expect(relative, isNotNull); | |
| 8333 expect(relative.toString(), "package:a/c/lib.dart"); | |
| 8334 } | |
| 8335 | |
| 8336 void test_system() { | 4383 void test_system() { |
| 8337 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); | 4384 JavaFile file = FileUtilities2.createFile("/does/not/exist.dart"); |
| 8338 FileBasedSource source = | 4385 FileBasedSource source = new FileBasedSource(file, Uri.parse("dart:core")); |
| 8339 new FileBasedSource(file, parseUriWithException("dart:core")); | |
| 8340 expect(source, isNotNull); | 4386 expect(source, isNotNull); |
| 8341 expect(source.fullName, file.getAbsolutePath()); | 4387 expect(source.fullName, file.getAbsolutePath()); |
| 8342 expect(source.isInSystemLibrary, isTrue); | 4388 expect(source.isInSystemLibrary, isTrue); |
| 8343 } | 4389 } |
| 8344 } | 4390 } |
| 8345 | 4391 |
| 8346 @reflectiveTest | 4392 @reflectiveTest |
| 8347 class FileUriResolverTest { | 4393 class ResolveRelativeUriTest { |
| 8348 void test_creation() { | 4394 void test_resolveRelative_dart_dartUri() { |
| 8349 expect(new FileUriResolver(), isNotNull); | 4395 _assertResolve('dart:foo', 'dart:bar', 'dart:bar'); |
| 8350 } | 4396 } |
| 8351 | 4397 |
| 8352 void test_resolve_file() { | 4398 void test_resolveRelative_dart_fileName() { |
| 8353 UriResolver resolver = new FileUriResolver(); | 4399 _assertResolve('dart:test', 'lib.dart', 'dart:test/lib.dart'); |
| 8354 Source result = resolver | 4400 } |
| 8355 .resolveAbsolute(parseUriWithException("file:/does/not/exist.dart")); | 4401 |
| 4402 void test_resolveRelative_dart_filePath() { |
| 4403 _assertResolve('dart:test', 'c/lib.dart', 'dart:test/c/lib.dart'); |
| 4404 } |
| 4405 |
| 4406 void test_resolveRelative_dart_filePathWithParent() { |
| 4407 _assertResolve( |
| 4408 'dart:test/b/test.dart', '../c/lib.dart', 'dart:test/c/lib.dart'); |
| 4409 } |
| 4410 |
| 4411 void test_resolveRelative_package_dartUri() { |
| 4412 _assertResolve('package:foo/bar.dart', 'dart:test', 'dart:test'); |
| 4413 } |
| 4414 |
| 4415 void test_resolveRelative_package_emptyPath() { |
| 4416 _assertResolve('package:foo/bar.dart', '', 'package:foo/bar.dart'); |
| 4417 } |
| 4418 |
| 4419 void test_resolveRelative_package_fileName() { |
| 4420 _assertResolve('package:b/test.dart', 'lib.dart', 'package:b/lib.dart'); |
| 4421 } |
| 4422 |
| 4423 void test_resolveRelative_package_fileNameWithoutPackageName() { |
| 4424 _assertResolve('package:test.dart', 'lib.dart', 'package:lib.dart'); |
| 4425 } |
| 4426 |
| 4427 void test_resolveRelative_package_filePath() { |
| 4428 _assertResolve('package:b/test.dart', 'c/lib.dart', 'package:b/c/lib.dart'); |
| 4429 } |
| 4430 |
| 4431 void test_resolveRelative_package_filePathWithParent() { |
| 4432 _assertResolve( |
| 4433 'package:a/b/test.dart', '../c/lib.dart', 'package:a/c/lib.dart'); |
| 4434 } |
| 4435 |
| 4436 void _assertResolve(String baseStr, String containedStr, String expectedStr) { |
| 4437 Uri base = Uri.parse(baseStr); |
| 4438 Uri contained = Uri.parse(containedStr); |
| 4439 Uri result = resolveRelativeUri(base, contained); |
| 8356 expect(result, isNotNull); | 4440 expect(result, isNotNull); |
| 8357 expect(result.fullName, | 4441 expect(result.toString(), expectedStr); |
| 8358 FileUtilities2.createFile("/does/not/exist.dart").getAbsolutePath()); | 4442 } |
| 8359 } | 4443 } |
| 8360 | 4444 |
| 8361 void test_resolve_nonFile() { | 4445 @deprecated |
| 8362 UriResolver resolver = new FileUriResolver(); | |
| 8363 Source result = | |
| 8364 resolver.resolveAbsolute(parseUriWithException("dart:core")); | |
| 8365 expect(result, isNull); | |
| 8366 } | |
| 8367 | |
| 8368 void test_restore() { | |
| 8369 UriResolver resolver = new FileUriResolver(); | |
| 8370 Uri uri = parseUriWithException('file:///foo/bar.dart'); | |
| 8371 Source source = resolver.resolveAbsolute(uri); | |
| 8372 expect(source, isNotNull); | |
| 8373 expect(resolver.restoreAbsolute(source), uri); | |
| 8374 expect( | |
| 8375 resolver.restoreAbsolute( | |
| 8376 new NonExistingSource(source.fullName, null, null)), | |
| 8377 uri); | |
| 8378 } | |
| 8379 } | |
| 8380 | |
| 8381 @reflectiveTest | |
| 8382 class HtmlParserTest extends EngineTestCase { | |
| 8383 /** | |
| 8384 * The name of the 'script' tag in an HTML file. | |
| 8385 */ | |
| 8386 static String _TAG_SCRIPT = "script"; | |
| 8387 void fail_parse_scriptWithComment() { | |
| 8388 String scriptBody = r''' | |
| 8389 /** | |
| 8390 * <editable-label bind-value="dartAsignableValue"> | |
| 8391 * </editable-label> | |
| 8392 */ | |
| 8393 class Foo {}'''; | |
| 8394 ht.HtmlUnit htmlUnit = parse(""" | |
| 8395 <html> | |
| 8396 <body> | |
| 8397 <script type='application/dart'> | |
| 8398 $scriptBody | |
| 8399 </script> | |
| 8400 </body> | |
| 8401 </html>"""); | |
| 8402 _validate(htmlUnit, [ | |
| 8403 _t4("html", [ | |
| 8404 _t4("body", [ | |
| 8405 _t("script", _a(["type", "'application/dart'"]), scriptBody) | |
| 8406 ]) | |
| 8407 ]) | |
| 8408 ]); | |
| 8409 } | |
| 8410 | |
| 8411 ht.HtmlUnit parse(String contents) { | |
| 8412 // TestSource source = | |
| 8413 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents)
; | |
| 8414 ht.AbstractScanner scanner = new ht.StringScanner(null, contents); | |
| 8415 scanner.passThroughElements = <String>[_TAG_SCRIPT]; | |
| 8416 ht.Token token = scanner.tokenize(); | |
| 8417 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | |
| 8418 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 8419 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | |
| 8420 ht.HtmlUnit unit = | |
| 8421 new ht.HtmlParser(null, errorListener, options).parse(token, lineInfo); | |
| 8422 errorListener.assertNoErrors(); | |
| 8423 return unit; | |
| 8424 } | |
| 8425 | |
| 8426 void test_parse_attribute() { | |
| 8427 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>"); | |
| 8428 _validate(htmlUnit, [ | |
| 8429 _t4("html", [ | |
| 8430 _t("body", _a(["foo", "\"sdfsdf\""]), "") | |
| 8431 ]) | |
| 8432 ]); | |
| 8433 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; | |
| 8434 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; | |
| 8435 expect(bodyNode.attributes[0].text, "sdfsdf"); | |
| 8436 } | |
| 8437 | |
| 8438 void test_parse_attribute_EOF() { | |
| 8439 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\""); | |
| 8440 _validate(htmlUnit, [ | |
| 8441 _t4("html", [ | |
| 8442 _t("body", _a(["foo", "\"sdfsdf\""]), "") | |
| 8443 ]) | |
| 8444 ]); | |
| 8445 } | |
| 8446 | |
| 8447 void test_parse_attribute_EOF_missing_quote() { | |
| 8448 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsd"); | |
| 8449 _validate(htmlUnit, [ | |
| 8450 _t4("html", [ | |
| 8451 _t("body", _a(["foo", "\"sdfsd"]), "") | |
| 8452 ]) | |
| 8453 ]); | |
| 8454 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; | |
| 8455 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; | |
| 8456 expect(bodyNode.attributes[0].text, "sdfsd"); | |
| 8457 } | |
| 8458 | |
| 8459 void test_parse_attribute_extra_quote() { | |
| 8460 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"\"></body></html>"); | |
| 8461 _validate(htmlUnit, [ | |
| 8462 _t4("html", [ | |
| 8463 _t("body", _a(["foo", "\"sdfsdf\""]), "") | |
| 8464 ]) | |
| 8465 ]); | |
| 8466 } | |
| 8467 | |
| 8468 void test_parse_attribute_single_quote() { | |
| 8469 ht.HtmlUnit htmlUnit = parse("<html><body foo='sdfsdf'></body></html>"); | |
| 8470 _validate(htmlUnit, [ | |
| 8471 _t4("html", [ | |
| 8472 _t("body", _a(["foo", "'sdfsdf'"]), "") | |
| 8473 ]) | |
| 8474 ]); | |
| 8475 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; | |
| 8476 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; | |
| 8477 expect(bodyNode.attributes[0].text, "sdfsdf"); | |
| 8478 } | |
| 8479 | |
| 8480 void test_parse_comment_embedded() { | |
| 8481 ht.HtmlUnit htmlUnit = parse("<html <!-- comment -->></html>"); | |
| 8482 _validate(htmlUnit, [_t3("html", "")]); | |
| 8483 } | |
| 8484 | |
| 8485 void test_parse_comment_first() { | |
| 8486 ht.HtmlUnit htmlUnit = parse("<!-- comment --><html></html>"); | |
| 8487 _validate(htmlUnit, [_t3("html", "")]); | |
| 8488 } | |
| 8489 | |
| 8490 void test_parse_comment_in_content() { | |
| 8491 ht.HtmlUnit htmlUnit = parse("<html><!-- comment --></html>"); | |
| 8492 _validate(htmlUnit, [_t3("html", "<!-- comment -->")]); | |
| 8493 } | |
| 8494 | |
| 8495 void test_parse_content() { | |
| 8496 ht.HtmlUnit htmlUnit = parse("<html>\n<p a=\"b\">blat \n </p>\n</html>"); | |
| 8497 // ht.XmlTagNode.getContent() does not include whitespace | |
| 8498 // between '<' and '>' at this time | |
| 8499 _validate(htmlUnit, [ | |
| 8500 _t3("html", "\n<pa=\"b\">blat \n </p>\n", [ | |
| 8501 _t("p", _a(["a", "\"b\""]), "blat \n ") | |
| 8502 ]) | |
| 8503 ]); | |
| 8504 } | |
| 8505 | |
| 8506 void test_parse_content_none() { | |
| 8507 ht.HtmlUnit htmlUnit = parse("<html><p/>blat<p/></html>"); | |
| 8508 _validate(htmlUnit, [ | |
| 8509 _t3("html", "<p/>blat<p/>", [_t3("p", ""), _t3("p", "")]) | |
| 8510 ]); | |
| 8511 } | |
| 8512 | |
| 8513 void test_parse_declaration() { | |
| 8514 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html>\n\n<html><p></p></html>"); | |
| 8515 _validate(htmlUnit, [ | |
| 8516 _t4("html", [_t3("p", "")]) | |
| 8517 ]); | |
| 8518 } | |
| 8519 | |
| 8520 void test_parse_directive() { | |
| 8521 ht.HtmlUnit htmlUnit = parse("<?xml ?>\n\n<html><p></p></html>"); | |
| 8522 _validate(htmlUnit, [ | |
| 8523 _t4("html", [_t3("p", "")]) | |
| 8524 ]); | |
| 8525 } | |
| 8526 | |
| 8527 void test_parse_getAttribute() { | |
| 8528 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>"); | |
| 8529 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; | |
| 8530 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; | |
| 8531 expect(bodyNode.getAttribute("foo").text, "sdfsdf"); | |
| 8532 expect(bodyNode.getAttribute("bar"), null); | |
| 8533 expect(bodyNode.getAttribute(null), null); | |
| 8534 } | |
| 8535 | |
| 8536 void test_parse_getAttributeText() { | |
| 8537 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>"); | |
| 8538 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; | |
| 8539 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; | |
| 8540 expect(bodyNode.getAttributeText("foo"), "sdfsdf"); | |
| 8541 expect(bodyNode.getAttributeText("bar"), null); | |
| 8542 expect(bodyNode.getAttributeText(null), null); | |
| 8543 } | |
| 8544 | |
| 8545 void test_parse_headers() { | |
| 8546 String code = r''' | |
| 8547 <html> | |
| 8548 <body> | |
| 8549 <h2>000</h2> | |
| 8550 <div> | |
| 8551 111 | |
| 8552 </div> | |
| 8553 </body> | |
| 8554 </html>'''; | |
| 8555 ht.HtmlUnit htmlUnit = parse(code); | |
| 8556 _validate(htmlUnit, [ | |
| 8557 _t4("html", [ | |
| 8558 _t4("body", [_t3("h2", "000"), _t4("div")]) | |
| 8559 ]) | |
| 8560 ]); | |
| 8561 } | |
| 8562 | |
| 8563 void test_parse_script() { | |
| 8564 ht.HtmlUnit htmlUnit = | |
| 8565 parse("<html><script >here is <p> some</script></html>"); | |
| 8566 _validate(htmlUnit, [ | |
| 8567 _t4("html", [_t3("script", "here is <p> some")]) | |
| 8568 ]); | |
| 8569 } | |
| 8570 | |
| 8571 void test_parse_self_closing() { | |
| 8572 ht.HtmlUnit htmlUnit = parse("<html>foo<br>bar</html>"); | |
| 8573 _validate(htmlUnit, [ | |
| 8574 _t3("html", "foo<br>bar", [_t3("br", "")]) | |
| 8575 ]); | |
| 8576 } | |
| 8577 | |
| 8578 void test_parse_self_closing_declaration() { | |
| 8579 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html><html>foo</html>"); | |
| 8580 _validate(htmlUnit, [_t3("html", "foo")]); | |
| 8581 } | |
| 8582 | |
| 8583 XmlValidator_Attributes _a(List<String> keyValuePairs) => | |
| 8584 new XmlValidator_Attributes(keyValuePairs); | |
| 8585 XmlValidator_Tag _t( | |
| 8586 String tag, XmlValidator_Attributes attributes, String content, | |
| 8587 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) => | |
| 8588 new XmlValidator_Tag(tag, attributes, content, children); | |
| 8589 XmlValidator_Tag _t3(String tag, String content, | |
| 8590 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) => | |
| 8591 new XmlValidator_Tag( | |
| 8592 tag, new XmlValidator_Attributes(), content, children); | |
| 8593 XmlValidator_Tag _t4(String tag, | |
| 8594 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) => | |
| 8595 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), null, children); | |
| 8596 void _validate(ht.HtmlUnit htmlUnit, List<XmlValidator_Tag> expectedTags) { | |
| 8597 XmlValidator validator = new XmlValidator(); | |
| 8598 validator.expectTags(expectedTags); | |
| 8599 htmlUnit.accept(validator); | |
| 8600 validator.assertValid(); | |
| 8601 } | |
| 8602 } | |
| 8603 | |
| 8604 @reflectiveTest | |
| 8605 class HtmlTagInfoBuilderTest extends HtmlParserTest { | |
| 8606 void test_builder() { | |
| 8607 HtmlTagInfoBuilder builder = new HtmlTagInfoBuilder(); | |
| 8608 ht.HtmlUnit unit = parse(r''' | |
| 8609 <html> | |
| 8610 <body> | |
| 8611 <div id="x"></div> | |
| 8612 <p class='c'></p> | |
| 8613 <div class='c'></div> | |
| 8614 </body> | |
| 8615 </html>'''); | |
| 8616 unit.accept(builder); | |
| 8617 HtmlTagInfo info = builder.getTagInfo(); | |
| 8618 expect(info, isNotNull); | |
| 8619 List<String> allTags = info.allTags; | |
| 8620 expect(allTags, hasLength(4)); | |
| 8621 expect(info.getTagWithId("x"), "div"); | |
| 8622 List<String> tagsWithClass = info.getTagsWithClass("c"); | |
| 8623 expect(tagsWithClass, hasLength(2)); | |
| 8624 } | |
| 8625 } | |
| 8626 | |
| 8627 @reflectiveTest | |
| 8628 class HtmlUnitBuilderTest extends EngineTestCase { | |
| 8629 InternalAnalysisContext _context; | |
| 8630 @override | |
| 8631 void setUp() { | |
| 8632 _context = AnalysisContextFactory.contextWithCore(); | |
| 8633 } | |
| 8634 | |
| 8635 @override | |
| 8636 void tearDown() { | |
| 8637 _context = null; | |
| 8638 super.tearDown(); | |
| 8639 } | |
| 8640 | |
| 8641 void test_embedded_script() { | |
| 8642 HtmlElementImpl element = _build(r''' | |
| 8643 <html> | |
| 8644 <script type="application/dart">foo=2;</script> | |
| 8645 </html>'''); | |
| 8646 _validate(element, [ | |
| 8647 _s(_l([_v("foo")])) | |
| 8648 ]); | |
| 8649 } | |
| 8650 | |
| 8651 void test_embedded_script_no_content() { | |
| 8652 HtmlElementImpl element = _build(r''' | |
| 8653 <html> | |
| 8654 <script type="application/dart"></script> | |
| 8655 </html>'''); | |
| 8656 _validate(element, [_s(_l())]); | |
| 8657 } | |
| 8658 | |
| 8659 void test_external_script() { | |
| 8660 HtmlElementImpl element = _build(r''' | |
| 8661 <html> | |
| 8662 <script type="application/dart" src="other.dart"/> | |
| 8663 </html>'''); | |
| 8664 _validate(element, [_s2("other.dart")]); | |
| 8665 } | |
| 8666 | |
| 8667 void test_external_script_no_source() { | |
| 8668 HtmlElementImpl element = _build(r''' | |
| 8669 <html> | |
| 8670 <script type="application/dart"/> | |
| 8671 </html>'''); | |
| 8672 _validate(element, [_s2(null)]); | |
| 8673 } | |
| 8674 | |
| 8675 void test_external_script_with_content() { | |
| 8676 HtmlElementImpl element = _build(r''' | |
| 8677 <html> | |
| 8678 <script type="application/dart" src="other.dart">blat=2;</script> | |
| 8679 </html>'''); | |
| 8680 _validate(element, [_s2("other.dart")]); | |
| 8681 } | |
| 8682 | |
| 8683 void test_no_scripts() { | |
| 8684 HtmlElementImpl element = _build(r''' | |
| 8685 <!DOCTYPE html> | |
| 8686 <html><p></p></html>'''); | |
| 8687 _validate(element, []); | |
| 8688 } | |
| 8689 | |
| 8690 void test_two_dart_scripts() { | |
| 8691 HtmlElementImpl element = _build(r''' | |
| 8692 <html> | |
| 8693 <script type="application/dart">bar=2;</script> | |
| 8694 <script type="application/dart" src="other.dart"/> | |
| 8695 <script src="dart.js"/> | |
| 8696 </html>'''); | |
| 8697 _validate(element, [ | |
| 8698 _s(_l([_v("bar")])), | |
| 8699 _s2("other.dart") | |
| 8700 ]); | |
| 8701 } | |
| 8702 | |
| 8703 HtmlElementImpl _build(String contents) { | |
| 8704 TestSource source = new TestSource( | |
| 8705 FileUtilities2.createFile("/test.html").getAbsolutePath(), contents); | |
| 8706 ChangeSet changeSet = new ChangeSet(); | |
| 8707 changeSet.addedSource(source); | |
| 8708 _context.applyChanges(changeSet); | |
| 8709 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context); | |
| 8710 return builder.buildHtmlElement(source, _context.parseHtmlUnit(source)); | |
| 8711 } | |
| 8712 | |
| 8713 HtmlUnitBuilderTest_ExpectedLibrary _l( | |
| 8714 [List<HtmlUnitBuilderTest_ExpectedVariable> expectedVariables = | |
| 8715 HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST]) => | |
| 8716 new HtmlUnitBuilderTest_ExpectedLibrary(this, expectedVariables); | |
| 8717 _ExpectedScript _s(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) => | |
| 8718 new _ExpectedScript.con1(expectedLibrary); | |
| 8719 _ExpectedScript _s2(String scriptSourcePath) => | |
| 8720 new _ExpectedScript.con2(scriptSourcePath); | |
| 8721 HtmlUnitBuilderTest_ExpectedVariable _v(String varName) => | |
| 8722 new HtmlUnitBuilderTest_ExpectedVariable(varName); | |
| 8723 void _validate( | |
| 8724 HtmlElementImpl element, List<_ExpectedScript> expectedScripts) { | |
| 8725 expect(element.context, same(_context)); | |
| 8726 List<HtmlScriptElement> scripts = element.scripts; | |
| 8727 expect(scripts, isNotNull); | |
| 8728 expect(scripts, hasLength(expectedScripts.length)); | |
| 8729 for (int scriptIndex = 0; scriptIndex < scripts.length; scriptIndex++) { | |
| 8730 expectedScripts[scriptIndex]._validate(scriptIndex, scripts[scriptIndex]); | |
| 8731 } | |
| 8732 } | |
| 8733 } | |
| 8734 | |
| 8735 class HtmlUnitBuilderTest_ExpectedLibrary { | |
| 8736 final HtmlUnitBuilderTest HtmlUnitBuilderTest_this; | |
| 8737 final List<HtmlUnitBuilderTest_ExpectedVariable> _expectedVariables; | |
| 8738 HtmlUnitBuilderTest_ExpectedLibrary(this.HtmlUnitBuilderTest_this, | |
| 8739 [this._expectedVariables = | |
| 8740 HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST]); | |
| 8741 void _validate(int scriptIndex, EmbeddedHtmlScriptElementImpl script) { | |
| 8742 LibraryElement library = script.scriptLibrary; | |
| 8743 expect(library, isNotNull, reason: "script $scriptIndex"); | |
| 8744 expect(script.context, same(HtmlUnitBuilderTest_this._context), | |
| 8745 reason: "script $scriptIndex"); | |
| 8746 CompilationUnitElement unit = library.definingCompilationUnit; | |
| 8747 expect(unit, isNotNull, reason: "script $scriptIndex"); | |
| 8748 List<TopLevelVariableElement> variables = unit.topLevelVariables; | |
| 8749 expect(variables, hasLength(_expectedVariables.length)); | |
| 8750 for (int index = 0; index < variables.length; index++) { | |
| 8751 _expectedVariables[index].validate(scriptIndex, variables[index]); | |
| 8752 } | |
| 8753 expect(library.enclosingElement, same(script), | |
| 8754 reason: "script $scriptIndex"); | |
| 8755 } | |
| 8756 } | |
| 8757 | |
| 8758 class HtmlUnitBuilderTest_ExpectedVariable { | |
| 8759 static const List<HtmlUnitBuilderTest_ExpectedVariable> EMPTY_LIST = | |
| 8760 const <HtmlUnitBuilderTest_ExpectedVariable>[]; | |
| 8761 final String _expectedName; | |
| 8762 HtmlUnitBuilderTest_ExpectedVariable(this._expectedName); | |
| 8763 void validate(int scriptIndex, TopLevelVariableElement variable) { | |
| 8764 expect(variable, isNotNull, reason: "script $scriptIndex"); | |
| 8765 expect(variable.name, _expectedName, reason: "script $scriptIndex"); | |
| 8766 } | |
| 8767 } | |
| 8768 | |
| 8769 /** | |
| 8770 * Instances of the class `HtmlWarningCodeTest` test the generation of HTML warn
ing codes. | |
| 8771 */ | |
| 8772 @reflectiveTest | |
| 8773 class HtmlWarningCodeTest extends EngineTestCase { | |
| 8774 /** | |
| 8775 * The analysis context used to resolve the HTML files. | |
| 8776 */ | |
| 8777 InternalAnalysisContext _context; | |
| 8778 | |
| 8779 /** | |
| 8780 * The contents of the 'test.html' file. | |
| 8781 */ | |
| 8782 String _contents; | |
| 8783 | |
| 8784 /** | |
| 8785 * The list of reported errors. | |
| 8786 */ | |
| 8787 List<AnalysisError> _errors; | |
| 8788 @override | |
| 8789 void setUp() { | |
| 8790 _context = AnalysisContextFactory.contextWithCore(); | |
| 8791 } | |
| 8792 | |
| 8793 @override | |
| 8794 void tearDown() { | |
| 8795 _context = null; | |
| 8796 _contents = null; | |
| 8797 _errors = null; | |
| 8798 super.tearDown(); | |
| 8799 } | |
| 8800 | |
| 8801 void test_invalidUri() { | |
| 8802 _verify( | |
| 8803 r''' | |
| 8804 <html> | |
| 8805 <script type='application/dart' src='ht:'/> | |
| 8806 </html>''', | |
| 8807 [HtmlWarningCode.INVALID_URI]); | |
| 8808 _assertErrorLocation2(_errors[0], "ht:"); | |
| 8809 } | |
| 8810 | |
| 8811 void test_uriDoesNotExist() { | |
| 8812 _verify( | |
| 8813 r''' | |
| 8814 <html> | |
| 8815 <script type='application/dart' src='other.dart'/> | |
| 8816 </html>''', | |
| 8817 [HtmlWarningCode.URI_DOES_NOT_EXIST]); | |
| 8818 _assertErrorLocation2(_errors[0], "other.dart"); | |
| 8819 } | |
| 8820 | |
| 8821 void _assertErrorLocation( | |
| 8822 AnalysisError error, int expectedOffset, int expectedLength) { | |
| 8823 expect(error.offset, expectedOffset, reason: error.toString()); | |
| 8824 expect(error.length, expectedLength, reason: error.toString()); | |
| 8825 } | |
| 8826 | |
| 8827 void _assertErrorLocation2(AnalysisError error, String expectedString) { | |
| 8828 _assertErrorLocation( | |
| 8829 error, _contents.indexOf(expectedString), expectedString.length); | |
| 8830 } | |
| 8831 | |
| 8832 void _verify(String contents, List<ErrorCode> expectedErrorCodes) { | |
| 8833 this._contents = contents; | |
| 8834 TestSource source = new TestSource( | |
| 8835 FileUtilities2.createFile("/test.html").getAbsolutePath(), contents); | |
| 8836 ChangeSet changeSet = new ChangeSet(); | |
| 8837 changeSet.addedSource(source); | |
| 8838 _context.applyChanges(changeSet); | |
| 8839 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context); | |
| 8840 builder.buildHtmlElement(source, _context.parseHtmlUnit(source)); | |
| 8841 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 8842 errorListener.addAll2(builder.errorListener); | |
| 8843 errorListener.assertErrorsWithCodes(expectedErrorCodes); | |
| 8844 _errors = errorListener.errors; | |
| 8845 } | |
| 8846 } | |
| 8847 | |
| 8848 /** | |
| 8849 * Instances of the class `MockDartSdk` implement a [DartSdk]. | |
| 8850 */ | |
| 8851 class MockDartSdk implements DartSdk { | |
| 8852 @override | |
| 8853 AnalysisContext get context => null; | |
| 8854 | |
| 8855 @override | |
| 8856 List<SdkLibrary> get sdkLibraries => null; | |
| 8857 | |
| 8858 @override | |
| 8859 String get sdkVersion => null; | |
| 8860 | |
| 8861 @override | |
| 8862 List<String> get uris => null; | |
| 8863 | |
| 8864 @override | |
| 8865 Source fromFileUri(Uri uri) => null; | |
| 8866 | |
| 8867 @override | |
| 8868 SdkLibrary getSdkLibrary(String dartUri) => null; | |
| 8869 | |
| 8870 @override | |
| 8871 Source mapDartUri(String dartUri) => null; | |
| 8872 } | |
| 8873 | |
| 8874 @reflectiveTest | |
| 8875 class ReferenceFinderTest extends EngineTestCase { | |
| 8876 DirectedGraph<ConstantEvaluationTarget> _referenceGraph; | |
| 8877 VariableElement _head; | |
| 8878 Element _tail; | |
| 8879 @override | |
| 8880 void setUp() { | |
| 8881 _referenceGraph = new DirectedGraph<ConstantEvaluationTarget>(); | |
| 8882 _head = ElementFactory.topLevelVariableElement2("v1"); | |
| 8883 } | |
| 8884 | |
| 8885 void test_visitSimpleIdentifier_const() { | |
| 8886 _visitNode(_makeTailVariable("v2", true)); | |
| 8887 _assertOneArc(_tail); | |
| 8888 } | |
| 8889 | |
| 8890 void test_visitSimpleIdentifier_nonConst() { | |
| 8891 _visitNode(_makeTailVariable("v2", false)); | |
| 8892 _assertOneArc(_tail); | |
| 8893 } | |
| 8894 | |
| 8895 void test_visitSuperConstructorInvocation_const() { | |
| 8896 _visitNode(_makeTailSuperConstructorInvocation("A", true)); | |
| 8897 _assertOneArc(_tail); | |
| 8898 } | |
| 8899 | |
| 8900 void test_visitSuperConstructorInvocation_nonConst() { | |
| 8901 _visitNode(_makeTailSuperConstructorInvocation("A", false)); | |
| 8902 _assertOneArc(_tail); | |
| 8903 } | |
| 8904 | |
| 8905 void test_visitSuperConstructorInvocation_unresolved() { | |
| 8906 SuperConstructorInvocation superConstructorInvocation = | |
| 8907 AstFactory.superConstructorInvocation(); | |
| 8908 _visitNode(superConstructorInvocation); | |
| 8909 _assertNoArcs(); | |
| 8910 } | |
| 8911 | |
| 8912 void _assertNoArcs() { | |
| 8913 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); | |
| 8914 expect(tails, hasLength(0)); | |
| 8915 } | |
| 8916 | |
| 8917 void _assertOneArc(Element tail) { | |
| 8918 Set<ConstantEvaluationTarget> tails = _referenceGraph.getTails(_head); | |
| 8919 expect(tails, hasLength(1)); | |
| 8920 expect(tails.first, same(tail)); | |
| 8921 } | |
| 8922 | |
| 8923 ReferenceFinder _createReferenceFinder(ConstantEvaluationTarget source) => | |
| 8924 new ReferenceFinder((ConstantEvaluationTarget dependency) { | |
| 8925 _referenceGraph.addEdge(source, dependency); | |
| 8926 }); | |
| 8927 SuperConstructorInvocation _makeTailSuperConstructorInvocation( | |
| 8928 String name, bool isConst) { | |
| 8929 List<ConstructorInitializer> initializers = | |
| 8930 new List<ConstructorInitializer>(); | |
| 8931 ConstructorDeclaration constructorDeclaration = AstFactory | |
| 8932 .constructorDeclaration(AstFactory.identifier3(name), null, | |
| 8933 AstFactory.formalParameterList(), initializers); | |
| 8934 if (isConst) { | |
| 8935 constructorDeclaration.constKeyword = new KeywordToken(Keyword.CONST, 0); | |
| 8936 } | |
| 8937 ClassElementImpl classElement = ElementFactory.classElement2(name); | |
| 8938 SuperConstructorInvocation superConstructorInvocation = | |
| 8939 AstFactory.superConstructorInvocation(); | |
| 8940 ConstructorElementImpl constructorElement = | |
| 8941 ElementFactory.constructorElement(classElement, name, isConst); | |
| 8942 _tail = constructorElement; | |
| 8943 superConstructorInvocation.staticElement = constructorElement; | |
| 8944 return superConstructorInvocation; | |
| 8945 } | |
| 8946 | |
| 8947 SimpleIdentifier _makeTailVariable(String name, bool isConst) { | |
| 8948 VariableDeclaration variableDeclaration = | |
| 8949 AstFactory.variableDeclaration(name); | |
| 8950 ConstLocalVariableElementImpl variableElement = | |
| 8951 ElementFactory.constLocalVariableElement(name); | |
| 8952 _tail = variableElement; | |
| 8953 variableElement.const3 = isConst; | |
| 8954 AstFactory.variableDeclarationList2( | |
| 8955 isConst ? Keyword.CONST : Keyword.VAR, [variableDeclaration]); | |
| 8956 SimpleIdentifier identifier = AstFactory.identifier3(name); | |
| 8957 identifier.staticElement = variableElement; | |
| 8958 return identifier; | |
| 8959 } | |
| 8960 | |
| 8961 void _visitNode(AstNode node) { | |
| 8962 node.accept(_createReferenceFinder(_head)); | |
| 8963 } | |
| 8964 } | |
| 8965 | |
| 8966 @reflectiveTest | 4446 @reflectiveTest |
| 8967 class SDKLibrariesReaderTest extends EngineTestCase { | 4447 class SDKLibrariesReaderTest extends EngineTestCase { |
| 8968 void test_readFrom_dart2js() { | 4448 void test_readFrom_dart2js() { |
| 8969 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( | 4449 LibraryMap libraryMap = new SdkLibrariesReader(true).readFromFile( |
| 8970 FileUtilities2.createFile("/libs.dart"), | 4450 FileUtilities2.createFile("/libs.dart"), |
| 8971 r''' | 4451 r''' |
| 8972 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 4452 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
| 8973 'first' : const LibraryInfo( | 4453 'first' : const LibraryInfo( |
| 8974 'first/first.dart', | 4454 'first/first.dart', |
| 8975 categories: 'Client', | 4455 categories: 'Client', |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9032 expect(second.path, "second/second.dart"); | 4512 expect(second.path, "second/second.dart"); |
| 9033 expect(second.shortName, "dart:second"); | 4513 expect(second.shortName, "dart:second"); |
| 9034 expect(second.isDart2JsLibrary, false); | 4514 expect(second.isDart2JsLibrary, false); |
| 9035 expect(second.isDocumented, false); | 4515 expect(second.isDocumented, false); |
| 9036 expect(second.isImplementation, true); | 4516 expect(second.isImplementation, true); |
| 9037 expect(second.isVmLibrary, false); | 4517 expect(second.isVmLibrary, false); |
| 9038 } | 4518 } |
| 9039 } | 4519 } |
| 9040 | 4520 |
| 9041 @reflectiveTest | 4521 @reflectiveTest |
| 9042 class StringScannerTest extends AbstractScannerTest { | |
| 9043 @override | |
| 9044 ht.AbstractScanner newScanner(String input) { | |
| 9045 return new ht.StringScanner(null, input); | |
| 9046 } | |
| 9047 } | |
| 9048 | |
| 9049 /** | |
| 9050 * Instances of the class `ToSourceVisitorTest` | |
| 9051 */ | |
| 9052 @reflectiveTest | |
| 9053 class ToSourceVisitorTest extends EngineTestCase { | |
| 9054 void fail_visitHtmlScriptTagNode_attributes_content() { | |
| 9055 _assertSource( | |
| 9056 "<script type='application/dart'>f() {}</script>", | |
| 9057 HtmlFactory.scriptTagWithContent( | |
| 9058 "f() {}", [HtmlFactory.attribute("type", "'application/dart'")])); | |
| 9059 } | |
| 9060 | |
| 9061 void fail_visitHtmlScriptTagNode_noAttributes_content() { | |
| 9062 _assertSource( | |
| 9063 "<script>f() {}</script>", HtmlFactory.scriptTagWithContent("f() {}")); | |
| 9064 } | |
| 9065 | |
| 9066 void test_visitHtmlScriptTagNode_attributes_noContent() { | |
| 9067 _assertSource( | |
| 9068 "<script type='application/dart'/>", | |
| 9069 HtmlFactory | |
| 9070 .scriptTag([HtmlFactory.attribute("type", "'application/dart'")])); | |
| 9071 } | |
| 9072 | |
| 9073 void test_visitHtmlScriptTagNode_noAttributes_noContent() { | |
| 9074 _assertSource("<script/>", HtmlFactory.scriptTag()); | |
| 9075 } | |
| 9076 | |
| 9077 void test_visitHtmlUnit_empty() { | |
| 9078 _assertSource("", new ht.HtmlUnit(null, new List<ht.XmlTagNode>(), null)); | |
| 9079 } | |
| 9080 | |
| 9081 void test_visitHtmlUnit_nonEmpty() { | |
| 9082 _assertSource( | |
| 9083 "<html/>", new ht.HtmlUnit(null, [HtmlFactory.tagNode("html")], null)); | |
| 9084 } | |
| 9085 | |
| 9086 void test_visitXmlAttributeNode() { | |
| 9087 _assertSource("x=y", HtmlFactory.attribute("x", "y")); | |
| 9088 } | |
| 9089 | |
| 9090 /** | |
| 9091 * Assert that a `ToSourceVisitor` will produce the expected source when visit
ing the given | |
| 9092 * node. | |
| 9093 * | |
| 9094 * @param expectedSource the source string that the visitor is expected to pro
duce | |
| 9095 * @param node the AST node being visited to produce the actual source | |
| 9096 */ | |
| 9097 void _assertSource(String expectedSource, ht.XmlNode node) { | |
| 9098 PrintStringWriter writer = new PrintStringWriter(); | |
| 9099 node.accept(new ht.ToSourceVisitor(writer)); | |
| 9100 expect(writer.toString(), expectedSource); | |
| 9101 } | |
| 9102 } | |
| 9103 | |
| 9104 @reflectiveTest | |
| 9105 class UriKindTest { | 4522 class UriKindTest { |
| 9106 void test_fromEncoding() { | 4523 void test_fromEncoding() { |
| 9107 expect(UriKind.fromEncoding(0x64), same(UriKind.DART_URI)); | 4524 expect(UriKind.fromEncoding(0x64), same(UriKind.DART_URI)); |
| 9108 expect(UriKind.fromEncoding(0x66), same(UriKind.FILE_URI)); | 4525 expect(UriKind.fromEncoding(0x66), same(UriKind.FILE_URI)); |
| 9109 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); | 4526 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); |
| 9110 expect(UriKind.fromEncoding(0x58), same(null)); | 4527 expect(UriKind.fromEncoding(0x58), same(null)); |
| 9111 } | 4528 } |
| 9112 | 4529 |
| 9113 void test_getEncoding() { | 4530 void test_getEncoding() { |
| 9114 expect(UriKind.DART_URI.encoding, 0x64); | 4531 expect(UriKind.DART_URI.encoding, 0x64); |
| 9115 expect(UriKind.FILE_URI.encoding, 0x66); | 4532 expect(UriKind.FILE_URI.encoding, 0x66); |
| 9116 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 4533 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
| 9117 } | 4534 } |
| 9118 } | 4535 } |
| 9119 | |
| 9120 /** | |
| 9121 * Instances of `XmlValidator` traverse an [XmlNode] structure and validate the
node | |
| 9122 * hierarchy. | |
| 9123 */ | |
| 9124 class XmlValidator extends ht.RecursiveXmlVisitor<Object> { | |
| 9125 /** | |
| 9126 * A list containing the errors found while traversing the AST structure. | |
| 9127 */ | |
| 9128 List<String> _errors = new List<String>(); | |
| 9129 /** | |
| 9130 * The tags to expect when visiting or `null` if tags should not be checked. | |
| 9131 */ | |
| 9132 List<XmlValidator_Tag> _expectedTagsInOrderVisited; | |
| 9133 /** | |
| 9134 * The current index into the [expectedTagsInOrderVisited] array. | |
| 9135 */ | |
| 9136 int _expectedTagsIndex = 0; | |
| 9137 /** | |
| 9138 * The key/value pairs to expect when visiting or `null` if attributes should
not be | |
| 9139 * checked. | |
| 9140 */ | |
| 9141 List<String> _expectedAttributeKeyValuePairs; | |
| 9142 /** | |
| 9143 * The current index into the [expectedAttributeKeyValuePairs]. | |
| 9144 */ | |
| 9145 int _expectedAttributeIndex = 0; | |
| 9146 /** | |
| 9147 * Assert that no errors were found while traversing any of the AST structures
that have been | |
| 9148 * visited. | |
| 9149 */ | |
| 9150 void assertValid() { | |
| 9151 while (_expectedTagsIndex < _expectedTagsInOrderVisited.length) { | |
| 9152 String expectedTag = | |
| 9153 _expectedTagsInOrderVisited[_expectedTagsIndex++]._tag; | |
| 9154 _errors.add("Expected to visit node with tag: $expectedTag"); | |
| 9155 } | |
| 9156 if (!_errors.isEmpty) { | |
| 9157 StringBuffer buffer = new StringBuffer(); | |
| 9158 buffer.write("Invalid XML structure:"); | |
| 9159 for (String message in _errors) { | |
| 9160 buffer.writeln(); | |
| 9161 buffer.write(" "); | |
| 9162 buffer.write(message); | |
| 9163 } | |
| 9164 fail(buffer.toString()); | |
| 9165 } | |
| 9166 } | |
| 9167 | |
| 9168 /** | |
| 9169 * Set the tags to be expected when visiting | |
| 9170 * | |
| 9171 * @param expectedTags the expected tags | |
| 9172 */ | |
| 9173 void expectTags(List<XmlValidator_Tag> expectedTags) { | |
| 9174 // Flatten the hierarchy into expected order in which the tags are visited | |
| 9175 List<XmlValidator_Tag> expected = new List<XmlValidator_Tag>(); | |
| 9176 _expectTags(expected, expectedTags); | |
| 9177 this._expectedTagsInOrderVisited = expected; | |
| 9178 } | |
| 9179 | |
| 9180 @override | |
| 9181 Object visitHtmlUnit(ht.HtmlUnit node) { | |
| 9182 if (node.parent != null) { | |
| 9183 _errors.add("HtmlUnit should not have a parent"); | |
| 9184 } | |
| 9185 if (node.endToken.type != ht.TokenType.EOF) { | |
| 9186 _errors.add("HtmlUnit end token should be of type EOF"); | |
| 9187 } | |
| 9188 _validateNode(node); | |
| 9189 return super.visitHtmlUnit(node); | |
| 9190 } | |
| 9191 | |
| 9192 @override | |
| 9193 Object visitXmlAttributeNode(ht.XmlAttributeNode actual) { | |
| 9194 if (actual.parent is! ht.XmlTagNode) { | |
| 9195 _errors.add( | |
| 9196 "Expected ${actual.runtimeType} to have parent of type XmlTagNode"); | |
| 9197 } | |
| 9198 String actualName = actual.name; | |
| 9199 String actualValue = actual.valueToken.lexeme; | |
| 9200 if (_expectedAttributeIndex < _expectedAttributeKeyValuePairs.length) { | |
| 9201 String expectedName = | |
| 9202 _expectedAttributeKeyValuePairs[_expectedAttributeIndex]; | |
| 9203 if (expectedName != actualName) { | |
| 9204 _errors.add( | |
| 9205 "Expected ${_expectedTagsIndex - 1} tag: ${_expectedTagsInOrderVisit
ed[_expectedTagsIndex - 1]._tag} attribute ${_expectedAttributeIndex ~/ 2} to ha
ve name: $expectedName but found: $actualName"); | |
| 9206 } | |
| 9207 String expectedValue = | |
| 9208 _expectedAttributeKeyValuePairs[_expectedAttributeIndex + 1]; | |
| 9209 if (expectedValue != actualValue) { | |
| 9210 _errors.add( | |
| 9211 "Expected ${_expectedTagsIndex - 1} tag: ${_expectedTagsInOrderVisit
ed[_expectedTagsIndex - 1]._tag} attribute ${_expectedAttributeIndex ~/ 2} to ha
ve value: $expectedValue but found: $actualValue"); | |
| 9212 } | |
| 9213 } else { | |
| 9214 _errors.add( | |
| 9215 "Unexpected ${_expectedTagsIndex - 1} tag: ${_expectedTagsInOrderVisit
ed[_expectedTagsIndex - 1]._tag} attribute ${_expectedAttributeIndex ~/ 2} name:
$actualName value: $actualValue"); | |
| 9216 } | |
| 9217 _expectedAttributeIndex += 2; | |
| 9218 _validateNode(actual); | |
| 9219 return super.visitXmlAttributeNode(actual); | |
| 9220 } | |
| 9221 | |
| 9222 @override | |
| 9223 Object visitXmlTagNode(ht.XmlTagNode actual) { | |
| 9224 if (!(actual.parent is ht.HtmlUnit || actual.parent is ht.XmlTagNode)) { | |
| 9225 _errors.add( | |
| 9226 "Expected ${actual.runtimeType} to have parent of type HtmlUnit or Xml
TagNode"); | |
| 9227 } | |
| 9228 if (_expectedTagsInOrderVisited != null) { | |
| 9229 String actualTag = actual.tag; | |
| 9230 if (_expectedTagsIndex < _expectedTagsInOrderVisited.length) { | |
| 9231 XmlValidator_Tag expected = | |
| 9232 _expectedTagsInOrderVisited[_expectedTagsIndex]; | |
| 9233 if (expected._tag != actualTag) { | |
| 9234 _errors.add( | |
| 9235 "Expected $_expectedTagsIndex tag: ${expected._tag} but found: $ac
tualTag"); | |
| 9236 } | |
| 9237 _expectedAttributeKeyValuePairs = expected._attributes._keyValuePairs; | |
| 9238 int expectedAttributeCount = | |
| 9239 _expectedAttributeKeyValuePairs.length ~/ 2; | |
| 9240 int actualAttributeCount = actual.attributes.length; | |
| 9241 if (expectedAttributeCount != actualAttributeCount) { | |
| 9242 _errors.add( | |
| 9243 "Expected $_expectedTagsIndex tag: ${expected._tag} to have $expec
tedAttributeCount attributes but found $actualAttributeCount"); | |
| 9244 } | |
| 9245 _expectedAttributeIndex = 0; | |
| 9246 _expectedTagsIndex++; | |
| 9247 expect(actual.attributeEnd, isNotNull); | |
| 9248 expect(actual.contentEnd, isNotNull); | |
| 9249 int count = 0; | |
| 9250 ht.Token token = actual.attributeEnd.next; | |
| 9251 ht.Token lastToken = actual.contentEnd; | |
| 9252 while (!identical(token, lastToken)) { | |
| 9253 token = token.next; | |
| 9254 if (++count > 1000) { | |
| 9255 fail( | |
| 9256 "Expected $_expectedTagsIndex tag: ${expected._tag} to have a se
quence of tokens from getAttributeEnd() to getContentEnd()"); | |
| 9257 break; | |
| 9258 } | |
| 9259 } | |
| 9260 if (actual.attributeEnd.type == ht.TokenType.GT) { | |
| 9261 if (ht.HtmlParser.SELF_CLOSING.contains(actual.tag)) { | |
| 9262 expect(actual.closingTag, isNull); | |
| 9263 } else { | |
| 9264 expect(actual.closingTag, isNotNull); | |
| 9265 } | |
| 9266 } else if (actual.attributeEnd.type == ht.TokenType.SLASH_GT) { | |
| 9267 expect(actual.closingTag, isNull); | |
| 9268 } else { | |
| 9269 fail("Unexpected attribute end token: ${actual.attributeEnd.lexeme}"); | |
| 9270 } | |
| 9271 if (expected._content != null && expected._content != actual.content) { | |
| 9272 _errors.add( | |
| 9273 "Expected $_expectedTagsIndex tag: ${expected._tag} to have conten
t '${expected._content}' but found '${actual.content}'"); | |
| 9274 } | |
| 9275 if (expected._children.length != actual.tagNodes.length) { | |
| 9276 _errors.add( | |
| 9277 "Expected $_expectedTagsIndex tag: ${expected._tag} to have ${expe
cted._children.length} children but found ${actual.tagNodes.length}"); | |
| 9278 } else { | |
| 9279 for (int index = 0; index < expected._children.length; index++) { | |
| 9280 String expectedChildTag = expected._children[index]._tag; | |
| 9281 String actualChildTag = actual.tagNodes[index].tag; | |
| 9282 if (expectedChildTag != actualChildTag) { | |
| 9283 _errors.add( | |
| 9284 "Expected $_expectedTagsIndex tag: ${expected._tag} child $ind
ex to have tag: $expectedChildTag but found: $actualChildTag"); | |
| 9285 } | |
| 9286 } | |
| 9287 } | |
| 9288 } else { | |
| 9289 _errors.add("Visited unexpected tag: $actualTag"); | |
| 9290 } | |
| 9291 } | |
| 9292 _validateNode(actual); | |
| 9293 return super.visitXmlTagNode(actual); | |
| 9294 } | |
| 9295 | |
| 9296 /** | |
| 9297 * Append the specified tags to the array in depth first order | |
| 9298 * | |
| 9299 * @param expected the array to which the tags are added (not `null`) | |
| 9300 * @param expectedTags the expected tags to be added (not `null`, contains no
`null`s) | |
| 9301 */ | |
| 9302 void _expectTags( | |
| 9303 List<XmlValidator_Tag> expected, List<XmlValidator_Tag> expectedTags) { | |
| 9304 for (XmlValidator_Tag tag in expectedTags) { | |
| 9305 expected.add(tag); | |
| 9306 _expectTags(expected, tag._children); | |
| 9307 } | |
| 9308 } | |
| 9309 | |
| 9310 void _validateNode(ht.XmlNode node) { | |
| 9311 if (node.beginToken == null) { | |
| 9312 _errors.add("No begin token for ${node.runtimeType}"); | |
| 9313 } | |
| 9314 if (node.endToken == null) { | |
| 9315 _errors.add("No end token for ${node.runtimeType}"); | |
| 9316 } | |
| 9317 int nodeStart = node.offset; | |
| 9318 int nodeLength = node.length; | |
| 9319 if (nodeStart < 0 || nodeLength < 0) { | |
| 9320 _errors.add("No source info for ${node.runtimeType}"); | |
| 9321 } | |
| 9322 ht.XmlNode parent = node.parent; | |
| 9323 if (parent != null) { | |
| 9324 int nodeEnd = nodeStart + nodeLength; | |
| 9325 int parentStart = parent.offset; | |
| 9326 int parentEnd = parentStart + parent.length; | |
| 9327 if (nodeStart < parentStart) { | |
| 9328 _errors.add( | |
| 9329 "Invalid source start ($nodeStart) for ${node.runtimeType} inside ${
parent.runtimeType} ($parentStart)"); | |
| 9330 } | |
| 9331 if (nodeEnd > parentEnd) { | |
| 9332 _errors.add( | |
| 9333 "Invalid source end ($nodeEnd) for ${node.runtimeType} inside ${pare
nt.runtimeType} ($parentStart)"); | |
| 9334 } | |
| 9335 } | |
| 9336 } | |
| 9337 } | |
| 9338 | |
| 9339 class XmlValidator_Attributes { | |
| 9340 final List<String> _keyValuePairs; | |
| 9341 XmlValidator_Attributes([this._keyValuePairs = StringUtilities.EMPTY_ARRAY]); | |
| 9342 } | |
| 9343 | |
| 9344 class XmlValidator_Tag { | |
| 9345 static const List<XmlValidator_Tag> EMPTY_LIST = const <XmlValidator_Tag>[]; | |
| 9346 final String _tag; | |
| 9347 final XmlValidator_Attributes _attributes; | |
| 9348 final String _content; | |
| 9349 final List<XmlValidator_Tag> _children; | |
| 9350 XmlValidator_Tag(this._tag, this._attributes, this._content, | |
| 9351 [this._children = EMPTY_LIST]); | |
| 9352 } | |
| 9353 | |
| 9354 class _ExpectedScript { | |
| 9355 String _expectedExternalScriptName; | |
| 9356 HtmlUnitBuilderTest_ExpectedLibrary _expectedLibrary; | |
| 9357 _ExpectedScript.con1(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) { | |
| 9358 this._expectedExternalScriptName = null; | |
| 9359 this._expectedLibrary = expectedLibrary; | |
| 9360 } | |
| 9361 _ExpectedScript.con2(String expectedExternalScriptPath) { | |
| 9362 this._expectedExternalScriptName = expectedExternalScriptPath; | |
| 9363 this._expectedLibrary = null; | |
| 9364 } | |
| 9365 void _validate(int scriptIndex, HtmlScriptElement script) { | |
| 9366 if (_expectedLibrary != null) { | |
| 9367 _validateEmbedded(scriptIndex, script); | |
| 9368 } else { | |
| 9369 _validateExternal(scriptIndex, script); | |
| 9370 } | |
| 9371 } | |
| 9372 | |
| 9373 void _validateEmbedded(int scriptIndex, HtmlScriptElement script) { | |
| 9374 if (script is! EmbeddedHtmlScriptElementImpl) { | |
| 9375 fail( | |
| 9376 "Expected script $scriptIndex to be embedded, but found ${script != nu
ll ? script.runtimeType : "null"}"); | |
| 9377 } | |
| 9378 EmbeddedHtmlScriptElementImpl embeddedScript = | |
| 9379 script as EmbeddedHtmlScriptElementImpl; | |
| 9380 _expectedLibrary._validate(scriptIndex, embeddedScript); | |
| 9381 } | |
| 9382 | |
| 9383 void _validateExternal(int scriptIndex, HtmlScriptElement script) { | |
| 9384 if (script is! ExternalHtmlScriptElementImpl) { | |
| 9385 fail( | |
| 9386 "Expected script $scriptIndex to be external with src=$_expectedExtern
alScriptName but found ${script != null ? script.runtimeType : "null"}"); | |
| 9387 } | |
| 9388 ExternalHtmlScriptElementImpl externalScript = | |
| 9389 script as ExternalHtmlScriptElementImpl; | |
| 9390 Source scriptSource = externalScript.scriptSource; | |
| 9391 if (_expectedExternalScriptName == null) { | |
| 9392 expect(scriptSource, isNull, reason: "script $scriptIndex"); | |
| 9393 } else { | |
| 9394 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | |
| 9395 String actualExternalScriptName = scriptSource.shortName; | |
| 9396 expect(actualExternalScriptName, _expectedExternalScriptName, | |
| 9397 reason: "script $scriptIndex"); | |
| 9398 } | |
| 9399 } | |
| 9400 } | |
| OLD | NEW |