]> Sergey Matveev's repositories - public-inbox.git/blob - t/lei_external.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / lei_external.t
1 #!perl -w
2 # Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # internal unit test, see t/lei-externals.t for functional tests
5 use strict; use v5.10.1; use Test::More;
6 my $cls = 'PublicInbox::LeiExternal';
7 require_ok $cls;
8 my $canon = $cls->can('ext_canonicalize');
9 my $exp = 'https://example.com/my-inbox/';
10 is($canon->('https://example.com/my-inbox'), $exp, 'trailing slash added');
11 is($canon->('https://example.com/my-inbox//'), $exp, 'trailing slash removed');
12 is($canon->('https://example.com//my-inbox/'), $exp, 'leading slash removed');
13 is($canon->('https://EXAMPLE.com/my-inbox/'), $exp, 'lowercased');
14 is($canon->('/this/path/is/nonexistent/'), '/this/path/is/nonexistent',
15         'non-existent pathname canonicalized');
16 is($canon->('/this//path/'), '/this/path', 'extra slashes gone');
17 is($canon->('/ALL/CAPS'), '/ALL/CAPS', 'caps preserved');
18
19 my $glob2re = $cls->can('glob2re');
20 is($glob2re->('http://[::1]:1234/foo/'), undef, 'IPv6 URL not globbed');
21 is($glob2re->('foo'), undef, 'plain string unchanged');
22 is_deeply($glob2re->('[f-o]'), '[f-o]' , 'range accepted');
23 is_deeply($glob2re->('*'), '[^/]*?' , 'wildcard accepted');
24 is_deeply($glob2re->('{a,b,c}'), '(a|b|c)' , 'braces');
25 is_deeply($glob2re->('{,b,c}'), '(|b|c)' , 'brace with empty @ start');
26 is_deeply($glob2re->('{a,b,}'), '(a|b|)' , 'brace with empty @ end');
27 is_deeply($glob2re->('{a}'), undef, 'ungrouped brace');
28 is_deeply($glob2re->('{a'), undef, 'open left brace');
29 is_deeply($glob2re->('a}'), undef, 'open right brace');
30 is_deeply($glob2re->('*.[ch]'), '[^/]*?\\.[ch]', 'suffix glob');
31 is_deeply($glob2re->('{[a-z],9,}'), '([a-z]|9|)' , 'brace with range');
32 is_deeply($glob2re->('\\{a,b\\}'), undef, 'escaped brace');
33 is_deeply($glob2re->('\\\\{a,b}'), '\\\\\\\\(a|b)', 'fake escape brace');
34
35 done_testing;