Skip to content

Commit

Permalink
Only test official syntax groups (continued)
Browse files Browse the repository at this point in the history
This is a continuation of the work in 9012058.
  • Loading branch information
hinrik committed Mar 1, 2015
1 parent 8019ea1 commit 1dfdb0f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 190 deletions.
20 changes: 4 additions & 16 deletions t/01_highlighting.t
Expand Up @@ -7,17 +7,7 @@ use File::Find;
use File::Spec::Functions qw<catfile catdir>;
use Test::More;
use Test::Differences;
use Text::VimColor 0.24;

# hack to work around a silly limitation in Text::VimColor,
# will remove it when Text::VimColor has been patched
%Text::VimColor::SYNTAX_TYPE = map { $_ => 1 } qw(
Comment Constant Identifier Statement PreProc Type Special Underlined
Ignore Error Todo String Character Number Boolean Float Function
Conditional Repeat Label Operator Keyword Exception Include Define Macro
PreCondit StorageClass Structure Typedef Tag SpecialChar Delimiter
SpecialComment Debug
);
use Text::VimColor 0.25;

my %LANG_HIGHLIGHTERS = (
perl => [
Expand All @@ -40,23 +30,21 @@ my %LANG_HIGHLIGHTERS = (
sub construct_highlighter {
my ( $lang, $option_set ) = @_;

my $color_file = catfile('t', 'define_all.vim');
my $css_file = catfile('t', 'vim_syntax.css');

my $syntax_file = catfile('syntax', "$lang.vim");
my $ftplugin_file = catfile('ftplugin', "$lang.vim");
my $css_url = join('/', '..', '..', 't', 'vim_syntax.css');
my $css_file = catfile('t', 'vim_syntax.css');
my $css_url = join('/', '..', '..', 't', 'vim_syntax.css');

return Text::VimColor->new(
html_full_page => 1,
html_inline_stylesheet => 0,
html_stylesheet_url => $css_url,
all_syntax_groups => 1,
extra_vim_options => [
@$option_set,
'+set runtimepath=.',
"+source $ftplugin_file",
"+source $syntax_file",
"+source $color_file", # all syntax classes should be defined
"+syn sync fromstart",
],
);
Expand Down
26 changes: 6 additions & 20 deletions t/02_syntax_tt2.t
Expand Up @@ -5,32 +5,20 @@ use warnings;
use File::Spec::Functions qw<catfile catdir>;
use Test::More tests => 3; # can we upgrade to 0.88 and use done_testing?
use Test::Differences;
use Text::VimColor;

# hack to work around a silly limitation in Text::VimColor,
# will remove it when Text::VimColor has been patched
{
package TrueHash;
use base 'Tie::StdHash';
sub EXISTS { return 1 };
}
tie %Text::VimColor::SYNTAX_TYPE, 'TrueHash';
use Text::VimColor 0.25;

my $lang = 'tt2';
my $syntax_file = catfile('syntax', "$lang.vim");
my $color_file = catfile('t', 'define_all.vim');
my $syntax_file = catfile('syntax', "$lang.vim");

sub parse_string {
my ($string, $scripts) = @_;
my $syntax = Text::VimColor->new(
string => $string,
vim_options => [
qw(-RXZ -i NONE -u NONE -U NONE -N -n), # for performance
'+set nomodeline', # for performance
extra_vim_options => [
'+set runtimepath=.', # don't consider system runtime files
@{ $scripts || [] },
"+source $syntax_file",
"+source $color_file", # all syntax classes should be defined
'+syn sync fromstart',
],
);
return $syntax->marked;
Expand Down Expand Up @@ -72,12 +60,10 @@ TT2
[ Type => '[% ' ],
[ Statement => 'PERL' ],
[ Type => ' %]' ],
[ '' => "\n" ],
[ 'tt2_perlcode' => ' ' ],
[ '' => "\n " ],
[ Identifier => 'print(' ],
[ String => '"vim"' ],
[ 'tt2_perlcode' => ');' ],
[ '' => "\n" ],
[ '' => ");\n" ],
[ Type => '[% ' ],
[ Statement => 'END' ],
[ Type => ' %]' ],
Expand Down
155 changes: 66 additions & 89 deletions t/05_syntax_mason.t
Expand Up @@ -5,32 +5,20 @@ use warnings;
use File::Spec::Functions qw<catfile catdir>;
use Test::More tests => 6; # can we upgrade to 0.88 and use done_testing?
use Test::Differences;
use Text::VimColor;

# hack to work around a silly limitation in Text::VimColor,
# will remove it when Text::VimColor has been patched
{
package TrueHash;
use base 'Tie::StdHash';
sub EXISTS { return 1 };
}
tie %Text::VimColor::SYNTAX_TYPE, 'TrueHash';
use Text::VimColor 0.25;

my $lang = 'mason';
my $syntax_file = catfile('syntax', "$lang.vim");
my $color_file = catfile('t', 'define_all.vim');
my $syntax_file = catfile('syntax', "$lang.vim");

sub parse_string {
my ($string, $scripts) = @_;
my $syntax = Text::VimColor->new(
string => $string,
vim_options => [
qw(-RXZ -i NONE -u NONE -U NONE -N -n), # for performance
'+set nomodeline', # for performance
extra_vim_options => [
'+set runtimepath=.', # don't consider system runtime files
@{ $scripts || [] },
"+source $syntax_file",
"+source $color_file", # all syntax classes should be defined
'+syn sync fromstart',
],
);
return $syntax->marked;
Expand All @@ -43,14 +31,14 @@ eq_or_diff
MASON
[
[ Delimiter => '<%method title>' ],
[ masonMethod => 'Home' ],
[ '' => 'Home' ],
[ Delimiter => '</%method>' ],
[ '' => "\n<h1>" ],
[ Delimiter => '<%perl>' ],
[ Statement => "print" ],
[ masonPerl => ' ' ],
[ '' => ' ' ],
[ String => '"foobar"' ],
[ masonPerl => ';' ],
[ '' => ';' ],
[ Delimiter => "</%perl>" ],
[ '' => "</h1>\n" ],
],
Expand All @@ -77,10 +65,9 @@ MASON
[ Statement => '=cut' ],
[ '' => "\n" ],
[ Statement => 'print' ],
[ masonInit => ' ' ],
[ '' => ' ' ],
[ String => '"foo"' ],
[ masonInit => ';' ],
[ '' => "\n" ],
[ '' => ";\n" ],
[ Delimiter => '</%init>' ],
[ '' => "\n" ],
],
Expand All @@ -95,17 +82,15 @@ eq_or_diff
MASON
[
[ Delimiter => '%'],
[ masonLine => ' '],
[ '' => ' '],
[ Conditional => 'if'],
[ masonLine => ' ('],
[ '' => ' ('],
[ Identifier => '$boolean'],
[ masonLine => ') {'],
[ '' => "\n<li>hello</li>\n"],
[ '' => ") {\n<li>hello</li>\n"],
[ Delimiter => "%"],
[ masonLine => ' }'],
[ '' => "\n"],
[ '' => " }\n"],
[ Delimiter => "<& SELF:header"],
[ masonComp => ' '],
[ '' => ' '],
[ Delimiter => "&>"],
[ '' => "\n"],
],
Expand All @@ -121,20 +106,16 @@ asdf
MASON
[
[ Delimiter => '<&| foo'],
[ masonComp => ', '],
[ '' => ', '],
[ String => 'bar'],
[ masonComp => ' => '],
[ '' => ' => '],
[ Identifier => '$baz'],
[ masonComp => ' '],
[ '' => ' '],
[ Delimiter => '&>'],
[ '' => "\n"],
[ masonCompContent => "asdf"],
[ '' => "\n"],
[ '' => "\nasdf\n"],
[ Delimiter => "%"],
[ Comment => '# foo'],
[ '' => "\n"],
[ masonCompContent => "<hlagh>"],
[ '' => "\n"],
[ '' => "\n<hlagh>\n"],
[ Delimiter => "</&>"],
[ '' => "\n"],
],
Expand All @@ -147,33 +128,32 @@ eq_or_diff
% map { $_ => 'y' } qw(qa sa );
MASON
[
['Delimiter','%'],
['masonLine',' '],
['Repeat','for'],
['masonLine',' '],
['Statement','my'],
['masonLine',' '],
['Identifier','$t'],
['masonLine',' ('],
['String','qw{foo bar}'],
['masonLine',') { '],
['Comment','# foo'],
['',"\n<div>\n"],
['Delimiter','%'],
['masonLine',' '],
['Statement','map'],
['masonLine',' '],
['Statement','{'],
['masonLine',' '],
['Identifier','$_'],
['masonLine',' => '],
['String','\'y\''],
['masonLine',' '],
['Statement','}'],
['masonLine',' '],
['String','qw(qa sa )'],
['masonLine',';'],
['',"\n"],
[Delimiter =>'%'],
['' => ' '],
[Repeat => 'for'],
['' =>' '],
[Statement => 'my'],
['' => ' '],
[Identifier => '$t'],
['' => ' ('],
[String => 'qw{foo bar}'],
['' => ') { '],
[Comment => '# foo'],
['' => "\n<div>\n"],
[Delimiter => '%'],
['' => ' '],
[Statement => 'map'],
['' => ' '],
[Statement => '{'],
['' => ' '],
[Identifier => '$_'],
['' => ' => '],
[String => '\'y\''],
['' => ' '],
[Statement => '}'],
['' => ' '],
[String => 'qw(qa sa )'],
['' => ";\n"],
],
'basic Template syntax';

Expand All @@ -191,30 +171,27 @@ dsfsdf+2
%>
MASON
[
['Delimiter','<%'],
['masonExpr',' '],
['Comment','# This is a single-line comment'],
['',"\n"],
['masonExpr','foo+'],
['Number',2],
['',"\n"],
['Delimiter','%>'],
['',"\ndsfsdf+2\n<html>\n"],
['Delimiter','<%'],
['masonExpr',' '],
['Comment','# foo '],
['Delimiter','%>'],
['',"\n"],
['Delimiter','<%'],
['',"\n"],
['masonExpr',' '],
['Comment','# This is a'],
['',"\n"],
['masonExpr',' '],
['Comment','# multi-line comment'],
['',"\n"],
['Delimiter','%>'],
['',"\n"],
[Delimiter => '<%'],
['' => ' '],
[Comment => '# This is a single-line comment'],
['' => "\nfoo+"],
[Number => 2],
['' => "\n"],
[Delimiter => '%>'],
['' => "\ndsfsdf+2\n<html>\n"],
[Delimiter => '<%'],
['' => ' '],
[Comment => '# foo '],
[Delimiter => '%>'],
['' => "\n"],
[Delimiter => '<%'],
['' => "\n "],
[Comment => '# This is a'],
['' => "\n "],
[Comment => '# multi-line comment'],
['' => "\n"],
[Delimiter => '%>'],
['' => "\n"],
],
'basic Template syntax';

Expand Down
53 changes: 0 additions & 53 deletions t/define_all.vim

This file was deleted.

0 comments on commit 1dfdb0f

Please sign in to comment.