3 ms·
> But, how do you systematically unit test nested functions? Why, with nested unittests, of course! Just put them in a nested type first: void main() {
by CyberShadow 8y ago
> But, how do you systematically unit test nested functions?
Why, with nested unittests, of course! Just put them in a nested type first:
void main()
{
static int nested(int x)
{
return x * 2;
}
struct Test
{
unittest
{
assert(nested(2) == 4);
}
}
}
Well, OK, that's more of a hack than a feature, and you obviously can't test non-static nested functions (as there'd be no way to give values to the outer function's frame variables). But you asked :)
- deleted 8y ago[deleted]