]> git.vpit.fr Git - perl/modules/Hash-Normalize.git/blob - t/12-renormalize.t
This is 0.01
[perl/modules/Hash-Normalize.git] / t / 12-renormalize.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
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, $cafe_nfc => 2);
14 normalize %h1;
15 is_deeply [ sort keys %h1 ], [ 'cafe', $cafe_nfc ], 'new hash';
16
17 my %h2 = %h1;
18 normalize %h2;
19 is_deeply [ sort keys %h2 ], [ 'cafe', $cafe_nfc ], 'idempotent renormalization';
20
21 my %h3 = %h1;
22 normalize %h3, 'D';
23 is_deeply [ sort keys %h3 ], [ 'cafe', $cafe_nfd ], 'true renormalization';
24
25 my %h4   = (cafe => 1, $cafe_nfc => 2, $cafe_nfd => 3);
26 my $keys = join ' ', sort keys %h4;
27 is scalar(keys %h4), 3, 'plain hash contains 3 keys';
28 eval { normalize %h4 };
29 like $@, qr/^Key collision after normalization /, 'normalizations collide';
30 is join(' ', sort keys %h4), $keys, 'collision happened but hash was untouched'