| 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 analyzer.test.generated.sdk_test; | 5 library analyzer.test.generated.sdk_test; |
| 6 | 6 |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator; | 9 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator; |
| 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/java_engine_io.dart'; | 12 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 13 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:analyzer/src/generated/source.dart'; | 14 import 'package:analyzer/src/generated/source.dart'; |
| 15 import 'package:analyzer/src/summary/summarize_elements.dart'; | 15 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 16 import 'package:test/test.dart'; | 16 import 'package:test/test.dart'; |
| 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 18 | 18 |
| 19 import '../../../embedder_tests.dart'; | 19 import '../../../embedder_tests.dart'; |
| 20 import '../../../generated/test_support.dart'; | 20 import '../../../generated/test_support.dart'; |
| 21 import '../../../resource_utils.dart'; | 21 import '../../../resource_utils.dart'; |
| 22 | 22 |
| 23 main() { | 23 main() { |
| 24 defineReflectiveSuite(() { | 24 defineReflectiveSuite(() { |
| 25 defineReflectiveTests(EmbedderSdkTest); | 25 defineReflectiveTests(EmbedderSdkTest); |
| 26 defineReflectiveTests(FolderBasedDartSdkTest); | 26 defineReflectiveTests(FolderBasedDartSdkTest); |
| 27 defineReflectiveTests(SdkExtensionFinderTest); | 27 defineReflectiveTests(SdkExtensionFinderTest); |
| 28 defineReflectiveTests(SdkLibrariesReaderTest); | 28 defineReflectiveTests(SdkLibrariesReaderTest); |
| 29 defineReflectiveTests(SdkLibraryImplTest); | |
| 30 }); | 29 }); |
| 31 } | 30 } |
| 32 | 31 |
| 33 @reflectiveTest | 32 @reflectiveTest |
| 34 class EmbedderSdkTest extends EmbedderRelatedTest { | 33 class EmbedderSdkTest extends EmbedderRelatedTest { |
| 35 void test_creation() { | 34 void test_creation() { |
| 36 EmbedderYamlLocator locator = new EmbedderYamlLocator({ | 35 EmbedderYamlLocator locator = new EmbedderYamlLocator({ |
| 37 'fox': <Folder>[pathTranslator.getResource(foxLib)] | 36 'fox': <Folder>[pathTranslator.getResource(foxLib)] |
| 38 }); | 37 }); |
| 39 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); | 38 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 SdkLibrary second = libraryMap.getLibrary("dart:second"); | 466 SdkLibrary second = libraryMap.getLibrary("dart:second"); |
| 468 expect(second, isNotNull); | 467 expect(second, isNotNull); |
| 469 expect(second.category, "Server"); | 468 expect(second.category, "Server"); |
| 470 expect(second.path, "second/second.dart"); | 469 expect(second.path, "second/second.dart"); |
| 471 expect(second.shortName, "dart:second"); | 470 expect(second.shortName, "dart:second"); |
| 472 expect(second.isDart2JsLibrary, false); | 471 expect(second.isDart2JsLibrary, false); |
| 473 expect(second.isDocumented, false); | 472 expect(second.isDocumented, false); |
| 474 expect(second.isImplementation, true); | 473 expect(second.isImplementation, true); |
| 475 expect(second.isVmLibrary, false); | 474 expect(second.isVmLibrary, false); |
| 476 } | 475 } |
| 477 | |
| 478 void test_readFrom_patches() { | |
| 479 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( | |
| 480 resourceProvider.getFile('/libs.dart'), | |
| 481 r''' | |
| 482 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 483 'foo' : const LibraryInfo( | |
| 484 'foo/foo.dart', | |
| 485 patches: { | |
| 486 DART2JS_PLATFORM | VM_PLATFORM: ['a', 'b'], | |
| 487 DART2JS_PLATFORM: ['c', 'd'], | |
| 488 VM_PLATFORM: ['e']}), | |
| 489 };'''); | |
| 490 expect(libraryMap, isNotNull); | |
| 491 expect(libraryMap.size(), 1); | |
| 492 SdkLibrary library = libraryMap.getLibrary('dart:foo'); | |
| 493 expect(library, isNotNull); | |
| 494 expect(library.path, 'foo/foo.dart'); | |
| 495 expect(library.shortName, 'dart:foo'); | |
| 496 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), | |
| 497 unorderedEquals(['a', 'b', 'c', 'd'])); | |
| 498 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), | |
| 499 unorderedEquals(['a', 'b', 'e'])); | |
| 500 } | |
| 501 | |
| 502 void test_readFrom_patches_invalid_notList() { | |
| 503 expect(() { | |
| 504 new SdkLibrariesReader(false).readFromFile( | |
| 505 resourceProvider.getFile('/libs.dart'), | |
| 506 r''' | |
| 507 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 508 'foo' : const LibraryInfo( | |
| 509 'foo/foo.dart', | |
| 510 patches: { | |
| 511 VM_PLATFORM: 'X'}), | |
| 512 };'''); | |
| 513 }, throwsArgumentError); | |
| 514 } | |
| 515 | |
| 516 void test_readFrom_patches_invalid_notString_inList() { | |
| 517 expect(() { | |
| 518 new SdkLibrariesReader(false).readFromFile( | |
| 519 resourceProvider.getFile('/libs.dart'), | |
| 520 r''' | |
| 521 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 522 'foo' : const LibraryInfo( | |
| 523 'foo/foo.dart', | |
| 524 patches: { | |
| 525 VM_PLATFORM: [42]}), | |
| 526 };'''); | |
| 527 }, throwsArgumentError); | |
| 528 } | |
| 529 | |
| 530 void test_readFrom_patches_invalid_path_hasDotDot() { | |
| 531 _assertPatchPathIsInvalid('foo/../bar.dart'); | |
| 532 _assertPatchPathIsInvalid('../foo/bar.dart'); | |
| 533 _assertPatchPathIsInvalid('foo/bar..dart'); | |
| 534 } | |
| 535 | |
| 536 void test_readFrom_patches_invalid_path_isAbsolute() { | |
| 537 _assertPatchPathIsInvalid('/foo.dart'); | |
| 538 _assertPatchPathIsInvalid('/foo/bar.dart'); | |
| 539 } | |
| 540 | |
| 541 void test_readFrom_patches_invalid_path_notPosix() { | |
| 542 _assertPatchPathIsInvalid(r'foo\bar.dart'); | |
| 543 } | |
| 544 | |
| 545 void test_readFrom_patches_invalid_platformCombinator() { | |
| 546 expect(() { | |
| 547 new SdkLibrariesReader(false).readFromFile( | |
| 548 resourceProvider.getFile('/libs.dart'), | |
| 549 r''' | |
| 550 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 551 'foo' : const LibraryInfo( | |
| 552 'foo/foo.dart', | |
| 553 patches: { | |
| 554 DART2JS_PLATFORM + VM_PLATFORM: ['X']}), | |
| 555 };'''); | |
| 556 }, throwsArgumentError); | |
| 557 } | |
| 558 | |
| 559 void test_readFrom_patches_invalid_unknownPlatform() { | |
| 560 expect(() { | |
| 561 new SdkLibrariesReader(false).readFromFile( | |
| 562 resourceProvider.getFile('/libs.dart'), | |
| 563 r''' | |
| 564 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 565 'foo' : const LibraryInfo( | |
| 566 'foo/foo.dart', | |
| 567 patches: { | |
| 568 MY_UNKNOWN_PLATFORM: ['foo/bar_patch.dart']}), | |
| 569 };'''); | |
| 570 }, throwsArgumentError); | |
| 571 } | |
| 572 | |
| 573 void test_readFrom_patches_no() { | |
| 574 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile( | |
| 575 resourceProvider.getFile('/libs.dart'), | |
| 576 r''' | |
| 577 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 578 'my' : const LibraryInfo('my/my.dart') | |
| 579 };'''); | |
| 580 expect(libraryMap, isNotNull); | |
| 581 expect(libraryMap.size(), 1); | |
| 582 SdkLibrary library = libraryMap.getLibrary('dart:my'); | |
| 583 expect(library, isNotNull); | |
| 584 expect(library.path, 'my/my.dart'); | |
| 585 expect(library.shortName, 'dart:my'); | |
| 586 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), isEmpty); | |
| 587 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), isEmpty); | |
| 588 } | |
| 589 | |
| 590 void _assertPatchPathIsInvalid(String patchPath) { | |
| 591 expect(() { | |
| 592 new SdkLibrariesReader(false).readFromFile( | |
| 593 resourceProvider.getFile('/libs.dart'), | |
| 594 ''' | |
| 595 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | |
| 596 'foo' : const LibraryInfo( | |
| 597 'foo/foo.dart', | |
| 598 patches: { | |
| 599 VM_PLATFORM: [r'$patchPath']}), | |
| 600 };'''); | |
| 601 }, throwsArgumentError); | |
| 602 } | |
| 603 } | 476 } |
| 604 | |
| 605 @reflectiveTest | |
| 606 class SdkLibraryImplTest extends EngineTestCase { | |
| 607 void test_patches() { | |
| 608 SdkLibraryImpl library = new SdkLibraryImpl('dart:foo'); | |
| 609 // Set patches. | |
| 610 library.setPatchPaths( | |
| 611 SdkLibraryImpl.DART2JS_PLATFORM | SdkLibraryImpl.VM_PLATFORM, | |
| 612 ['a', 'b']); | |
| 613 library.setPatchPaths(SdkLibraryImpl.DART2JS_PLATFORM, ['c', 'd']); | |
| 614 library.setPatchPaths(SdkLibraryImpl.VM_PLATFORM, ['e']); | |
| 615 // Get patches. | |
| 616 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), | |
| 617 unorderedEquals(['a', 'b', 'c', 'd'])); | |
| 618 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), | |
| 619 unorderedEquals(['a', 'b', 'e'])); | |
| 620 } | |
| 621 } | |
| OLD | NEW |