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

Side by Side 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 unified diff | Download patch
OLDNEW
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);
29 }); 30 });
30 } 31 }
31 32
32 @reflectiveTest 33 @reflectiveTest
33 class EmbedderSdkTest extends EmbedderRelatedTest { 34 class EmbedderSdkTest extends EmbedderRelatedTest {
34 void test_creation() { 35 void test_creation() {
35 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 36 EmbedderYamlLocator locator = new EmbedderYamlLocator({
36 'fox': <Folder>[pathTranslator.getResource(foxLib)] 37 'fox': <Folder>[pathTranslator.getResource(foxLib)]
37 }); 38 });
38 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls); 39 EmbedderSdk sdk = new EmbedderSdk(resourceProvider, locator.embedderYamls);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 expect(urlMappings['dart:bear'], 385 expect(urlMappings['dart:bear'],
385 equals(resourceProvider.convertPath("/tmp/grizzly.dart"))); 386 equals(resourceProvider.convertPath("/tmp/grizzly.dart")));
386 expect(urlMappings['dart:relative'], 387 expect(urlMappings['dart:relative'],
387 equals(resourceProvider.convertPath("/relative.dart"))); 388 equals(resourceProvider.convertPath("/relative.dart")));
388 expect(urlMappings['dart:deep'], 389 expect(urlMappings['dart:deep'],
389 equals(resourceProvider.convertPath("/tmp/deep/directory/file.dart"))); 390 equals(resourceProvider.convertPath("/tmp/deep/directory/file.dart")));
390 } 391 }
391 } 392 }
392 393
393 @reflectiveTest 394 @reflectiveTest
394 class SDKLibrariesReaderTest extends EngineTestCase { 395 class SdkLibrariesReaderTest extends EngineTestCase {
395 /** 396 /**
396 * The resource provider used by these tests. 397 * The resource provider used by these tests.
397 */ 398 */
398 MemoryResourceProvider resourceProvider; 399 MemoryResourceProvider resourceProvider;
399 400
400 @override 401 @override
401 void setUp() { 402 void setUp() {
402 resourceProvider = new MemoryResourceProvider(); 403 resourceProvider = new MemoryResourceProvider();
403 } 404 }
404 405
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 SdkLibrary second = libraryMap.getLibrary("dart:second"); 467 SdkLibrary second = libraryMap.getLibrary("dart:second");
467 expect(second, isNotNull); 468 expect(second, isNotNull);
468 expect(second.category, "Server"); 469 expect(second.category, "Server");
469 expect(second.path, "second/second.dart"); 470 expect(second.path, "second/second.dart");
470 expect(second.shortName, "dart:second"); 471 expect(second.shortName, "dart:second");
471 expect(second.isDart2JsLibrary, false); 472 expect(second.isDart2JsLibrary, false);
472 expect(second.isDocumented, false); 473 expect(second.isDocumented, false);
473 expect(second.isImplementation, true); 474 expect(second.isImplementation, true);
474 expect(second.isVmLibrary, false); 475 expect(second.isVmLibrary, false);
475 } 476 }
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_platformCombinator() {
531 expect(() {
532 new SdkLibrariesReader(false).readFromFile(
533 resourceProvider.getFile('/libs.dart'),
534 r'''
535 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
536 'foo' : const LibraryInfo(
537 'foo/foo.dart',
538 patches: {
539 DART2JS_PLATFORM + VM_PLATFORM: ['X']}),
540 };''');
541 }, throwsArgumentError);
542 }
543
544 void test_readFrom_patches_invalid_unknownPlatform() {
545 expect(() {
546 new SdkLibrariesReader(false).readFromFile(
547 resourceProvider.getFile('/libs.dart'),
548 r'''
549 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
550 'foo' : const LibraryInfo(
551 'foo/foo.dart',
552 patches: {
553 MY_UNKNOWN_PLATFORM: ['foo/bar_patch.dart']}),
554 };''');
555 }, throwsArgumentError);
556 }
557
558 void test_readFrom_patches_no() {
559 LibraryMap libraryMap = new SdkLibrariesReader(false).readFromFile(
560 resourceProvider.getFile('/libs.dart'),
561 r'''
562 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
563 'my' : const LibraryInfo('my/my.dart')
564 };''');
565 expect(libraryMap, isNotNull);
566 expect(libraryMap.size(), 1);
567 SdkLibrary library = libraryMap.getLibrary('dart:my');
568 expect(library, isNotNull);
569 expect(library.path, 'my/my.dart');
570 expect(library.shortName, 'dart:my');
571 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), isEmpty);
572 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), isEmpty);
573 }
476 } 574 }
575
576 @reflectiveTest
577 class SdkLibraryImplTest extends EngineTestCase {
578 void test_patches() {
579 SdkLibraryImpl library = new SdkLibraryImpl('dart:foo');
580 // Set patches.
581 library.setPatchPaths(
582 SdkLibraryImpl.DART2JS_PLATFORM | SdkLibraryImpl.VM_PLATFORM,
583 ['a', 'b']);
584 library.setPatchPaths(SdkLibraryImpl.DART2JS_PLATFORM, ['c', 'd']);
585 library.setPatchPaths(SdkLibraryImpl.VM_PLATFORM, ['e']);
586 // Get patches.
587 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM),
588 unorderedEquals(['a', 'b', 'c', 'd']));
589 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM),
590 unorderedEquals(['a', 'b', 'e']));
591 }
592 }
OLDNEW
« 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