Difference between revisions of "Category talk:StripToNumbers/testcases"
Jump to navigation
Jump to search
blackwiki>SMcCandlish m (typo) |
m (31 revisions imported) |
||
| (10 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
| + | {{test cases}} | ||
==Strip units from CSS values (why I want this)== | ==Strip units from CSS values (why I want this)== | ||
| − | * Input | + | * Input: <code>-12em, 34px, 56.7%, "89", 0</code> |
* Result: {{#invoke:StripToNumbers | main | -12em, 34px, 56.7%, "89", 0 }} | * Result: {{#invoke:StripToNumbers | main | -12em, 34px, 56.7%, "89", 0 }} | ||
| − | * Input (will choke because of multiple <code>.</code> characters: -12em, 34px, 56.7%, "8.9", 0 | + | * Input (will choke because of multiple <code>.</code> characters: <code>-12em, 34px, 56.7%, "8.9", 0</code> |
* Result: {{#invoke:StripToNumbers | main | -12em, 34px, 56.7%, "8.9", 0 }} | * Result: {{#invoke:StripToNumbers | main | -12em, 34px, 56.7%, "8.9", 0 }} | ||
| − | * Input (will choke because of multiple <code>-</code> characters: -12em, 34px, 57%, "-8.9", 0 | + | * Input (will choke because of multiple <code>-</code> characters: <code>-12em, 34px, 57%, "-8.9", 0</code> |
* Result: {{#invoke:StripToNumbers | main | -12em, 34px, 57%, "-8.9", 0 }} | * Result: {{#invoke:StripToNumbers | main | -12em, 34px, 57%, "-8.9", 0 }} | ||
| − | * Input: inherit | + | * Input: <code>inherit</code> |
* Result: {{#invoke:StripToNumbers | main | inherit }} | * Result: {{#invoke:StripToNumbers | main | inherit }} | ||
==Find numbers in a bunch of stuff== | ==Find numbers in a bunch of stuff== | ||
| − | * Input: SDks]df9s>dfjklasdfk9kasdfkasdkie0kmc'@(aks | + | * Input: <code>SDks]df9s>dfjklasdfk9kasdfkasdkie0kmc'@(aks</code> |
* Result: {{#invoke:StripToNumbers | main | SDks]df9s>dfjklasdfk9kasdfkasdkie0kmc'@(aks}} | * Result: {{#invoke:StripToNumbers | main | SDks]df9s>dfjklasdfk9kasdfkasdkie0kmc'@(aks}} | ||
| − | * Input: "12.3x4" | + | * Input: <code>"12.3x4"</code> |
* Result: {{#invoke:StripToNumbers | main | "12.3x4" }} | * Result: {{#invoke:StripToNumbers | main | "12.3x4" }} | ||
==Halve number found in stuff== | ==Halve number found in stuff== | ||
| − | * Input: foobarbaz50%blahblahblah | + | * Input: <code>foobarbaz50%blahblahblah</code> |
* Result: {{#invoke:StripToNumbers | halve | foobarbaz50%blahblahblah}} | * Result: {{#invoke:StripToNumbers | halve | foobarbaz50%blahblahblah}} | ||
| − | * Input: -66.6666666666666666666666666666 | + | * Input: <code>-66.6666666666666666666666666666</code> |
* Result: {{#invoke:StripToNumbers | halve | -66.6666666666666666666666666666}} | * Result: {{#invoke:StripToNumbers | halve | -66.6666666666666666666666666666}} | ||
| − | * Input: chickenbutt | + | * Input: <code>chickenbutt</code> |
* Result: {{#invoke:StripToNumbers | halve | chickenbutt }} | * Result: {{#invoke:StripToNumbers | halve | chickenbutt }} | ||
==Nastier input tests== | ==Nastier input tests== | ||
| − | * Input: style="font-size: 70% ;" | + | * Input: <code>style="font-size: 70% ;"</code> |
* Result: {{#invoke:StripToNumbers | main | style="font-size: 70% ;"}} | * Result: {{#invoke:StripToNumbers | main | style="font-size: 70% ;"}} | ||
| − | * Input: 'style="font-size: 70% ;"' | + | * Input: <code>'style="font-size: 70% ;"'</code> |
* Result: {{#invoke:StripToNumbers | main | 'style="font-size: 70% ;"'}} | * Result: {{#invoke:StripToNumbers | main | 'style="font-size: 70% ;"'}} | ||
| − | * Input: `style="font-size: 70% ;"` | + | * Input: <code>`style="font-size: 70% ;"`</code> |
* Result: {{#invoke:StripToNumbers | main | `style="font-size: 70% ;"`}} | * Result: {{#invoke:StripToNumbers | main | `style="font-size: 70% ;"`}} | ||
| − | * Input: =70% | + | * Input: <code>=70%</code> |
* Result: {{#invoke:StripToNumbers | main | =70% }} | * Result: {{#invoke:StripToNumbers | main | =70% }} | ||
| − | Yeah, it dies on contact with <code>=</code>. Can it be escaped? | + | Yeah, it dies on contact with <code>=</code>. Can it be escaped? (see below: use {{para|1|=70%}}) |
| − | * Input: {{=}}70% | + | * Input: <code>{<nowiki />{=}}70%</code> |
* Result: {{#invoke:StripToNumbers | main | {{=}}70% }} | * Result: {{#invoke:StripToNumbers | main | {{=}}70% }} | ||
| − | * Input: style{{=}}"font-size: 70% ;" | + | * Input: <code>style{<nowiki />{=}}"font-size: 70% ;"</code> |
* Result: {{#invoke:StripToNumbers | main | style{{=}}"font-size: 70% ;"}} | * Result: {{#invoke:StripToNumbers | main | style{{=}}"font-size: 70% ;"}} | ||
| − | + | * Input: <code><span style{<nowiki />{=}}"font-size: 70%;"></code> | |
| + | * Result: {{#invoke:StripToNumbers | main | <span style{{=}}"font-size: 70%;">}} | ||
| + | * Input: <code><span style<nowiki>=</nowiki>"font-size: 70%;"></code> | ||
| + | * Result: {{#invoke:StripToNumbers | main | <span style<nowiki>=</nowiki>"font-size: 70%;">}} | ||
| + | Yes, though only with {{tlx|{{=}}}}; it chokes on {{tag|nowiki}}. Though this points out the relative uselessness of trying to use this on strings this complicated, since <code>-70</code> is the opposite of the desired output, <code>70</code>. It needs to be able to discern with <code>-</code> is directly associated with a numeral (or perhaps a <code>.</code>, since while <code>-.7</code> is crappy style, it's still a technically valid way to write <code>-0.7</code>. | ||
| + | |||
| + | '''Try''': {{para|1|=70%}} | ||
| + | * Input: <code>1=70%</code> | ||
| + | * Result: {{#invoke:StripToNumbers | main | 1=70% }} {{aye}} | ||
| + | |||
| + | |||
| + | * Input: <code><span class="nowrap"><span data-sort-value="7001123000000000000♠"></span>12.3</span></code> (produced by <nowiki>{{val|12.3}}</nowiki>) | ||
| + | * Result: {{#invoke:StripToNumbers | main | 1=<span class="nowrap"><span data-sort-value="7001123000000000000♠"></span>12.3</span>}} | ||
| + | |||
| + | == After upgrade to match more narrowly == | ||
| + | * Input: <code>style{<nowiki />{=}}"margin-left: 10% ;"</code> | ||
| + | * Result: {{#invoke:StripToNumbers | main | style{{=}}"margin-left: 10% ;"}} | ||
| + | * Input: <code>style{<nowiki />{=}}"margin-left: -10% ;"</code> | ||
| + | * Result: {{#invoke:StripToNumbers | main | style{{=}}"margin-left: -10% ;"}} | ||
| + | * Input: <code>Weasels - 12. Chickens - 72.</code> | ||
| + | * Result: {{#invoke:StripToNumbers | main | Weasels - 12. Chickens - 72.}} | ||
Latest revision as of 14:12, 28 September 2020
Contents
Strip units from CSS values (why I want this)
- Input:
-12em, 34px, 56.7%, "89", 0 - Result: -12
- Input (will choke because of multiple
.characters:-12em, 34px, 56.7%, "8.9", 0 - Result: -12
- Input (will choke because of multiple
-characters:-12em, 34px, 57%, "-8.9", 0 - Result: -12
- Input:
inherit - Result: Lua error in Module:StripToNumbers at line 8: Input did not contain valid numeric data.
Find numbers in a bunch of stuff
- Input:
SDks]df9s>dfjklasdfk9kasdfkasdkie0kmc'@(aks - Result: 9
- Input:
"12.3x4" - Result: 12.3
Halve number found in stuff
- Input:
foobarbaz50%blahblahblah - Result: 25
- Input:
-66.6666666666666666666666666666 - Result: -33.333333333333
- Input:
chickenbutt - Result: Lua error in Module:StripToNumbers at line 8: Input did not contain valid numeric data.
Nastier input tests
- Input:
style="font-size: 70% ;" - Result: Lua error: bad argument #1 to 'unstrip' (string expected, got nil).
- Input:
'style="font-size: 70% ;"' - Result: Lua error: bad argument #1 to 'unstrip' (string expected, got nil).
- Input:
`style="font-size: 70% ;"` - Result: Lua error: bad argument #1 to 'unstrip' (string expected, got nil).
- Input:
=70% - Result: Lua error: bad argument #1 to 'unstrip' (string expected, got nil).
Yeah, it dies on contact with =. Can it be escaped? (see below: use |1=)
- Input:
{{=}}70% - Result: 70
- Input:
style{{=}}"font-size: 70% ;" - Result: 70
- Input:
<span style{{=}}"font-size: 70%;"> - Result: 70
- Input:
<span style<nowiki>=</nowiki>"font-size: 70%;"> - Result: 70
Yes, though only with {{=}}; it chokes on <nowiki>...</nowiki>. Though this points out the relative uselessness of trying to use this on strings this complicated, since -70 is the opposite of the desired output, 70. It needs to be able to discern with - is directly associated with a numeral (or perhaps a ., since while -.7 is crappy style, it's still a technically valid way to write -0.7.
Try: |1=
- Input:
1=70% - Result: 70

- Input:
<span class="nowrap"><span data-sort-value="7001123000000000000♠"></span>12.3</span>(produced by {{val|12.3}}) - Result: 7.001123e+18
After upgrade to match more narrowly
- Input:
style{{=}}"margin-left: 10% ;" - Result: 10
- Input:
style{{=}}"margin-left: -10% ;" - Result: -10
- Input:
Weasels - 12. Chickens - 72. - Result: 12