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

Side by Side Diff: pkg/analyzer/test/src/dart/sdk/patch_test.dart

Issue 2414123003: Add support for patching parts. (Closed)
Patch Set: 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:analyzer/dart/ast/ast.dart'; 5 import 'package:analyzer/dart/ast/ast.dart';
6 import 'package:analyzer/dart/ast/token.dart'; 6 import 'package:analyzer/dart/ast/token.dart';
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/dart/sdk/patch.dart'; 9 import 'package:analyzer/src/dart/sdk/patch.dart';
10 import 'package:analyzer/src/dart/sdk/sdk.dart'; 10 import 'package:analyzer/src/dart/sdk/sdk.dart';
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 patches: {VM_PLATFORM: ['does_not_exists.dart']}), 383 patches: {VM_PLATFORM: ['does_not_exists.dart']}),
384 };'''); 384 };''');
385 _createSdk(); 385 _createSdk();
386 File file = provider.newFile(_p('/sdk/lib/test/test.dart'), ''); 386 File file = provider.newFile(_p('/sdk/lib/test/test.dart'), '');
387 Source source = file.createSource(FastUri.parse('dart:test')); 387 Source source = file.createSource(FastUri.parse('dart:test'));
388 CompilationUnit unit = SdkPatcher.parse(source, true, listener); 388 CompilationUnit unit = SdkPatcher.parse(source, true, listener);
389 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit); 389 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit);
390 }, throwsArgumentError); 390 }, throwsArgumentError);
391 } 391 }
392 392
393 test_part() {
394 String baseLibCode = r'''
395 library test;
396 part 'test_part.dart';
397 class A {}
398 ''';
399 String basePartCode = r'''
400 part of test;
401 class B {}
402 ''';
403 _setSdkLibraries(r'''
404 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
405 'test' : const LibraryInfo(
406 'test/test.dart',
407 patches: {VM_PLATFORM: ['test/test_patch.dart']}),
408 };''');
409 File fileLib = provider.newFile(_p('/sdk/lib/test/test.dart'), baseLibCode);
410 File filePart =
411 provider.newFile(_p('/sdk/lib/test/test_part.dart'), basePartCode);
412 provider.newFile(
413 _p('/sdk/lib/test/test_patch.dart'),
414 r'''
415 import 'foo.dart';
416
417 @patch
418 class A {
419 int _a() => 1;
420 }
421
422 @patch
423 class B {
424 int _b() => 1;
425 }
426
427 class _C {}
428 ''');
429
430 _createSdk();
431
432 {
433 Uri uri = FastUri.parse('dart:test');
434 Source source = fileLib.createSource(uri);
435 CompilationUnit unit = SdkPatcher.parse(source, true, listener);
436 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit);
437 _assertUnitCode(
438 unit,
439 "library test; part 'test_part.dart'; import 'foo.dart'; "
440 "class A {int _a() => 1;} class _C {}");
441 }
442
443 {
444 Uri uri = FastUri.parse('dart:test/test_part.dart');
445 Source source = filePart.createSource(uri);
446 CompilationUnit unit = SdkPatcher.parse(source, true, listener);
447 patcher.patch(sdk, SdkLibraryImpl.VM_PLATFORM, listener, source, unit);
448 _assertUnitCode(unit, "part of test; class B {int _b() => 1;}");
449 }
450 }
451
393 test_topLevel_class_append() { 452 test_topLevel_class_append() {
394 CompilationUnit unit = _doTopLevelPatching( 453 CompilationUnit unit = _doTopLevelPatching(
395 r''' 454 r'''
396 class A {} 455 class A {}
397 ''', 456 ''',
398 r''' 457 r'''
399 class _B { 458 class _B {
400 void mmm() {} 459 void mmm() {}
401 } 460 }
402 '''); 461 ''');
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void _setSdkLibraries(String code) { 697 void _setSdkLibraries(String code) {
639 provider.newFile( 698 provider.newFile(
640 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); 699 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code);
641 } 700 }
642 701
643 static void _assertPrevNextToken(Token prev, Token next) { 702 static void _assertPrevNextToken(Token prev, Token next) {
644 expect(prev.next, same(next)); 703 expect(prev.next, same(next));
645 expect(next.previous, same(prev)); 704 expect(next.previous, same(prev));
646 } 705 }
647 } 706 }
OLDNEW
« pkg/analyzer/lib/src/dart/sdk/patch.dart ('K') | « pkg/analyzer/lib/src/dart/sdk/patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698