Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of concept bindings for fetch_delete_key and a regression test. #658

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,7 @@ QAST::MASTOperations.add_core_moarop_mapping('bindkey_n', 'bindkey_n', 2);
QAST::MASTOperations.add_core_moarop_mapping('bindkey_s', 'bindkey_s', 2);
QAST::MASTOperations.add_core_moarop_mapping('existskey', 'existskey');
QAST::MASTOperations.add_core_moarop_mapping('deletekey', 'deletekey');
QAST::MASTOperations.add_core_moarop_mapping('fetch_delete_key', 'fetch_delete_key');
QAST::MASTOperations.add_core_moarop_mapping('elems', 'elems');
QAST::MASTOperations.add_core_moarop_mapping('setelems', 'setelemspos', 0);
QAST::MASTOperations.add_core_moarop_mapping('dimensions', 'dimensions');
Expand Down
19 changes: 18 additions & 1 deletion t/nqp/108-vmhash.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plan(28);
plan(41);

my $backend := nqp::getcomp('nqp').backend.name;

Expand Down Expand Up @@ -100,3 +100,20 @@ $key := nqp::iterkey_s($iter);
ok(nqp::existskey($hash, $key), 'second key from iterator exists');
nqp::deletekey($hash, $key);
ok(!nqp::existskey($hash, $key), 'second key from iterator no longer exists');
is(nqp::elems($hash), 0, 'hash has no elements');

$hash<a> := 1;
$hash<b> := 2;
is(nqp::elems($hash), 2, 'hash has 2 elements once more');
ok(!nqp::defined(nqp::fetch_delete_key($hash, 'c')), 'key not found');
is(nqp::elems($hash), 2, 'hash still has 2 elements');
is(nqp::fetch_delete_key($hash, 'a'), 1, 'key is found');
is(nqp::elems($hash), 1, 'key was deleted');
ok(!nqp::existskey($hash, 'a'), 'key no longer exists');
ok(nqp::existskey($hash, 'b'), 'second key still exists');
ok(!nqp::defined(nqp::fetch_delete_key($hash, 'a')), 'key is gone');

is(nqp::fetch_delete_key($hash, 'b'), 2, 'second key is found');
is(nqp::elems($hash), 0, 'second key was deleted');
ok(!nqp::existskey($hash, 'b'), 'second key no longer exists');
ok(!nqp::defined(nqp::fetch_delete_key($hash, 'b')), 'second key is gone');