]> git.vpit.fr Git - perl/modules/Hash-Normalize.git/blob - t/11-base.t
This is 0.01
[perl/modules/Hash-Normalize.git] / t / 11-base.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => (1 + 2 * 3) * 3 + 4;
7
8 use Hash::Normalize qw<normalize>;
9
10 my $cafe_nfc = "caf\x{e9}";
11 my $cafe_nfd = "cafe\x{301}";
12
13 my %h1 = (cafe => 1);
14 normalize %h1;
15 is_deeply [ sort keys %h1 ], [ 'cafe' ], 'new hash';
16
17 for my $run (1, 2) {
18  my $r1 = $h1{'cafe'};
19  my $r2 = $h1{$cafe_nfc};
20  my $r3 = $h1{$cafe_nfd};
21
22  is $r1, 1,     "init run $run fetch 1";
23  is $r2, undef, "init run $run fetch 2";
24  is $r3, undef, "init run $run fetch 3";
25 }
26
27 $h1{$cafe_nfd} = 2;
28
29 is_deeply [ sort keys %h1 ], [ 'cafe', $cafe_nfc ], 'after store 1';
30
31 for my $run (1, 2) {
32  my $r1 = $h1{'cafe'};
33  my $r2 = $h1{$cafe_nfc};
34  my $r3 = $h1{$cafe_nfd};
35
36  is $r1, 1, "store 1 run $run fetch 1";
37  is $r2, 2, "store 1 run $run fetch 2";
38  is $r3, 2, "store 1 run $run fetch 3";
39 }
40
41 $h1{$cafe_nfc} = 3;
42
43 is_deeply [ sort keys %h1 ], [ 'cafe', $cafe_nfc ], 'after store 2';
44
45 for my $run (1, 2) {
46  my $r1 = $h1{'cafe'};
47  my $r2 = $h1{$cafe_nfc};
48  my $r3 = $h1{$cafe_nfd};
49
50  is $r1, 1, "store 2 run $run fetch 1";
51  is $r2, 3, "store 2 run $run fetch 2";
52  is $r3, 3, "store 2 run $run fetch 3";
53 }
54
55 my %h2;
56 normalize %h2, 'd';
57 %h2 = %h1;
58 is_deeply [ sort keys %h2 ], [ 'cafe', $cafe_nfd ], 'list assign';
59
60 is exists $h1{$cafe_nfd}, 1, 'exists';
61
62 my $val = delete $h1{$cafe_nfd};
63 is $val, 3, 'delete';
64 is_deeply [ sort keys %h1 ], [ 'cafe' ], 'after delete';