]> Sergey Matveev's repositories - public-inbox.git/blob - t/hval.t
msgmap: add tmp_clone to create an anonymous copy
[public-inbox.git] / t / hval.t
1 # Copyright (C) 2017-2018 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use_ok 'PublicInbox::Hval';
7
8 my $ibx = {
9         -no_obfuscate_re => qr/(?:example\.com)\z/i,
10         -no_obfuscate => {
11                 'meta@public-inbox.org' => 1,
12         }
13 };
14
15 my $html = <<'EOF';
16 hello@example.comm
17 hello@example.com
18 meta@public-inbox.org
19 test@public-inbox.org
20 test@a.b.c.org
21 te.st@example.org
22 EOF
23
24 PublicInbox::Hval::obfuscate_addrs($ibx, $html);
25
26 my $exp = <<'EOF';
27 hello@example&#8226;comm
28 hello@example.com
29 meta@public-inbox.org
30 test@public-inbox&#8226;org
31 test@a&#8226;b.c.org
32 te.st@example&#8226;org
33 EOF
34
35 is($html, $exp, 'only obfuscated relevant addresses');
36
37 is('foo-bar', PublicInbox::Hval::to_filename('foo bar  '),
38         'to_filename has no trailing -');
39
40 is('foo-bar', PublicInbox::Hval::to_filename("foo   bar\nanother line\n"),
41         'to_filename has no repeated -, and nothing past LF');
42
43 is('foo.bar', PublicInbox::Hval::to_filename("foo....bar"),
44         'to_filename squeezes -');
45
46
47 done_testing();