2 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict; use v5.10.1; use PublicInbox::TestCommon;
6 use_ok 'PublicInbox::URInntps';
7 my $uri = PublicInbox::URInntps->new('nntp://EXAMPLE.com/inbox.test');
8 isnt(ref($uri), 'PublicInbox::URInntps', 'URI fallback');
9 is($uri->scheme, 'nntp', 'NNTP fallback ->scheme');
11 $uri = PublicInbox::URInntps->new('nntps://EXAMPLE.com/inbox.test');
12 is($uri->host, 'EXAMPLE.com', 'host matches');
13 is($uri->canonical->host, 'example.com', 'host canonicalized');
14 is($uri->canonical->as_string, 'nntps://example.com/inbox.test',
16 is($uri->port, 563, 'nntps port');
17 is($uri->userinfo, undef, 'no userinfo');
18 is($uri->scheme, 'nntps', '->scheme works');
19 is($uri->group, 'inbox.test', '->group works');
21 $uri = PublicInbox::URInntps->new('nntps://foo@0/');
22 is("$uri", $uri->as_string, '"" overload works');
23 is($uri->host, '0', 'numeric host');
24 is($uri->userinfo, 'foo', 'user extracted');
26 $uri = PublicInbox::URInntps->new('nntps://ipv6@[::1]');
27 is($uri->host, '::1', 'IPv6 host');
28 is($uri->group, '', '->group is empty');
30 $uri = PublicInbox::URInntps->new('nntps://0:666/INBOX.test');
31 is($uri->port, 666, 'port read');
32 is($uri->group, 'INBOX.test', 'group read after port');
34 is(PublicInbox::URInntps->new('nntps://0:563/')->canonical->as_string,
35 'nntps://0/', 'default port stripped');
37 $uri = PublicInbox::URInntps->new('nntps://NSA:Hunter2@0/inbox');
38 is($uri->userinfo, 'NSA:Hunter2', 'userinfo accepted w/ pass');
40 $uri = PublicInbox::URInntps->new('nntps://NSA:Hunter2@0/inbox.test/9-10');
41 is_deeply([$uri->group], [ 'inbox.test', 9, 10 ], 'ranges work');