From 1f02f2a7926c0d56c11bfe516fa6dffc0c80d480 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Tue, 6 Dec 2022 13:52:47 -0800 Subject: [PATCH] Add an example of generating an anonymous closure This fixes https://github.com/dart-lang/code_builder/issues/381. --- test/specs/method_test.dart | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/specs/method_test.dart b/test/specs/method_test.dart index 0f2e093..297afeb 100644 --- a/test/specs/method_test.dart +++ b/test/specs/method_test.dart @@ -590,4 +590,19 @@ void main() { '''), ); }); + + test('should create a method as a closure', () { + expect( + Method( + (b) => b + ..requiredParameters.add( + Parameter((b) => b..name = 'a'), + ) + ..body = const Code(''), + ).closure, + equalsDart(r''' + (a) { } + '''), + ); + }); }