Template:Escape/testcases

Using internal method to remove {{code|{}}:
{{demo |br=0 |{{escape|mode=kill |char=! |{*{#invoke:Escape!main!mode{{=}}kill!{{#invoke:Escape/testcases|test_string2}}!{}*} |* |{{!}} }}}}

Using replace to remove {{code|{}}:
{{demo|br=0|{{escape|mode=kill|char=!|{*{#invoke:Escape!main!mode{{=}}undo!{*{replace!{*{#invoke:Escape!main!mode{{=}}text!{{#invoke:Escape/testcases|test_string2}}}*}!{!}*}*}*}|*|{{!}}}}}}

No removal of {{code|{}} between escape/unescape (escape char not restored):
undefined

Restore to original after escape
undefined

Remove the word test if not escaped and then place a different escape char in the place of the old escape char (for use by something else):
Note: The '%' char is a special in Lua, so use '%%' if that is the desired replacement. Otherwise, just a single char is fine (or a word). {{#invoke:Escape|main|mode=kill||test|%% }}