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

Unified Diff: pkg/analyzer/test/src/dart/sdk/sdk_test.dart

Issue 2408863002: Parse the 'patches' argument in SDK libraries declarations. (Closed)
Patch Set: Rework to support 'PLATFORM1 | PLATFORM2' and [list, of, paths]. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/dart/sdk/sdk_test.dart
diff --git a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart b/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
index 882f08b4005c66ea630f8910035fdfac6ebbc578..214bfa224dc59f06c7b621261b1064e24aa0c6fb 100644
--- a/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
+++ b/pkg/analyzer/test/src/dart/sdk/sdk_test.dart
@@ -25,7 +25,8 @@ main() {
defineReflectiveTests(EmbedderSdkTest);
defineReflectiveTests(FolderBasedDartSdkTest);
defineReflectiveTests(SdkExtensionFinderTest);
- defineReflectiveTests(SDKLibrariesReaderTest);
+ defineReflectiveTests(SdkLibrariesReaderTest);
+ defineReflectiveTests(SdkLibraryImplTest);
});
}
@@ -391,7 +392,7 @@ class SdkExtensionFinderTest {
}
@reflectiveTest
-class SDKLibrariesReaderTest extends EngineTestCase {
+class SdkLibrariesReaderTest extends EngineTestCase {
/**
* The resource provider used by these tests.
*/
@@ -473,4 +474,119 @@ final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
expect(second.isImplementation, true);
expect(second.isVmLibrary, false);
}
+
+ void test_readFrom_patches() {
+ LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'foo' : const LibraryInfo(
+ 'foo/foo.dart',
+ patches: {
+ DART2JS_PLATFORM | VM_PLATFORM: ['a', 'b'],
+ DART2JS_PLATFORM: ['c', 'd'],
+ VM_PLATFORM: ['e']}),
+};''');
+ expect(libraryMap, isNotNull);
+ expect(libraryMap.size(), 1);
+ SdkLibrary library = libraryMap.getLibrary('dart:foo');
+ expect(library, isNotNull);
+ expect(library.path, 'foo/foo.dart');
+ expect(library.shortName, 'dart:foo');
+ expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM),
+ unorderedEquals(['a', 'b', 'c', 'd']));
+ expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM),
+ unorderedEquals(['a', 'b', 'e']));
+ }
+
+ void test_readFrom_patches_invalid_notList() {
+ expect(() {
+ new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'foo' : const LibraryInfo(
+ 'foo/foo.dart',
+ patches: {
+ VM_PLATFORM: 'X'}),
+};''');
+ }, throwsArgumentError);
+ }
+
+ void test_readFrom_patches_invalid_notString_inList() {
+ expect(() {
+ new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'foo' : const LibraryInfo(
+ 'foo/foo.dart',
+ patches: {
+ VM_PLATFORM: [42]}),
+};''');
+ }, throwsArgumentError);
+ }
+
+ void test_readFrom_patches_invalid_platformCombinator() {
+ expect(() {
+ new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'foo' : const LibraryInfo(
+ 'foo/foo.dart',
+ patches: {
+ DART2JS_PLATFORM + VM_PLATFORM: ['X']}),
+};''');
+ }, throwsArgumentError);
+ }
+
+ void test_readFrom_patches_invalid_unknownPlatform() {
+ expect(() {
+ new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'foo' : const LibraryInfo(
+ 'foo/foo.dart',
+ patches: {
+ MY_UNKNOWN_PLATFORM: ['foo/bar_patch.dart']}),
+};''');
+ }, throwsArgumentError);
+ }
+
+ void test_readFrom_patches_no() {
+ LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile(
+ resourceProvider.getFile('/libs.dart'),
+ r'''
+final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
+ 'my' : const LibraryInfo('my/my.dart')
+};''');
+ expect(libraryMap, isNotNull);
+ expect(libraryMap.size(), 1);
+ SdkLibrary library = libraryMap.getLibrary('dart:my');
+ expect(library, isNotNull);
+ expect(library.path, 'my/my.dart');
+ expect(library.shortName, 'dart:my');
+ expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), isEmpty);
+ expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), isEmpty);
+ }
+}
+
+@reflectiveTest
+class SdkLibraryImplTest extends EngineTestCase {
+ void test_patches() {
+ SdkLibraryImpl library = new SdkLibraryImpl('dart:foo');
+ // Set patches.
+ library.setPatchPaths(
+ SdkLibraryImpl.DART2JS_PLATFORM | SdkLibraryImpl.VM_PLATFORM,
+ ['a', 'b']);
+ library.setPatchPaths(SdkLibraryImpl.DART2JS_PLATFORM, ['c', 'd']);
+ library.setPatchPaths(SdkLibraryImpl.VM_PLATFORM, ['e']);
+ // Get patches.
+ expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM),
+ unorderedEquals(['a', 'b', 'c', 'd']));
+ expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM),
+ unorderedEquals(['a', 'b', 'e']));
+ }
}
« pkg/analyzer/lib/src/generated/sdk.dart ('K') | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698