Skip to content

Commit

Permalink
[array unset]
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Jun 25, 2010
1 parent 9128ec7 commit f9937b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 12 additions & 2 deletions src/Partcl/commands/array.pm
Expand Up @@ -162,8 +162,18 @@ my sub statistics() {
'XXX';
}

my sub unset() {
'XXX';
my sub unset($array, $pattern = '*') {
my $globber := StringGlob::Compiler.compile($pattern);
for $array -> $key {
if (?Regex::Cursor.parse($key, :rule($globber), :c(0))) {
Q:PIR {
$P1 = find_lex '$array'
$P2 = find_lex '$key'
delete $P1[$P2]
}
}
}
'';
}
Expand Down
10 changes: 5 additions & 5 deletions t/cmd_array.t
Expand Up @@ -168,19 +168,19 @@ eval_is {
catch {unset a}
array set a [list a b]
list [array unset a] [array get a]
} {{} {}} {array unset, effect & return value} {TODO NQPRX}
} {{} {}} {array unset, effect & return value}

eval_is {
catch {unset a}
array set a [list a b c d]
list [array unset a a] [array get a]
} {{} {c d}} {array unset, with pattern & return value} {TODO NQPRX}
} {{} {c d}} {array unset, with pattern & return value}

eval_is {
catch {unset a}
array set a [list apple 1 orange 2 aardvark 3]
list [array unset a a*] [array get a]
} {{} {orange 2}} {array unset with pattern} {TODO NQPRX}
} {{} {orange 2}} {array unset with pattern}

eval_is {
catch {unset a}
Expand All @@ -192,12 +192,12 @@ eval_is {
eval_is {
catch {unset a}
array unset a
} {} {array unset, bad array} {TODO NQPRX}
} {} {array unset, bad array}

eval_is {
catch {unset a}
array unset a monkey*
} {} {array unset, bad array, pattern} {TODO NQPRX}
} {} {array unset, bad array, pattern}

eval_is {
array unset monkey my monkey monkey
Expand Down

0 comments on commit f9937b5

Please sign in to comment.