Skip to content

Commit

Permalink
Add some nqp::hllizefor tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmurias committed Jan 27, 2016
1 parent 6e6470b commit 527fd9d
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion t/nqp/97-hll.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
plan(10);
plan(18);

ok(nqp::bindhllsym("blabla", "key1", "value1") eq 'value1', 'nqp::bindhllsym');
nqp::bindhllsym("blabla", "key2", "value2");
Expand All @@ -19,3 +19,33 @@ ok(nqp::gethllsym("nqp", "key3") eq "value4", 'nqp::bindcurhllsym/nqp::gethllsym
nqp::bindhllsym("nqp", "key4", "value5");

ok(nqp::getcurhllsym("key4") eq "value5", 'nqp::bindhllsym/nqp::getcurhllsym combo');

nqp::sethllconfig('foobar', nqp::hash(
'foreign_transform_hash', -> $hash {
'HASH:' ~ $hash<key>;
},
'foreign_transform_array', -> $array {
'ARRAY:' ~ $array[2];
},
'foreign_transform_code', -> $code {
sub ($value) {$code($value) * 10};
},
'null_value', 'fearsome *NULL*'
));

nqp::sethllconfig('empty', nqp::hash(
));

ok(nqp::hllizefor(nqp::hash('key', 'value1'), 'foobar') eq 'HASH:value1', 'hllizefor with hash');
ok(nqp::hllizefor(nqp::list('the 0th one', 'the 1st one', 'the 2nd'), 'foobar') eq 'ARRAY:the 2nd', 'hllizefor with nqp::list');
my $sub := nqp::hllizefor(sub ($value) {$value+2}, 'foobar');
ok($sub(5) == 70, 'hllizerfor with coderef');
ok(nqp::hllizefor(nqp::null(), 'foobar') eq 'fearsome *NULL*', 'hllizerfor with null');

my $hash := nqp::hash('key', 'value1');
my $list := nqp::list('the 0th one', 'the 1st one', 'the 2nd');

ok(nqp::eqaddr($hash, $hash), 'preserving hash');
ok(nqp::eqaddr(nqp::hllizefor($list, 'empty'), $list), 'preserving list');
ok(nqp::eqaddr(nqp::hllizefor($sub, 'empty'), $sub), 'preserving code ref');
ok(nqp::isnull(nqp::hllizefor(nqp::null(), 'empty')), 'preserving null');

0 comments on commit 527fd9d

Please sign in to comment.