codegen, tests/when: implement when