File: filehighlighter-1

package info (click to toggle)
libarch-perl 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 576 kB
  • ctags: 430
  • sloc: perl: 6,145; makefile: 31
file content (125 lines) | stat: -rwxr-xr-x 4,804 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
123
124
125
#!/usr/bin/perl -w

# The script tests Arch::FileHighlighter methods.

use FindBin;
use lib "$FindBin::Bin/../perllib";

my $c_file_content = <<ENDTEXT;
#include <stdio.h>
#include <string.h>

/* useful program */

int main() {
	memfrob((void *)main, 100);
	return 0;
}
/* end */
ENDTEXT

use Test::More tests => 41;
use_ok("Arch::FileHighlighter");

my ($fh, $html_ref, @html_lines);
my ($html_content, @ampersands, @tags);
my @real_lines = Arch::Util::load_file($0) =~ /(.*)\n/g;

sub comment ($) { qq(<span class="syntax_comment">$_[0]</span>) }

# ----------------------------------------------------------------------------

$fh = Arch::FileHighlighter->new([ 'internal', 'none', 'enscript' ]);
isa_ok($fh, 'Arch::FileHighlighter', "creating object 1");

$html_ref = $fh->highlight($0);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight script itself");
@html_lines = $$html_ref =~ /(.*)\n/g;
is(int @html_lines, int @real_lines, "number of markup lines");
is($html_lines[0], comment('#!/usr/bin/perl -w'), "markup of sh-bang line");
is($html_lines[1], '', "markup of empty line");
is($html_lines[2], comment('# The script tests Arch::FileHighlighter methods.'), "markup of comment line");

$html_ref = $fh->highlight("file.c", \$c_file_content);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight inline content");
$html_content = $$html_ref;
@ampersands = $html_content =~ /&/g;
is(int @ampersands, 4, "entities/quoting");
@html_lines = $html_content =~ /(.*)\n/g;
is(int @html_lines, 10, "number of lines");
@tags = $html_content =~ /</g;
is(int @tags, 4, "number of tags");

# ----------------------------------------------------------------------------

$fh = Arch::FileHighlighter->new([ 'internal(c+pm)', 'none', 'enscript' ]);
isa_ok($fh, 'Arch::FileHighlighter', "creating object 2");

$html_ref = $fh->highlight($0);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight script itself");
@html_lines = $$html_ref =~ /(.*)\n/g;
is(int @html_lines, int @real_lines, "number of markup lines");
is($html_lines[0], '#!/usr/bin/perl -w', "markup of sh-bang line");
is($html_lines[1], '', "markup of empty line");
is($html_lines[2], '# The script tests Arch::FileHighlighter methods.', "markup of comment line");

$html_ref = $fh->highlight("file.c", \$c_file_content);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight inline content");
$html_content = $$html_ref;
@ampersands = $html_content =~ /&/g;
is(int @ampersands, 4, "entities/quoting");
@html_lines = $html_content =~ /(.*)\n/g;
is(int @html_lines, 10, "number of lines");
@tags = $html_content =~ /</g;
is(int @tags, 4, "number of tags");

# ----------------------------------------------------------------------------

$fh = Arch::FileHighlighter->new([ 'none(c+pm)', 'internal', 'enscript' ]);
isa_ok($fh, 'Arch::FileHighlighter', "creating object 3");

$html_ref = $fh->highlight($0);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight script itself");
@html_lines = $$html_ref =~ /(.*)\n/g;
is(int @html_lines, int @real_lines, "number of markup lines");
is($html_lines[0], comment('#!/usr/bin/perl -w'), "markup of sh-bang line");
is($html_lines[1], '', "markup of empty line");
is($html_lines[2], comment('# The script tests Arch::FileHighlighter methods.'), "markup of comment line");

$html_ref = $fh->highlight("file.c", \$c_file_content);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight inline content");
$html_content = $$html_ref;
@ampersands = $html_content =~ /&/g;
is(int @ampersands, 4, "entities/quoting");
@html_lines = $html_content =~ /(.*)\n/g;
is(int @html_lines, 10, "number of lines");
@tags = $html_content =~ /</g;
is(int @tags, 0, "number of tags");

# ----------------------------------------------------------------------------

SKIP: {
skip("no /usr/bin/enscript", 10) unless -x "/usr/bin/enscript";

$fh = Arch::FileHighlighter->new([ 'enscript(asis)', 'internal', 'none(c+pm)' ]);
isa_ok($fh, 'Arch::FileHighlighter', "creating object 3");

$html_ref = $fh->highlight($0);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight script itself");
@html_lines = $$html_ref =~ /(.*)\n/g;
is(int @html_lines, int @real_lines, "number of markup lines");
is($html_lines[0], comment('#!/usr/bin/perl -w'), "markup of sh-bang line");
is($html_lines[1], '', "markup of empty line");
is($html_lines[2], comment('# The script tests Arch::FileHighlighter methods.'), "markup of comment line");

$html_ref = $fh->highlight("file.c", \$c_file_content);
ok($html_ref && ref($html_ref) eq 'SCALAR', "highlight inline content");
$html_content = $$html_ref;
@ampersands = $html_content =~ /&/g;
is(int @ampersands, 4, "entities/quoting");
@html_lines = $html_content =~ /(.*)\n/g;
is(int @html_lines, 10, "number of lines");
@tags = $html_content =~ /</g;
is(int @tags, 20, "number of tags");

}