File: formatter_googlesearch.t

package info (click to toggle)
libmojomojo-perl 1.11%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,496 kB
  • ctags: 927
  • sloc: perl: 14,671; sh: 148; xml: 120; makefile: 8; ruby: 6
file content (88 lines) | stat: -rwxr-xr-x 2,526 bytes parent folder | download | duplicates (3)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 9;
use lib 't/lib';
use FakeCatalystObject;

BEGIN {
    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
    use_ok 'MojoMojo::Formatter::GoogleSearch';
    use_ok 'Catalyst::Test', 'MojoMojo';
}

my $fake_c = FakeCatalystObject->new;
my $content;

#----- ASCII
{
    $content = 'see {{google MojoMojo}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=MojoMojo">MojoMojo</a>\n|,
        'ASCII web search',
    );
}

{
    $content = 'see {{google:web MojoMojo}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=MojoMojo">MojoMojo</a>\n|,
        'ASCII web search',
    );
}

{
    $content = 'see {{google:image MojoMojo}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/images?q=MojoMojo">MojoMojo</a>\n|,
        'ASCII image search',
    );
}

{
    $content = 'see {{google:movie MojoMojo}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=MojoMojo&tbs=vid%3A1">MojoMojo</a>\n|,
        'ASCII movie search',
    );
}

{
    $content = 'see {{google:movie Perl MojoMojo}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=Perl+MojoMojo&tbs=vid%3A1">Perl MojoMojo</a>\n|,
        'ASCII movie search (two keywords)',
    );
}

#----- Unicode
{
    $content = 'see {{google もじょもじょ}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=%E3%82%82%E3%81%98%E3%82%87%E3%82%82%E3%81%98%E3%82%87">もじょもじょ</a>\n|,
        'ASCII web search (Unicode keyword)',
    );
}

#----- few keywords
{
    $content = 'see {{google もじょ モジョ}}';
    MojoMojo::Formatter::GoogleSearch->format_content(\$content, $fake_c, undef);
    is(
        $content,
        qq|see <a href="http://www.google.com/search?q=%E3%82%82%E3%81%98%E3%82%87+%E3%83%A2%E3%82%B8%E3%83%A7">もじょ モジョ</a>\n|,
        'ASCII web search (Unicode two keywords)',
    );
}