Add test case for ‘format’ bug and refactor