Content deleted Content added
No edit summary Tags: Reverted Mobile edit Mobile web edit |
m Reverted edits by 205.207.203.15 (talk) (HG) (3.4.13) |
||
(8 intermediate revisions by 7 users not shown) | |||
Line 1:
{{permprot}}
{{copied|from=Module:Yesno|from_oldid=828075573|to=:incubator:Module:Wp/nod/Yesno|to_diff=4237022}}
==Testcases and documentation==
<pre>
{| class="wikitable"
|+ Test Cases (via [[Template:Yesno/doc]])
|-
! Module output
! Template output
! Expected
|-
| {{#invoke:Yesno|yesno|yes}}
| {{yesno|yes}}
| yes
|-
| {{#invoke:Yesno|yesno|YeS}}
| {{yesno|YeS}}
| yes
|-
| {{#invoke:Yesno|yesno|Y}}
| {{yesno|Y}}
| yes
|-
| {{#invoke:Yesno|yesno|y}}
| {{yesno|y}}
| yes
|-
| {{#invoke:Yesno|yesno|no}}
| {{yesno|no}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|}}
| {{yesno|}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno}}
| {{yesno}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|¬}}
| {{yesno|¬}}
| ''(blank)''
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher}}
| {{yesno|purplemonkeydishwasher}}
| yes
|-
| {{#invoke:Yesno|yesno|yes|yes=bacon}}
| {{yesno|yes|yes=bacon}}
| bacon
|-
| {{#invoke:Yesno|yesno|no|no=ham}}
| {{yesno|no|no=ham}}
| ham
|-
| {{#invoke:Yesno|yesno|blank= eggs}}
| {{yesno|blank= eggs}}
|
|-
| {{#invoke:Yesno|yesno|no=ham}}
| {{yesno|no=ham}}
|
|-
| {{#invoke:Yesno|yesno|blank= eggs|no=ham}}
| {{yesno|blank= eggs|no=ham}}
|
|-
| {{#invoke:Yesno|yesno|¬|¬=sausage}}
| {{yesno|¬|¬=sausage}}
| sausage
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea}}
| {{yesno|purplemonkeydishwasher|def=cup-of-tea}}
| cup-of-tea
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|yes=bacon}}
| {{yesno|purplemonkeydishwasher|yes=bacon}}
| bacon
|-
| {{#invoke:Yesno|yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}}
| {{yesno|purplemonkeydishwasher|def=cup-of-tea|yes=bacon}}
| cup-of-tea
|-
| {{#invoke:Yesno|yesno|yes|yes=no|no=yes}}
| {{yesno|yes|yes=no|no=yes}}
| no
|-
| {{#invoke:Yesno|yesno|no|yes=no|no=yes}}
| {{yesno|no|yes=no|no=yes}}
| yes
|-
| {{#invoke:Yesno|yesno| no |no=no}}
| {{yesno| no |no=no}}
| no
|}
</pre>
:<small>Note: Pre tags added to suppress script errors. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 14:25, 20 September 2013 (UTC)</small>
As you can see, the template does not behave exactly as its documentation claims it does. I was not sure which to regard as authoritative: the ideal or actual implementation. I ultimately went with the former. Removing <code>and not any</code> from the Lua code will make the module behave like exactly like the template.
--[[User:Ori.livneh|Ori.livneh]] ([[User talk:Ori.livneh|talk]]) 10:46, 28 February 2013 (UTC)
:Just needs to handle spaces in the params better. -- [[User:WOSlinker|WOSlinker]] ([[User talk:WOSlinker|talk]]) 11:41, 2 March 2013 (UTC)
::Thanks. Fixed. I moved your test case to the table above. --[[User:Ori.livneh|Ori.livneh]] ([[User talk:Ori.livneh|talk]]) 05:58, 3 March 2013 (UTC)
:::Yesno has ~8M transclusions. No question it should handle the legacy 1:1. Test it. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 22:31, 11 March 2013 (UTC)
The documentation is wrong. The "egg" example assumes thet the input value is ''blank''. But in the code examples the input parameter is ''omitted''. Compare:
* <nowiki>{{yesno|blank= eggs|no=ham}}</nowiki> → {{yesno|blank= eggs|no=ham}}
* <nowiki>{{yesno||blank= eggs|no=ham}}</nowiki> → {{yesno||blank= eggs|no=ham}}
This is what is actually documented:
* <nowiki>{{yesno|blank= eggs|no=ham|¬=bread}}</nowiki> → {{yesno|blank= eggs|no=ham|¬=bread}}
:I have changed the documentation. Not the table above. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 13:16, 23 March 2013 (UTC)
== Why? ==
{{tl|yesno}} is quite simple, so I'm not sure if there is a point in replacing it with functionally equivalent Lua. There are many cases where Lua can be much faster and easier to read, but I'm not sure that is the case here. In fact, because of the slight overhead with #invoke, simple parser functions can actually be slightly faster than the equivalent Lua. I haven't tested that here, but I wouldn't be surprised if there is no performance advantage in a case like this. Seems like a strange template to target for Lua conversion. [[User:Dragons flight|Dragons flight]] ([[User talk:Dragons flight|talk]]) 14:57, 12 March 2013 (UTC)
It’s just for compatibility. For some weird reason, yesno might not work and this will.
<span style="font-family:'Arial';">[[User:E Super Maker|E Super Maker]]</span> ([[User talk:E Super Maker|😲 shout]]) 15:47, 23 November 2019 (UTC)
== test failed ==
{{resolved}}
Line 100 ⟶ 218:
Where lines 15 and 23 are new compared to the current code. <span style="border:1px solid maroon; padding:0 2px">[[User:CRwikiCA|<span style="font-family:'Courier';color:maroon">CRwikiCA</span>]] [[User talk:CRwikiCA|<i style="color:navy">talk</i>]]</span> 18:17, 23 April 2015 (UTC)
:No opposition, so {{done}} — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 10:43, 27 April 2015 (UTC)
::I would be interested to know cases where such "t/f" values may be encountered. I know that in command prompts we may encounter "y/n" choices. But I cannot recall having ever encountered "t/f".
::Refs [[phab:T137584|T137584]] (« Allow Scribunto code to add a category without changing output »), which would allow to know on what (and how many) pages these values are actually used.
::[[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 00:05, 20 October 2024 (UTC)
== Support on/off detection ==
Line 131 ⟶ 252:
::This can also mostly be handled by specifying the default parameter (i.e. <syntaxhighlight lang="lua" inline>myvariable = yesno(value, false)</syntaxhighlight>), although this does leave the case <syntaxhighlight lang="lua" inline>yesno(nil, false)</syntaxhighlight>, which evaluates to <syntaxhighlight lang="lua" inline>nil</syntaxhighlight>. The reason I originally programmed the module this way is so that it can be mostly backwards-compatible with [[Template:Yesno]], which it is intended to replace. Originally the plan was to do a straight conversion of [[Template:Yesno]] to Lua, but it turned out that doing that was actually slower than just using the template, given the template's simplicity and the initial cost of switching between PHP and Lua. So instead this module became Lua-only, with most of the behaviour of [[Template:Yesno]]. The intention there was that module writers could easily incorporate it into modules that convert more complex templates without having to change the template logic too much. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 22:11, 23 December 2021 (UTC)
:::OK, thx. I can use this code solution with confidence now, no research-&-test needed. Might as well add it to the /doc. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 16:35, 24 December 2021 (UTC)
::::The abovementioned <code>yesno(value) or true/false</code> has a common pitfall and should be avoided: if value is "false", <code>yesno(value) or true</code> would gives "true", instead of the presumably expected "false". See section « Standard solution: and/or » on [http://lua-users.org/wiki/TernaryOperator this page]. [[User:Od1n|Od1n]] ([[User talk:Od1n|talk]]) 18:15, 22 September 2024 (UTC)
|