File: saslprep_bytes.t

package info (click to toggle)
libunicode-stringprep-perl 1.104%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 284 kB
  • sloc: perl: 3,558; sh: 48; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,763 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use strict;
use bytes; # !!!

use Test::More;
use Test::NoWarnings;

use Unicode::Stringprep;

our @strprep = (

  # test vectors from RFC 4013, section 3.
  #

  [ "I\xADX",	      	'IX',		'SOFT HYPHEN mapped to nothing' ],
  [ 'user',          	'user',		'no transformation' ],
  [ 'USER',          	'USER',		'case preserved, will not match #2' ],
  [ "\xAA",     	'a',		'output is NFKC, input in ISO 8859-1' ],
  [ "\x07",     	undef,		'Error - prohibited character' ],

  # some more tests
  #

  [ '',		'',		'German umlaut case preserved' ],
  [ '',		'',		'German umlaut case preserved' ],
  [ "",		' ',		'no-break space mapped to ASCII space' ],
  [ "\xA0 ",		'   ',		'no space collapsing' ],

);

plan tests => ($#strprep+1) + 1;

my %C12_to_SPACE = ();
for(my $pos=0; $pos <= $#Unicode::Stringprep::Prohibited::C12; $pos+=2) 
{
  for(my $char = $Unicode::Stringprep::Prohibited::C12[$pos]; 
         defined $Unicode::Stringprep::Prohibited::C12[$pos]
	 && $char <= $Unicode::Stringprep::Prohibited::C12[$pos];
	 $char++) {
    $C12_to_SPACE{$char} = ' ';
  }
};

*saslprep = Unicode::Stringprep->new(
  3.2,
  [ \@Unicode::Stringprep::Mapping::B1,
    \%C12_to_SPACE ],
  'KC',
  [ \@Unicode::Stringprep::Prohibited::C12,
    \@Unicode::Stringprep::Prohibited::C21,
    \@Unicode::Stringprep::Prohibited::C22,
    \@Unicode::Stringprep::Prohibited::C3,
    \@Unicode::Stringprep::Prohibited::C4,
    \@Unicode::Stringprep::Prohibited::C5,
    \@Unicode::Stringprep::Prohibited::C6,
    \@Unicode::Stringprep::Prohibited::C7,
    \@Unicode::Stringprep::Prohibited::C8,
    \@Unicode::Stringprep::Prohibited::C9,
  ],
  1
);

foreach my $test (@strprep) 
{
  my ($in,$out,$comment) = @{$test};

  is(eval{saslprep($in)}, $out, $comment);
}