/
cleaner-markdown.t
53 lines (43 loc) · 1.54 KB
/
cleaner-markdown.t
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
# t/cleaner-markdown.t
#
# Test LJ::CleanHTML with Markdown text.
#
# Authors:
# Jen Griffin <kareila@livejournal.com>
#
# Copyright (c) 2017 by Dreamwidth Studios, LLC.
#
# This program is free software; you may redistribute it and/or modify it under
# the same terms as Perl itself. For a copy of the license, please reference
# 'perldoc perlartistic' or 'perldoc perlgpl'.
#
use strict;
use warnings;
use Test::More tests => 4;
BEGIN { $LJ::_T_CONFIG = 1; require "$ENV{LJHOME}/cgi-bin/ljlib.pl"; }
use LJ::CleanHTML;
my $lju_sys = LJ::ljuser("system");
my $url = 'https://medium.com/@username/title-of-page';
my $as_markdown = sub { return "!markdown\n$_[0]" };
my $clean = sub {
my ( $text ) = @_;
$text = $as_markdown->( $text );
LJ::CleanHTML::clean_event( \$text, { wordlength => 80 } );
chomp $text;
return $text;
};
# plain text user tag
is( $clean->('@system'), "<p>$lju_sys</p>",
"user tag in plain text converted" );
# plain URL containing user tag
# (Markdown conversion sets preformatted flag, so this won't linkify)
is( $clean->($url), "<p>$url</p>",
"user tag in URL not converted" );
# linked URL containing user tag
is( $clean->("[link from \@system]($url)"),
qq{<p><a href="$url">link from $lju_sys</a></p>},
"user tag in href not converted, but user tag in link text converted []" );
# same as standard HTML
is( $clean->(qq{<a href="$url">link from \@system</a>}),
qq{<p><a href="$url">link from $lju_sys</a></p>},
"user tag in href not converted, but user tag in link text converted <>" );