Jump to content

Module:Escape/testcases: Difference between revisions

From Humanipedia
hp>Codehydro
mNo edit summary
 
hp>Codehydro
m remove nowiki
Line 1: Line 1:
p = {}
====Original:====
{{#invoke:Escape/testcases|test_string2}}


function p.test_string()
====Using internal method to remove {{code|{}}:====
  return 'test, \\test, \\{,test\\\\ \\\\ \\\\\\\\'
{{demo
end
  |br=0
|{{escape|mode=kill
  |char=!
  |{*{#invoke:Escape!main!mode{{=}}kill!{{#invoke:Escape/testcases|test_string2}}!{}*}
  |*
  |{{!}}
}}}}


function p.test_string2()
====Using {{t|replace}} to remove {{code|{}}:====
return 'test { test {\\{ test, \\test, \\{,test\\ \\ \\ {\\'
{{demo|br=0|{{escape|mode=kill|char=!|{*{#invoke:Escape!main!mode{{=}}undo!{*{replace!{*{#invoke:Escape!main!mode{{=}}text!{{#invoke:Escape/testcases|test_string2}}}*}!{!}*}*}*}|*|{{!}}}}}}
end


function p.test_string_module(frame)
====No removal of {{code|{}} between escape/unescape (escape char not restored):====
return (p['test_string' .. (frame.args[1] or '')]():gsub('\\', '\\\\'))
{{demo|br=0|{{escape|mode=kill|char=!|{*{#invoke:Escape!main!mode{{=}}undo
end
!{*{#invoke:Escape!main!mode{{=}}text!{{#invoke:Escape/testcases|test_string2}}}*}
*}*}|*|{{!}}}}}}


function p.test_kill500(frame)
====Restore to original after escape====
local esc = require('Module:Escape')
{{demo|br=0|{{escape|mode=kill|char=!|{*{#invoke:Escape!main!mode{{=}}undo
for k = 1, 500 do
!{*{#invoke:Escape!main!mode{{=}}text!{{#invoke:Escape/testcases|test_string2}}}*}
  local v = esc:kill(p.test_string2(), 'test')
!\
end
*}*}|*|{{!}}}}}}
return os.clock(esc)
end


return p
====Remove the word {{code|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).
{{demo|br=0|{{((}}#invoke:Escape{{!}}main{{!}}mode{{=}}kill
{{!}}{{#invoke:Escape/testcases|test_string2}}
{{!}}test
{{!}}%%
{{))}}}}

Revision as of 15:21, 16 January 2015

Original:

Lua error at line 1: unexpected symbol near '=='.

Using internal method to remove <syntaxhighlight lang="text" class="" style="" inline="1">{</syntaxhighlight>:

Lua error in package.lua at line 80: module 'Module:Yesno' not found.

Using {{replace}} to remove <syntaxhighlight lang="text" class="" style="" inline="1">{</syntaxhighlight>:

Lua error in package.lua at line 80: module 'Module:Yesno' not found.

No removal of <syntaxhighlight lang="text" class="" style="" inline="1">{</syntaxhighlight> between escape/unescape (escape char not restored):

Lua error in package.lua at line 80: module 'Module:Yesno' not found.

Restore to original after escape

Lua error in package.lua at line 80: module 'Module:Yesno' not found.

Remove the word <syntaxhighlight lang="text" class="" style="" inline="1">test</syntaxhighlight> 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). Lua error in package.lua at line 80: module 'Module:Yesno' not found.