Add a test for ReplaceAll and fix a bug it found