File: Kate.t

package info (click to toggle)
libsyntax-highlight-engine-kate-perl 0.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 3,848 kB
  • sloc: perl: 84,065; ruby: 176; asm: 166; cpp: 144; jsp: 128; haskell: 116; sh: 111; f90: 99; python: 98; ml: 75; xml: 43; yacc: 37; ansic: 32; tcl: 29; lisp: 24; makefile: 14; awk: 13; php: 5
file content (106 lines) | stat: -rwxr-xr-x 3,028 bytes parent folder | download | duplicates (4)
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
use strict;

use Term::ANSIColor;

use Test::More;

my %reg = ();
open RG, "<REGISTERED" or  die "cannot open REGISTERED";
while (my $t = <RG>) {
	chomp($t);
	my ($lang, $testfile) = split /\t/, $t;
	unless (defined($testfile)) { $testfile = "" }
	#diag "#language $lang, samplefile, ;$testfile; quovadis";
	$reg{$lang} = $testfile;
}
close RG;

my %filetypes = (
	'../some/path/index.html' => 'HTML',
	'Module.pm' => 'Perl',
	'c:\\Documents and Settings\\My Documents\\settings.xml' => 'XML',
);

my %options = (
	substitutions => {
		"\n" => color('reset') . "\n",
	},
	format_table => {
		Alert => [color('white bold on_green'), color('reset')],
		BaseN => [color('green'), color('reset')],
		BString => [color('red bold'), color('reset')],
		Char => [color('magenta'), color('reset')],
		Comment => [color('white bold on_blue'), color('reset')],
		DataType => [color('blue'), color('reset')],
		DecVal => [color('blue bold'), color('reset')],
		Error => [color('yellow bold on_red'), color('reset')],
		Float => [color('blue bold'), color('reset')],
		Function => [color('yellow bold on_blue'), color('reset')],
		IString => [color('red'), color('reset')],
		Keyword => [color('bold'), color('reset')],
		Normal => [color('reset'), color('reset')],
		Operator => [color('green'), color('reset')],
		Others => [color('yellow bold on_green'), color('reset')],
		RegionMarker => [color('black on_yellow bold'), color('reset')],
		Reserved => [color('magenta on_blue'), color('reset')],
		String => [color('red'), color('reset')],
		Variable => [color('blue on_red bold'), color('reset')],
		Warning => [color('green bold on_red'), color('reset')],
	},
);

my @langl = sort keys %reg;
my @ftl = sort keys %filetypes;
my $numtest = (@langl * 4) + 2 + (@ftl * 2);

plan tests => $numtest;
use Syntax::Highlight::Engine::Kate;
ok(1, "cannot find Kate");

my $k = new Syntax::Highlight::Engine::Kate(%options);
ok(defined($k), "cannot create Kate");

for (@ftl) {
	my $t = $_;
	my $l = $k->languagePropose($t);
	is($l, $filetypes{$t}, "Cannot select correct filetype for $t");
	$k->languageAutoSet($t);
	is($k->language, $filetypes{$t}, "Cannot select correct filetype for $t");
}

for (@langl) {
	my $ln = $_;
	#diag "testing $ln";
	my $md = $k->syntaxes->{$ln};
	my $mod = "Syntax::Highlight::Engine::Kate::$md";
	eval "use $mod";
	is($@, "", "cannot find $mod");
	my $m = new $mod(%options);
	ok(defined($m), "cannot create $mod");
	my $fl = $reg{$ln};
	if ($fl ne "") {
		my $txt = "";
		open(TST, "<$fl") or die "cannot open $fl";
		while (<TST>) { 
			$txt = $txt . $_; 
		};
		close TST;
		my $res = "";
		#diag "testing as kate plugin";
		$k->language($ln);
		$k->reset;
		eval "\$res = \$k->highlightText(\$txt)";
		is($@, "", "errors when highlighting");
#		diag $res;
		#diag "testing standalone";
		eval "\$res = \$m->highlightText(\$txt)";
		is($@, "", "errors when highlighting");
#		diag $res;
	} else {
		diag "Should be SKIP-ed! '$ln'";
		ok(1); ok(1);
		#skip(1, "no test file");
		#skip(1, "no test file");
	}
}