diff --git a/lib/src/Formatters/SuperFormalParameterFormatter.dart b/lib/src/Formatters/SuperFormalParameterFormatter.dart index 66cc965..079ed8b 100644 --- a/lib/src/Formatters/SuperFormalParameterFormatter.dart +++ b/lib/src/Formatters/SuperFormalParameterFormatter.dart @@ -26,6 +26,7 @@ class SuperFormalParameterFormatter extends IFormatter if (node is! SuperFormalParameter) throw FormatException('Not a SuperFormalParameter: ${node.runtimeType}'); + formatState.acceptList(node.sortedCommentAndAnnotations, astVisitor, '$methodName/node.sortedCommentAndAnnotations'); formatState.copyEntity(node.requiredKeyword, astVisitor, '$methodName/node.requiredKeyword'); if (node.type != null) diff --git a/test/Formatters/SuperFormalParameterFormatter_test.dart b/test/Formatters/SuperFormalParameterFormatter_test.dart new file mode 100644 index 0000000..a878bf1 --- /dev/null +++ b/test/Formatters/SuperFormalParameterFormatter_test.dart @@ -0,0 +1,39 @@ +import 'package:analyzer/dart/ast/ast.dart'; +import 'package:dart_format/src/Formatters/SuperFormalParameterFormatter.dart'; + +import '../TestTools/AstCreator.dart'; +import '../TestTools/TestGroupConfig.dart'; +import '../TestTools/TestTools.dart'; +import '../TestTools/Visitors/TestVisitor.dart'; + +void main() +{ + TestTools.init(); + + final List testGroupConfigs = [ + TestGroupConfig( + inputNodeCreator: AstCreator.createFormalParameterInFunction, + inputLeading: 'void f(', + inputMiddle: '@a int super.s', + inputTrailing: '){}', + name: 'SuperFormalParameter', + astVisitors: >[ + TestVisitor(7, '@a'), + TestVisitor(10, 'int') + ] + ), + TestGroupConfig( + inputNodeCreator: AstCreator.createFormalParameterInDefaultFormalParameterInFunction, + inputLeading: 'void f({', + inputMiddle: '@a required int super.s', + inputTrailing: '}){}', + name: 'SuperFormalParameter with named', + astVisitors: >[ + TestVisitor(8, '@a'), + TestVisitor(20, 'int') + ] + ) + ]; + + TestTools.runTestGroupsForFormatter(testGroupConfigs, 'SuperFormalParameterFormatter', SuperFormalParameterFormatter.new, StackTrace.current); +} diff --git a/test/TestTools/AstCreator.dart b/test/TestTools/AstCreator.dart index 49ced55..f532251 100644 --- a/test/TestTools/AstCreator.dart +++ b/test/TestTools/AstCreator.dart @@ -93,6 +93,12 @@ class AstCreator static FormalParameter createFormalParameterInFunction(String s) => createFormalParameterListInFunction(s).parameters[0]; + static DefaultFormalParameter createDefaultFormalParameterInFunction(String s) + => createFormalParameterInFunction(s) as DefaultFormalParameter; + + static FormalParameter createFormalParameterInDefaultFormalParameterInFunction(String s) + => createDefaultFormalParameterInFunction(s).parameter; + static FormalParameterList createFormalParameterListInFunction(String s) => createFunctionExpression(s).parameters!;