File: uri.t

package info (click to toggle)
libjson-validator-perl 5.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,160 kB
  • sloc: perl: 3,015; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 2,195 bytes parent folder | download | duplicates (2)
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
use Mojo::Base -strict;
use Test::More;
use JSON::Validator::URI;

subtest 'url https' => sub {
  my $url = JSON::Validator::URI->new('https://foo.com');
  is $url->scheme, 'https',   'scheme';
  is $url->host,   'foo.com', 'host';
  is $url->nid,    undef,     'nid';
  is $url->nss,    undef,     'nss';
};

subtest 'urn uuid' => sub {
  my $urn = JSON::Validator::URI->new('urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f');
  is $urn->host,     undef,                                  'host';
  is $urn->scheme,   'urn',                                  'scheme';
  is $urn->nid,      'uuid',                                 'nid';
  is $urn->nss,      'ee564b8a-7a87-4125-8c96-e9f123d6766f', 'nss';
  is $urn->fragment, undef,                                  'fragment';
};

subtest 'urn jv' => sub {
  my $urn = JSON::Validator::URI->new('urn:jv:draft4-4242#foo');
  ok $urn->is_abs,   'is_abs';
  is $urn->host,     undef,         'host';
  is $urn->scheme,   'urn',         'scheme';
  is $urn->nid,      'jv',          'nid';
  is $urn->nss,      'draft4-4242', 'nss';
  is $urn->fragment, 'foo',         'fragment';

  my $clone = $urn->clone;
  is $clone->host,      undef,                    'clone host';
  is $clone->scheme,    'urn',                    'clone scheme';
  is $clone->nid,       'jv',                     'clone nid';
  is $clone->nss,       'draft4-4242',            'clone nss';
  is $clone->fragment,  'foo',                    'clone fragment';
  is $clone->to_string, 'urn:jv:draft4-4242#foo', 'clone to_string';
};

subtest 'urn to_abs' => sub {
  my $urn = JSON::Validator::URI->new('urn:jv:draft4-4242#foo');

  my $abs = $urn->to_abs(JSON::Validator::URI->new('urn:jv:draft4-4242#bar'));
  is $abs->to_string, $urn->to_string, 'is_abs';

  $urn = JSON::Validator::URI->new('#foo');
  $abs = $urn->to_abs(JSON::Validator::URI->new('urn:jv:draft4-4242#bar'));
  is $abs->to_string, 'urn:jv:draft4-4242#foo', 'to_abs';

  # TODO: I don't think it's valid for a URN to have a path, so this might get reverted
  my $rel = JSON::Validator::URI->new('b.json');
  is $rel->to_abs($abs)->to_string, 'urn:jv:draft4-4242/b.json#foo', 'b.json to_abs';
};

done_testing;