Initial commit
[tie-hash-sorted-xs.git] / t / Tie-Hash-Sorted-XS.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use Test::More tests => 5;
6 BEGIN { use_ok('Tie::Hash::Sorted::XS') };
7
8 tie my %hash, 'Tie::Hash::Sorted::XS';
9
10 $hash{Jim} = 5;
11 $hash{Bob} = 3;
12 $hash{Anna} = 7;
13
14 my $keys = join ' ', keys %hash;
15
16 is $keys, 'Anna Bob Jim', 'keys are ordered';
17 is $hash{Bob}, 3, 'retrieval works';
18
19
20 tie my %refhash, 'Tie::Hash::Sorted::XS', Tree::SizeBalanced::any_int->new(sub { $$a <=> $$b });
21 $refhash{\5} = 1;
22 my $three = 3;
23 $refhash{\$three} = 2;
24 my $tworef = \2;
25 $refhash{$tworef} = 3;
26
27 my $values = '';
28 for (keys %refhash) {
29 $values .= $refhash{$_} . ' ';
30 }
31 chop $values;
32
33 my @keys = keys %refhash;
34 is ref($keys[0]), 'SCALAR', 'non-string keys work';
35 is $values, '3 2 1', 'values of refhash'
This page took 0.024294 seconds and 4 git commands to generate.