Last modified: 2009-06-05 17:16:53 UTC
Enter: <{{#switch: foo | bar = bar | #default | baz = quok }}> Expected: <quok> Actual: <> The #default delimiter is only recognised as such if it is the last in a duplicate stack.
That's how it is in all programming languages I know.
(In reply to comment #0) > Enter: > > <{{#switch: foo | bar = bar | #default | baz = quok }}> > > Expected: > > <quok> > > Actual: > > <> I'm confused, <> should be expected, because 'foo' doesn't have its own entry. Perhaps you mean #switch: baz
<{{#switch: foo | bar = bar | #default = quuz | baz = quok }}> outputs <quuz> as expected. WORKSFORME. (In reply to comment #1) > That's how it is in all programming languages I know. $ echo '<?php switch(1) { default: echo "default\n"; break; case 2: echo "2\n"; break; }' | php default Also probably not in C. Why would such a restriction exist?
Wow, edit conflicts on bugzilla! But as we're all so fond of saying, wikimarkup is not a programming language :P The clear intention for the layman is for the "#default" to act as a marker for 'none of the above' (or indeed 'none of the below' as the #default case doesn't have to be the last in the sequence). If we replaced "#default" by "foo" in the example, then we'd get <{{#switch: foo | bar = bar | foo | baz = quok }}> --> <quok> as expected. The implication of the "#default" marker is that it *always* matches the test string, unless another explicit marker matches. The bug is that this universal-matching is position-dependent: <{{#switch: foo | bar | baz = ABC | #default = DEF }}> --> <DEF> <{{#switch: foo | bar | #default = DEF | baz = ABC }}> --> <DEF> <{{#switch: foo | #default | bar = DEF | baz = ABC }}> --> <> That doesn't look very intuitive to me.
(In reply to comment #4) > <{{#switch: foo | bar | baz = ABC | #default = DEF }}> --> <DEF> > <{{#switch: foo | bar | #default = DEF | baz = ABC }}> --> <DEF> > <{{#switch: foo | #default | bar = DEF | baz = ABC }}> --> <> > > That doesn't look very intuitive to me. Those test cases differ in more than position. The first two don't differ except for position, and they give the same output. The first two differ from the last test case in that the DEF has been moved from #default to bar, and therefore you get a different result. Where's the bug?
(In reply to comment #5) > Those test cases differ in more than position. > > The first two don't differ except for position, and they give the same output. > > The first two differ from the last test case in that the DEF has been moved > from #default to bar, and therefore you get a different result. > > Where's the bug? The syntax {{#switch: foo | bar | baz=quuz}} is supposed to be equivalent to {{#switch: foo | bar=quuz | baz=quuz}}. I.e., we support a kind of fallthrough, but it only worked for named parameters, not #default. He's right, this is a bug.
Fixed in r51509 and r51511.