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

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

Issue 2405383002: Patch imports and function type aliases. Report more errors. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/dart/sdk/patch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/dart/sdk/patch_test.dart
diff --git a/pkg/analyzer/test/src/dart/sdk/patch_test.dart b/pkg/analyzer/test/src/dart/sdk/patch_test.dart
index 25fc34a5cd1fa24417467d90e9244c01b5e368a9..6c51322b0058f3b564cba7ab5c34a1847149c76b 100644
--- a/pkg/analyzer/test/src/dart/sdk/patch_test.dart
+++ b/pkg/analyzer/test/src/dart/sdk/patch_test.dart
@@ -33,6 +33,32 @@ class SdkPatcherTest {
sdkFolder = provider.getFolder(_p('/sdk'));
}
+ test_directive_fail_export() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+import 'a.dart';
+''',
+ r'''
+export 'c.dart';
+''');
+ }, throwsArgumentError);
+ }
+
+ test_directive_import() {
+ CompilationUnit unit = _doTopLevelPatching(
+ r'''
+import 'a.dart';
+part 'b.dart';
+int bar() => 0;
+''',
+ r'''
+import 'c.dart';
+''');
+ _assertUnitCode(unit,
+ "import 'a.dart'; part 'b.dart'; import 'c.dart'; int bar() => 0;");
+ }
+
test_fail_noSuchLibrary() {
expect(() {
_setSdkLibraries('const LIBRARIES = const {};');
@@ -76,19 +102,19 @@ void set _foo3(int val) {}
'int get _foo2 => 1; void set _foo3(int val) {}');
}
- test_topLevel_fail_append_notPrivate() {
+ test_topLevel_fail_topLevelVariable() {
expect(() {
_doTopLevelPatching(
r'''
-int foo() => 1;
+int foo() => 0;
''',
r'''
-int bar() => 2;
+int _bar;
''');
}, throwsArgumentError);
}
- test_topLevel_fail_noExternalKeyword() {
+ test_topLevel_function_fail_noExternalKeyword() {
expect(() {
_doTopLevelPatching(
r'''
@@ -101,6 +127,54 @@ int foo() => 1;
}, throwsArgumentError);
}
+ test_topLevel_function_fail_notPrivate() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+int foo() => 1;
+''',
+ r'''
+int bar() => 2;
+''');
+ }, throwsArgumentError);
+ }
+
+ test_topLevel_functionTypeAlias_append() {
+ CompilationUnit unit = _doTopLevelPatching(
+ r'''
+int foo() => 0;
+''',
+ r'''
+typedef int _bar();
+''');
+ _assertUnitCode(unit, 'int foo() => 0; typedef int _bar();');
+ }
+
+ test_topLevel_functionTypeAlias_fail_hasAnnotation() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+int foo() => 0;
+''',
+ r'''
+@patch
+typedef int _bar();
+''');
+ }, throwsArgumentError);
+ }
+
+ test_topLevel_functionTypeAlias_fail_notPrivate() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+int foo() => 0;
+''',
+ r'''
+typedef int bar();
+''');
+ }, throwsArgumentError);
+ }
+
test_topLevel_patch_function() {
CompilationUnit unit = _doTopLevelPatching(
r'''
@@ -114,6 +188,18 @@ int foo() => 1;
_assertUnitCode(unit, 'int foo() => 1; int bar() => 2;');
}
+ test_topLevel_patch_function_blockBody() {
+ CompilationUnit unit = _doTopLevelPatching(
+ r'''
+external int foo();
+''',
+ r'''
+@patch
+int foo() {int v = 1; return v + 2;}
+''');
+ _assertUnitCode(unit, 'int foo() {int v = 1; return v + 2;}');
+ }
+
test_topLevel_patch_getter() {
CompilationUnit unit = _doTopLevelPatching(
r'''
« no previous file with comments | « 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