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

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

Issue 2416073002: Add support for patching fields. (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 840d4c5280c7eac3f27d3c210147dc4c4043d597..5b4422b52e66e9257ea4c0aa87af393baac28eea 100644
--- a/pkg/analyzer/test/src/dart/sdk/patch_test.dart
+++ b/pkg/analyzer/test/src/dart/sdk/patch_test.dart
@@ -226,6 +226,96 @@ class C {
_assertPrevNextToken(constructor.endToken, clazz.rightBracket);
}
+ test_class_field_append() {
+ CompilationUnit unit = _doTopLevelPatching(
+ r'''
+class C {
+ void a() {}
+}
+''',
+ r'''
+@patch
+class C {
+ int _b = 42;
+}
+''');
+ _assertUnitCode(unit, 'class C {void a() {} int _b = 42;}');
+ ClassDeclaration clazz = unit.declarations[0];
+ MethodDeclaration a = clazz.members[0];
+ FieldDeclaration b = clazz.members[1];
+ _assertPrevNextToken(a.endToken, b.beginToken);
+ _assertPrevNextToken(b.endToken, clazz.rightBracket);
+ }
+
+ test_class_field_append_fail_moreThanOne() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+class A {}
+''',
+ r'''
+@patch
+class A {
+ @patch
+ int _f1, _f2;
+}
+''');
+ }, throwsArgumentError);
+ }
+
+ test_class_field_append_fail_notPrivate() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+class A {}
+''',
+ r'''
+@patch
+class A {
+ @patch
+ int b;
+}
+''');
+ }, throwsArgumentError);
+ }
+
+ test_class_field_append_publiInPrivateClass() {
+ CompilationUnit unit = _doTopLevelPatching(
+ r'''
+class _C {
+ void a() {}
+}
+''',
+ r'''
+@patch
+class _C {
+ int b = 42;
+}
+''');
+ _assertUnitCode(unit, 'class _C {void a() {} int b = 42;}');
+ ClassDeclaration clazz = unit.declarations[0];
+ MethodDeclaration a = clazz.members[0];
+ FieldDeclaration b = clazz.members[1];
+ _assertPrevNextToken(a.endToken, b.beginToken);
+ _assertPrevNextToken(b.endToken, clazz.rightBracket);
+ }
+
+ test_class_field_patch_fail() {
+ expect(() {
+ _doTopLevelPatching(
+ r'''
+class A {}
+''',
+ r'''
+@patch
+class A {
+ @patch
+ int _f;
+}
+''');
+ }, throwsArgumentError);
+ }
+
test_class_getter_append() {
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