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'; |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 r''' | 520 r''' |
521 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 521 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
522 'foo' : const LibraryInfo( | 522 'foo' : const LibraryInfo( |
523 'foo/foo.dart', | 523 'foo/foo.dart', |
524 patches: { | 524 patches: { |
525 VM_PLATFORM: [42]}), | 525 VM_PLATFORM: [42]}), |
526 };'''); | 526 };'''); |
527 }, throwsArgumentError); | 527 }, throwsArgumentError); |
528 } | 528 } |
529 | 529 |
| 530 void test_readFrom_patches_invalid_path_hasDotDot() { |
| 531 _assertPathIsInvalid('foo/../bar.dart'); |
| 532 _assertPathIsInvalid('../foo/bar.dart'); |
| 533 _assertPathIsInvalid('foo/bar..dart'); |
| 534 } |
| 535 |
| 536 void test_readFrom_patches_invalid_path_isAbsolute() { |
| 537 _assertPathIsInvalid('/foo.dart'); |
| 538 _assertPathIsInvalid('/foo/bar.dart'); |
| 539 } |
| 540 |
| 541 void test_readFrom_patches_invalid_path_notPosix() { |
| 542 _assertPathIsInvalid(r'foo\bar.dart'); |
| 543 } |
| 544 |
530 void test_readFrom_patches_invalid_platformCombinator() { | 545 void test_readFrom_patches_invalid_platformCombinator() { |
531 expect(() { | 546 expect(() { |
532 new SdkLibrariesReader(false).readFromFile( | 547 new SdkLibrariesReader(false).readFromFile( |
533 resourceProvider.getFile('/libs.dart'), | 548 resourceProvider.getFile('/libs.dart'), |
534 r''' | 549 r''' |
535 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 550 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
536 'foo' : const LibraryInfo( | 551 'foo' : const LibraryInfo( |
537 'foo/foo.dart', | 552 'foo/foo.dart', |
538 patches: { | 553 patches: { |
539 DART2JS_PLATFORM + VM_PLATFORM: ['X']}), | 554 DART2JS_PLATFORM + VM_PLATFORM: ['X']}), |
(...skipping 24 matching lines...) Expand all Loading... |
564 };'''); | 579 };'''); |
565 expect(libraryMap, isNotNull); | 580 expect(libraryMap, isNotNull); |
566 expect(libraryMap.size(), 1); | 581 expect(libraryMap.size(), 1); |
567 SdkLibrary library = libraryMap.getLibrary('dart:my'); | 582 SdkLibrary library = libraryMap.getLibrary('dart:my'); |
568 expect(library, isNotNull); | 583 expect(library, isNotNull); |
569 expect(library.path, 'my/my.dart'); | 584 expect(library.path, 'my/my.dart'); |
570 expect(library.shortName, 'dart:my'); | 585 expect(library.shortName, 'dart:my'); |
571 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), isEmpty); | 586 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), isEmpty); |
572 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), isEmpty); | 587 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), isEmpty); |
573 } | 588 } |
| 589 |
| 590 void _assertPathIsInvalid(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 } |
574 } | 603 } |
575 | 604 |
576 @reflectiveTest | 605 @reflectiveTest |
577 class SdkLibraryImplTest extends EngineTestCase { | 606 class SdkLibraryImplTest extends EngineTestCase { |
578 void test_patches() { | 607 void test_patches() { |
579 SdkLibraryImpl library = new SdkLibraryImpl('dart:foo'); | 608 SdkLibraryImpl library = new SdkLibraryImpl('dart:foo'); |
580 // Set patches. | 609 // Set patches. |
581 library.setPatchPaths( | 610 library.setPatchPaths( |
582 SdkLibraryImpl.DART2JS_PLATFORM | SdkLibraryImpl.VM_PLATFORM, | 611 SdkLibraryImpl.DART2JS_PLATFORM | SdkLibraryImpl.VM_PLATFORM, |
583 ['a', 'b']); | 612 ['a', 'b']); |
584 library.setPatchPaths(SdkLibraryImpl.DART2JS_PLATFORM, ['c', 'd']); | 613 library.setPatchPaths(SdkLibraryImpl.DART2JS_PLATFORM, ['c', 'd']); |
585 library.setPatchPaths(SdkLibraryImpl.VM_PLATFORM, ['e']); | 614 library.setPatchPaths(SdkLibraryImpl.VM_PLATFORM, ['e']); |
586 // Get patches. | 615 // Get patches. |
587 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), | 616 expect(library.getPatches(SdkLibraryImpl.DART2JS_PLATFORM), |
588 unorderedEquals(['a', 'b', 'c', 'd'])); | 617 unorderedEquals(['a', 'b', 'c', 'd'])); |
589 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), | 618 expect(library.getPatches(SdkLibraryImpl.VM_PLATFORM), |
590 unorderedEquals(['a', 'b', 'e'])); | 619 unorderedEquals(['a', 'b', 'e'])); |
591 } | 620 } |
592 } | 621 } |
OLD | NEW |