Improve FnType to add a body or block

Signed-off-by: David Arendsen <darendsen@gamepoint.com>
This commit is contained in:
David Arendsen 2023-03-08 21:20:20 +01:00
commit ec73c70706
4 changed files with 56 additions and 26 deletions

View file

@ -81,12 +81,16 @@ final class FactoryTypeTest extends TestCase
'this can be anything'
],
'FnType with only content' => [
new FnType('(r) => ({ r with _value: r._value * r._value })'),
'(r) => ({ r with _value: r._value * r._value })'
FnType::params([])->withBlock('r with _value: r._value * r._value'),
'() => { r with _value: r._value * r._value }'
],
'FnType with params and content' => [
new FnType(['r', 'a'], '({ r with _value: r._value * r._value })'),
'(r, a) => ({ r with _value: r._value * r._value })'
'FnType with params and a body' => [
FnType::params(['r'])->withBody('r with _value: r._value * r._value'),
'(r) => r with _value: r._value * r._value'
],
'FnType with params and a block' => [
FnType::params(['r', 'a'])->withBlock('return r with _value: r._value * r._value'),
'(r, a) => { return r with _value: r._value * r._value }'
],
];
}