Skip to content
Newer
Older
100644 42 lines (26 sloc) 1.09 KB
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
1 #!./parrot nqp.pbc
2
3 # check hash access methods
4
7914bf6 @pmurias Test calling nqp::elems on hashes.
pmurias authored
5 plan(15);
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
6
7 my %h;
8
9 %h<a> := 1;
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
10 ok(1,"# hash assignment with numeric value works");
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
11
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
12 ok(%h<a> + 1 == 2, 'hash access to numeric value');
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
13
14 %h<a> := 'ok 3';
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
15 ok(%h<a> eq 'ok 3', 'hash access to string value');
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
16
17 %h{1} := '4';
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
18 ok(%h{1} == 4, 'numeric hash access');
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
19
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
20 ok(%h<1> + 1 eq "5", 'numbers stringify');
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
21
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
22 %h{'b'} := 'ok 6';
23 ok(%h{'b'} eq 'ok 6',"curly braces and single quotes work");
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
24
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
25 %h{"foo"} := "ok 7";
26 ok(%h{"foo"} eq "ok 7","curly braces and double quotes work");
b8a2ea3 @pmichaud [nqp]: Add postcircumfix:<{ }> and postcircumfix:«< >».
pmichaud authored
27
f68cb4f @pmurias convert test to using ok instead of say, add a test for a nqp-js bug
pmurias authored
28 %h<a> := 0;
29 ok(%h<a> eq '0',"we can fetch false values");
5d3cfd5 @pmurias Add testing for access of missing keys to test 18.
pmurias authored
30
31 ok(%h<c> eq '',"a missing key behaves properly when used as string");
32 ok(%h<c> == 0,"a missing key behaves properly when used as number");
9c680b3 @pmurias Add a test for nqp::hash(...) to 18-associative.t.
pmurias authored
33
34 my $h := nqp::hash('foo', 123,'bar','hello');
35 ok($h<foo> == 123, 'hash access on a hash created with nqp::hash');
36 ok($h<bar> eq 'hello', 'hash access on a hash created with nqp::hash');
d579e94 @pmurias Test boolification of hashes.
pmurias authored
37
7914bf6 @pmurias Test calling nqp::elems on hashes.
pmurias authored
38 ok(nqp::elems($h) == 2, 'nqp::elems on a hash');
39
d579e94 @pmurias Test boolification of hashes.
pmurias authored
40 ok(nqp::istrue(nqp::hash('foo', 1, 'bar', 2)) == 1, 'a hash with 2 elements is true');
41 ok(nqp::istrue(nqp::hash()) == 0, 'a hash with 0 elements is false');
Something went wrong with that request. Please try again.