File: 04-idn.t

package info (click to toggle)
liburi-escape-xs-perl 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 144 kB
  • ctags: 3
  • sloc: perl: 239; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (3)
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
#!perl -w
#
# $Id: 04-idn.t,v 1.4 2012/08/06 01:44:20 dankogai Exp $
#
# Original as URI-1.35/t/escape.t
#

use URI::Escape::XS;
use Test::More tests => 8;

SKIP: {
    use utf8;
    eval      { require Net::LibIDN }
      or eval { require Net::IDN::Encode }
      or skip 'Net::LibIDN or Net::IDN::Encode required', 8;

    my $d = 'http://cnn.com/news';
    my $e = 'http:%2F%2Fcnn.com%2Fnews';
    is encodeURIComponentIDN($d) => $e, 'first encodeURIComponentIDN must preserve the path';

    $d = 'http://cnn.com/news';
    $e = 'http:%2F%2Fcnn.com%2Fnews';
    is encodeURIComponentIDN($d) => $e, 'second encodeURIComponentIDN must preserve the path as well';

    $d = 'http://ドメイン名例.jp/dankogai/だん/ダン';
    $e = 'http:%2F%2Fxn--eckwd4c7cu47r2wf.jp%2Fdankogai%2F%E3%81%A0%E3%82%93%2F%E3%83%80%E3%83%B3';
    is decodeURIComponentIDN($e) => $d, 'decodeURIComponentIDN';
    is encodeURIComponentIDN($d) => $e, 'encodeURIComponentIDN';
    $d = 'http://ドメイン名例.jp:8080/dankogai/だん/ダン';
    $e = 'http:%2F%2Fxn--eckwd4c7cu47r2wf.jp:8080%2Fdankogai%2F%E3%81%A0%E3%82%93%2F%E3%83%80%E3%83%B3';
    is decodeURIComponentIDN($e) => $d, 'decodeURIComponentIDN';
    is encodeURIComponentIDN($d) => $e, 'encodeURIComponentIDN';
    $d = 'http://مثال.إختبار';
    $e = 'http:%2F%2Fxn--mgbh0fb.xn--kgbechtv';
    is decodeURIComponentIDN($e) => $d, 'decodeURIComponentIDN';
    is encodeURIComponentIDN($d) => $e, 'encodeURIComponentIDN';
}