File:  [parser3project] / parser3 / tests / 246.html
Revision 1.3: download - view: text, annotated - select for diffs - revision graph
Mon May 20 23:28:44 2024 UTC (2 years ago) by moko
Branches: MAIN
CVS tags: release_3_5_1, release_3_5_0, HEAD
@try-catch-comment added and used

@main[]
$h[^hash::create[]]
^first_and_last[Empty hash (^$h[^^hash::create[]]);$h]

$h.1[a]
^first_and_last[One element was added (^$h.1[a]);$h]

^h.delete[1]
^first_and_last[One element was deleted (^^h.delete[1]);$h]

$h.1[a]
^first_and_last[One element was added (^$h.1[a]);$h]

$h[
	$.1[a]
	$.2[b]
	$.3[c]
	$.4[d]
	$.5[e]
]
^first_and_last[Hash with 5 elements (^$h[ ^$.1[a] ^$.2[b] ^$.3[c] ^$.4[d] ^$.5[e] ]);$h]

^h.delete[5]
^first_and_last[The last element was deleted (^^h.delete[5]);$h]

^h.delete[1]
^first_and_last[The first element was deleted (^^h.delete[1]);$h]

$h.5[e]
^first_and_last[One element was added at the end (^$h.5[e]);$h]

$h.3[cc]
^first_and_last[One element was added at the middle (^$h.3[cc]);$h]

<h3>_at on hash with 5 elements (^$h[ ^$.1[a] ^$.2[b] ^$.3[c] ^$.4[d] ^$.5[e] ])</h3>
$h[
	$.1[a]
	$.2[b]
	$.3[c]
	$.4[d]
	$.5[e]
]
^at(0)
^at(1)
^at(2)
^at(3)
^at(4)

<br />
^at(-1)
^at(-2)
^at(-3)
^at(-4)
^at(-5)

<br />
^at(0)[key]
^at(1)[key]
^at(2)[key]
^at(3)[key]
^at(4)[key]

<br />
^at(0)[value]
^at(1)[value]
^at(2)[value]
^at(3)[value]
^at(4)[value]

<br />
^at(0)[hash]
^at(1)[hash]
^at(2)[hash]
^at(3)[hash]
^at(4)[hash]

<br />
# check if values preserve tainting. keys are always lost tainting
<h3>The first element was replaced (^$h.1[b&b])</h3>
$h.1[b&b]
^^h._at[first;hash]=^print[^h._at[first;hash]]<br />
^at(0)[key]
^at(0)[value]
^at(0)[hash]
<h3>One element was added at the end (^$h.[c&c][^^taint[d&d]])</h3>
$h.[c&c][^taint[d&d]]
^at(5)[key]
^at(5)[value]
^at(5)[hash]
^^h._at[last;hash]=^print[^h._at[last;hash]]<br />

<br />
^do[^^h._at[]]{must fail^h._at[]}
^do[^^h._at[first^;key^;hren]]{must fail^h._at[first;key;hren]}
^do[^^h._at(1){code}]{must fail^h._at(1){code}}
^do[^^h._at(1)(true)]{must fail^h._at(1)(true)}
^do[^^h._at[hren]]{must fail^h._at[hren]}
^do[^^h._at[first][hren]]{must fail^h._at[first][hren]}
^do[^^h._at[last][hren]]{must fail^h._at[last][hren]}
^do[^^h._at(1)[hren]]{must fail^h._at(1)[hren]}

@at[i;type]
^^h._at($i)^if(def $type){[$type]}=^print[^if(def $type){^h._at($i)[$type]}{^h._at($i)}]<br />

@first_and_last[sTitle;h]
^if(def $sTitle){<h3>$sTitle</h3>}
first:last='^h._at[first]':'^h._at[last;value]'<br />
first_key:last_key='^h._at[first;key]':'^h._at[last;key]'<br />

@do[label;code]
$label=^try{${code}}{$exception.handled(true)<b>^taint[as-is;$exception.comment]</b>}<br />

@print[u][k;v]
^if($u is "hash"){
	$result[^u.foreach[k;v]{'$k':'$v'}[, ]]
}{
	$result[$u]
}

E-mail: