Add unit test for greedy template replacement

This adds the missing unit test for #2497.