File: 01-basic.t

package info (click to toggle)
liburi-encode-perl 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 128 kB
  • sloc: perl: 204; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,238 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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!perl

####################
# LOAD CORE MODULES
####################
use strict;
use warnings FATAL => 'all';
use Encode qw();
use Test::More;

BEGIN { use_ok( "URI::Encode", qw(uri_encode uri_decode) ); }

# Define URI's
my $url
  = "http://mithun.aÿachit.com/my pages.html?name=m!thun&Yours=w%hat?#";
my $encoded
  = "http://mithun.a%C3%83%C2%BFachit.com/my%20pages.html?name=m!thun&Yours=w%25hat?#";
my $encoded_reserved
  = "http%3A%2F%2Fmithun.a%C3%83%C2%BFachit.com%2Fmy%20pages.html%3Fname%3Dm%21thun%26Yours%3Dw%25hat%3F%23";

# Test Init
my $uri = new_ok("URI::Encode");
can_ok( $uri, qw(encode decode) );

# Test OOP
is( $uri->encode($url), $encoded, 'OOP: Unreserved encoding' );
is(
    $uri->encode(
        $url, {
            encode_reserved => 1,
        }
    ),
    $encoded_reserved,
    'OOP: Reserved Encoding with HASH options'
);
is( $uri->encode( $url, 1 ),
    $encoded_reserved, 'OOP: Reserved Encoding with scalar option' );
is(
    $uri->encode(
        $encoded_reserved, {
            double_encode => 0,
        }
    ),
    $encoded_reserved,
    'OOP: Double encoding OFF'
);
is(
    $uri->encode(
        'This is a %20 test', {
            double_encode => 1,
        }
    ),
    'This%20is%20a%20%2520%20test',
    'OOP: Double encoding ON'
);
is( Encode::decode( 'utf-8-strict', $uri->decode($encoded) ),
    $url, 'OOP: Decoding' );

## Test Methods
can_ok( "URI::Encode", qw(uri_encode uri_decode) );
is( uri_encode($url), $encoded, 'Function: Unreserved encoding' );
is( uri_encode( $url, 1 ),
    $encoded_reserved, 'Function: Reserved encoding with scalar option' );
is(
    uri_encode(
        $url, {
            encode_reserved => 1,
        }
    ),
    $encoded_reserved,
    'Function: Reserved encoding with named option'
);
is(
    uri_encode(
        $encoded_reserved, {
            double_encode => 0,
        }
    ),
    $encoded_reserved,
    'Function: Double encoding OFF'
);
is( Encode::decode( 'utf-8-strict', uri_decode($encoded) ),
    $url, 'Function: Decoding' );

## Test Lowercase & Uppercase decode
is( $uri->decode('foo%2bbar'), 'foo+bar', 'Lower cased decoding' );
is( $uri->decode('foo%2Bbar'), 'foo+bar', 'Upper cased decoding' );

## Done
done_testing();
exit 0;