Support (x, y) when z, closes #1313
Add tests for nested whens