File: 02-view_code.t

package info (click to toggle)
libcgi-application-plugin-viewcode-perl 1.02-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 276 kB
  • sloc: perl: 1,783; makefile: 2
file content (122 lines) | stat: -rw-r--r-- 3,477 bytes parent folder | download | duplicates (5)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use Test::More;
use CGI;
use lib 't/lib';
use MyBase::MyApp;
use strict;

plan(tests => 23);

$ENV{'CGI_APP_RETURN_ONLY'} = 1;

# 1..4
# view_code
{
    my $cgi = CGI->new({
        rm => 'view_code',
    });
    my $app = MyBase::MyApp->new( QUERY => $cgi );
    my $output = $app->run();
    unlike($output, qr/String \{ color:#000000/);
    like($output, qr/<span class="String">/);
    like($output, qr/<span class="LineNumber"><a name="1">1/);
    like($output, qr/<span class="Comment_POD">/);
}

# 5..8
# view_code highlight=0
{
    my $cgi = CGI->new({
        rm          => 'view_code',
        highlight   => 0,
    }); 
    my $app = MyBase::MyApp->new( QUERY => $cgi );
    my $output = $app->run();
    like($output, qr/String \{ color:#000000/);
    like($output, qr/<span class="String">/);
    like($output, qr/<span class="LineNumber"><a name="1">1/);
    like($output, qr/<span class="Comment_POD">/);
}

# 9..12
# view_code hightlight=0, line_no=0
{
    my $cgi = CGI->new({
        rm          => 'view_code',
        highlight   => 0,
        line_no     => 0,
    }); 
    my $app = MyBase::MyApp->new( QUERY => $cgi );
    my $output = $app->run();
    like($output, qr/String \{ color:#000000/);
    like($output, qr/<span class="String">/);
    unlike($output, qr/<span class="LineNumber"><a name="1">1/);
    like($output, qr/<span class="Comment_POD">/);
}

# 13..16
# view_code hightlight=0, line_no=0, pod=0
{
    my $cgi = CGI->new({
        rm          => 'view_code',
        highlight   => 0,
        line_no     => 0,
        pod         => 0,
    });
    my $app = MyBase::MyApp->new( QUERY => $cgi );
    my $output = $app->run();
    like($output, qr/String \{ color:#000000/);
    like($output, qr/<span class="String">/);
    unlike($output, qr/<span class="LineNumber"><a name="1">1/);
    unlike($output, qr/<span class="Comment_POD">/);
}

# 17..23
# module and package links
{
    # using '::'
    my $cgi = CGI->new({
        rm      => 'view_code',
        module  => 'MyBase::MyApp',
    }); 
    my $app = MyBase::MyApp->new( QUERY => $cgi );
    my $output = $app->run();
    like($output, qr/<span class="Keyword">package<.+><a class="Package" href="[^"]+">MyBase::MyApp</);

    # using '-'
    $cgi = CGI->new({
        rm      => 'view_code',
        module  => 'MyBase-MyApp',
    }); 
    $app = MyBase::MyApp->new( QUERY => $cgi );
    $output = $app->run();
    like($output, qr/<span class="String">/);
    like($output, qr/<span class="Keyword">package<.+><a class="Package" href="[^"]+">MyBase::MyApp</);

    # following links
    my ($link) = $output =~ /<a href="\?([^"]+)>MyBase</;
    $cgi = CGI->new($link);
    $output = $app->run(QUERY => $cgi);
    like($output, qr/<span class="Keyword">package<.+><a class="Package" href="[^"]+">MyBase::MyApp</);


    # follow links with a different mode_param()
    $cgi = CGI->new({
        mode    => 'view_code',
        module  => 'MyBase-MyApp',
    });
    $app = MyBase::MyApp->new( QUERY => $cgi );
    $app->mode_param('mode');
    $output = $app->run();
    like($output, qr/<span class="String">/);
    like($output, qr/<span class="Keyword">package<.+><a class="Package" href="[^"]+">MyBase::MyApp</);

    # following links
    ($link) = $output =~ /<a href="\?([^"]+)>MyBase</;
    $cgi = CGI->new($link);
    $output = $app->run(QUERY => $cgi);
    like($output, qr/<span class="Keyword">package<.+><a class="Package" href="[^"]+">MyBase::MyApp</);
}