From: Vincent Pit Date: Wed, 20 Aug 2008 12:40:15 +0000 (+0200) Subject: Fix discrepancy between add('list',1) and add({list=>1},1) in favor of the latter X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=972e76e13b6f6e85c20493bddba2d1fd71fd57f8;p=perl%2Fmodules%2FSub-Nary.git Fix discrepancy between add('list',1) and add({list=>1},1) in favor of the latter --- diff --git a/Nary.xs b/Nary.xs index 95fca93..bcdde48 100644 --- a/Nary.xs +++ b/Nary.xs @@ -171,17 +171,11 @@ CODE: if (!SvOK(cur)) continue; if (!SvROK(cur)) { - if (strEQ(SvPV_nolen(cur), "list")) { - hv_clear(res); - sn_store(res, "list", 4, newSVuv(1), sn_hash_list); - break; - } else { - NV v = 1; - if ((old = hv_fetch_ent(res, cur, 1, 0)) && SvOK(val = HeVAL(old))) - v += SvNV(val); - sn_store_ent(res, cur, newSVnv(v), 0); - continue; - } + NV v = 1; + if ((old = hv_fetch_ent(res, cur, 1, 0)) && SvOK(val = HeVAL(old))) + v += SvNV(val); + sn_store_ent(res, cur, newSVnv(v), 0); + continue; } cur = SvRV(cur); hv_iterinit((HV *) cur); diff --git a/t/15-misc-xs.t b/t/15-misc-xs.t index bd6baac..80de3c5 100644 --- a/t/15-misc-xs.t +++ b/t/15-misc-xs.t @@ -23,11 +23,11 @@ is_deeply(scale(1, {}), { 0 => 1 }, 'scale const, empty-ref'); *add = *Sub::Nary::add{CODE}; -is_deeply(add('list'), { list => 1 }, 'add list'); -is_deeply(add(1, 'list'), { list => 1 }, 'add const, list'); -is_deeply(add({ }, 'list'), { list => 1 }, 'add empty-ref, list'); -is_deeply(add({ 1 => 1 }, 'list'), { list => 1 }, 'add ref, list'); -is_deeply(add({ 1 => 1 }, 1), { 1 => 2 }, 'add ref, prev-const'); +is_deeply(add('list'), { list => 1 }, 'add list'); +is_deeply(add(1, 'list'), { 1 => 1, list => 1 }, 'add const, list'); +is_deeply(add({ }, 'list'), { list => 1 }, 'add empty-ref, list'); +is_deeply(add({ 1 => 1 }, 'list'), { 1 => 1, list => 1 }, 'add ref, list'); +is_deeply(add({ 1 => 1 }, 1), { 1 => 2 }, 'add ref, prev-const'); *cumulate = *Sub::Nary::cumulate{CODE};