Changeset 12422
- Timestamp:
- 09/02/10 00:01:45 (18 months ago)
- Location:
- trunk/Syntax-Highlight-Perl6
- Files:
-
- 4 edited
-
lib/Syntax/Highlight/Perl6.pm (modified) (2 diffs)
-
t/00-std.t (modified) (1 diff)
-
t/01-syntax.t (modified) (2 diffs)
-
t/02-hilitep6.t (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Syntax-Highlight-Perl6/lib/Syntax/Highlight/Perl6.pm
r12421 r12422 87 87 $self->{parser} = STD->parse( 88 88 $src_text, 89 rule => $self->{rule},90 actions => __PACKAGE__ . '::Actions',91 tmp_prefix => $self->{tmp_prefix},89 rule => $self->{rule}, 90 actions => __PACKAGE__ . '::Actions', 91 tmp_prefix => $self->{tmp_prefix}, 92 92 ); 93 93 … … 430 430 #now delegate printing to a callback 431 431 #HACK to prevent parser->lineof(position) from breaking. lineof should be called in the same dynamic scope of parsing 432 $::ORIG = $self->{src_text}; 432 $::ORIG = $self->{src_text}; 433 433 $process_buffer->( $i, $buffer, $rule_to_color, $last_tree, $parser->lineof($i) ); 434 434 $buffer = $c; -
trunk/Syntax-Highlight-Perl6/t/00-std.t
r12415 r12422 10 10 11 11 #check that we have get back a parser when we have an empty string 12 my $r = STD->parse( '', tmp_prefix => $tmp);13 ok( defined $r, 'STD->parse() returned something on a empty string');14 isa_ok( $r, 'STD', 'STD->parse() return type' );12 my $r = STD->parse( '', tmp_prefix => $tmp ); 13 ok( defined $r, 'STD->parse() returned something on a empty string' ); 14 isa_ok( $r, 'STD', 'STD->parse() return type' ); -
trunk/Syntax-Highlight-Perl6/t/01-syntax.t
r12362 r12422 7 7 8 8 #it can be used... 9 BEGIN { 10 use_ok('Syntax::Highlight::Perl6'); 9 BEGIN { 10 use_ok('Syntax::Highlight::Perl6'); 11 11 } 12 12 … … 17 17 #text option is a required option in new() 18 18 dies_ok { Syntax::Highlight::Perl6->new(); } 'text option is required in new()'; 19 ok( defined Syntax::Highlight::Perl6->new(text => q{}, tmp_prefix => $tmp), 'text option can be empty');19 ok( defined Syntax::Highlight::Perl6->new( text => q{}, tmp_prefix => $tmp ), 'text option can be empty' ); 20 20 21 21 #check if new(...) works 22 22 my $p = Syntax::Highlight::Perl6->new( 23 text=> 'my $foo;',24 tmp_prefix=> $tmp23 text => 'my $foo;', 24 tmp_prefix => $tmp 25 25 ); 26 ok( defined $p, 'new() returned something');27 isa_ok( $p, 'Syntax::Highlight::Perl6', ' And it is the right class' );26 ok( defined $p, 'new() returned something' ); 27 isa_ok( $p, 'Syntax::Highlight::Perl6', ' And it is the right class' ); 28 28 29 29 #tests for snippet_html() 30 30 my $snippet = $p->snippet_html; 31 ok( defined $snippet, 'snippet_html returned something' );32 like( $snippet, '/<pre>/i', 'snippet_html contains <pre> tag' );33 unlike( $snippet, '/<html>/i', 'snippet_html should not contain any <html>' );34 like( $snippet, '/foo/i', 'snippet_html should contain the word foo' );31 ok( defined $snippet, 'snippet_html returned something' ); 32 like( $snippet, '/<pre>/i', 'snippet_html contains <pre> tag' ); 33 unlike( $snippet, '/<html>/i', 'snippet_html should not contain any <html>' ); 34 like( $snippet, '/foo/i', 'snippet_html should contain the word foo' ); 35 35 36 36 #tests for simple_html() 37 37 my $simple = $p->simple_html; 38 ok( defined $simple, 'simple_html returned something' );39 like( $simple, '/<pre>/i', 'simple_html should have <pre> tags');40 like( $simple, '/<html>/i', 'simple_html should contain <html>' );41 unlike( $simple, '/text\/javascript/i', 'simple_html should not contain any JS' );42 like( $simple, '/foo/i', 'simple_html should contain the word foo' );38 ok( defined $simple, 'simple_html returned something' ); 39 like( $simple, '/<pre>/i', 'simple_html should have <pre> tags' ); 40 like( $simple, '/<html>/i', 'simple_html should contain <html>' ); 41 unlike( $simple, '/text\/javascript/i', 'simple_html should not contain any JS' ); 42 like( $simple, '/foo/i', 'simple_html should contain the word foo' ); 43 43 44 44 #tests for full_html() 45 45 my $full = $p->full_html; 46 ok( defined $full, 'full_html returned something' );47 like( $full, '/<pre>/i', 'full_html should have <pre> tags');48 like( $full, '/<html>/i', 'full_html should contain <html>');49 like( $full, '/text\/javascript/i', 'full_html should contain JS' );50 like( $full, '/foo/i', 'full_html should contain the word foo');46 ok( defined $full, 'full_html returned something' ); 47 like( $full, '/<pre>/i', 'full_html should have <pre> tags' ); 48 like( $full, '/<html>/i', 'full_html should contain <html>' ); 49 like( $full, '/text\/javascript/i', 'full_html should contain JS' ); 50 like( $full, '/foo/i', 'full_html should contain the word foo' ); 51 51 52 52 #tests for ansi_text() 53 53 my $ansi = $p->ansi_text; 54 ok( defined $ansi, 'ansi_text returned something' );55 like( $ansi, '/\033\[.+?m/i', 'ansi_text should contain ansi color escape sequences' );56 like( $ansi, '/foo/i', 'ansi_text should contain the word foo');54 ok( defined $ansi, 'ansi_text returned something' ); 55 like( $ansi, '/\033\[.+?m/i', 'ansi_text should contain ansi color escape sequences' ); 56 like( $ansi, '/foo/i', 'ansi_text should contain the word foo' ); 57 57 58 58 #tests for tokens() 59 59 my @tokens = $p->tokens; 60 ok( @tokens, 'tokens returned an array');61 ok( $#tokens > 0, 'and the tokens has some elements in it' );62 isa_ok( $tokens[0], 'HASH', '$tokens[0] returned a hash' );63 my %rec = %{ $tokens[0]};64 ok( defined keys %rec, '%rec has one or keys');65 ok( defined $rec{buffer}, '%rec has a buffer');66 ok( defined $rec{last_pos}, '%rec has a last_pos');67 ok( defined $rec{rule}, '%rec has a rule');68 ok( defined $rec{tree}, '%rec has a tree');69 ok( defined $rec{lineno}, '%rec has a lineno');60 ok( @tokens, 'tokens returned an array' ); 61 ok( $#tokens > 0, 'and the tokens has some elements in it' ); 62 isa_ok( $tokens[0], 'HASH', '$tokens[0] returned a hash' ); 63 my %rec = %{ $tokens[0] }; 64 ok( defined keys %rec, '%rec has one or keys' ); 65 ok( defined $rec{buffer}, '%rec has a buffer' ); 66 ok( defined $rec{last_pos}, '%rec has a last_pos' ); 67 ok( defined $rec{rule}, '%rec has a rule' ); 68 ok( defined $rec{tree}, '%rec has a tree' ); 69 ok( defined $rec{lineno}, '%rec has a lineno' ); 70 70 71 71 #tests for static behavior between different instances 72 72 my $q = Syntax::Highlight::Perl6->new( 73 text=> q{my $bar = "&<>";},74 tmp_prefix=> $tmp73 text => q{my $bar = "&<>";}, 74 tmp_prefix => $tmp 75 75 ); 76 like( $q->snippet_html, '/bar/i', 'second instance worked perfectly' );77 like( $p->snippet_html, '/foo/i', 'and first instance is not affected' );76 like( $q->snippet_html, '/bar/i', 'second instance worked perfectly' ); 77 like( $p->snippet_html, '/foo/i', 'and first instance is not affected' ); 78 78 79 79 #tests for correct _escape_html behavior 80 like( $q->snippet_html, '/<>/', 81 'snippet_html & html escaping works'); 82 like( $q->snippet_html, '/&/', 83 'snippet_html & html escaping works'); 84 like( $q->simple_html, '/"/', 85 'simple_html html escaping works'); 86 like( $q->full_html, '/<>/', 87 'full_html html escaping works'); 80 like( 81 $q->snippet_html, '/<>/', 82 'snippet_html & html escaping works' 83 ); 84 like( 85 $q->snippet_html, '/&/', 86 'snippet_html & html escaping works' 87 ); 88 like( 89 $q->simple_html, '/"/', 90 'simple_html html escaping works' 91 ); 92 like( 93 $q->full_html, '/<>/', 94 'full_html html escaping works' 95 ); -
trunk/Syntax-Highlight-Perl6/t/02-hilitep6.t
r6171 r12422 9 9 10 10 #Skip tests on win32 platforms 11 if ($OSNAME eq 'MSWin32') {12 plan skip_all => 'IPC::Open2 does not like windows';11 if ( $OSNAME eq 'MSWin32' ) { 12 plan skip_all => 'IPC::Open2 does not like windows'; 13 13 } else { 14 plan tests => 30;14 plan tests => 30; 15 15 } 16 16 17 my $hilitep6 = File::Spec->catfile( qw(blib script hilitep6));18 if ( not -e $hilitep6) {19 $hilitep6 = File::Spec->catfile( qw(script hilitep6) ) 17 my $hilitep6 = File::Spec->catfile(qw(blib script hilitep6)); 18 if ( not -e $hilitep6 ) { 19 $hilitep6 = File::Spec->catfile(qw(script hilitep6)); 20 20 } 21 21 22 22 sub run_script { 23 my $args = shift;24 my $Perl = $Config{perlpath};25 open2(*README, *WRITEME, "$Perl -Ilib $hilitep6 $args");26 print WRITEME q{my $foo="&<>";};27 close WRITEME;28 local $INPUT_RECORD_SEPARATOR = undef;#enable localized slurp mode29 my $output = <README>;30 close(README);31 return $output;23 my $args = shift; 24 my $Perl = $Config{perlpath}; 25 open2( *README, *WRITEME, "$Perl -Ilib $hilitep6 $args" ); 26 print WRITEME q{my $foo="&<>";}; 27 close WRITEME; 28 local $INPUT_RECORD_SEPARATOR = undef; #enable localized slurp mode 29 my $output = <README>; 30 close(README); 31 return $output; 32 32 } 33 33 34 34 #tests for --help 35 35 my $help = run_script '--help'; 36 ok( defined $help, '--help returned something');37 like( $help, '/USAGE/', '--help contains USAGE');38 like( $help, '/--simple-html/', '--help contains --simple-html');39 like( $help, '/--full-html/', '--help contains --full-html');40 like( $help, '/--snippet-html/', '--help contains --snippet-html' );41 like( $help, '/--ansi-text/', '--help contains --ansi-text');36 ok( defined $help, '--help returned something' ); 37 like( $help, '/USAGE/', '--help contains USAGE' ); 38 like( $help, '/--simple-html/', '--help contains --simple-html' ); 39 like( $help, '/--full-html/', '--help contains --full-html' ); 40 like( $help, '/--snippet-html/', '--help contains --snippet-html' ); 41 like( $help, '/--ansi-text/', '--help contains --ansi-text' ); 42 42 43 43 #no arguments should default to --ansi-text=- 44 44 my $default = run_script q{}; 45 ok( defined $default, 'no arguments returned something'); 46 like( $default, '/\033\[.+?m/i', 47 'no arguments should contain ansi color escape sequences'); 48 like( $default, '/foo/i', 'no arguments should contain the word foo'); 45 ok( defined $default, 'no arguments returned something' ); 46 like( 47 $default, '/\033\[.+?m/i', 48 'no arguments should contain ansi color escape sequences' 49 ); 50 like( $default, '/foo/i', 'no arguments should contain the word foo' ); 49 51 50 52 #tests for --snippet-html 51 53 my $snippet = run_script '--snippet-html=-'; 52 ok( defined $snippet, '--snippet-html=- returned something' );53 like( $snippet, '/<pre>/i', '--snippet-html=- contains <pre> tag' );54 unlike( $snippet, '/<html>/i', '--snippet-html=- should not contain any <html>' );55 like( $snippet, '/foo/i', '--snippet-html=- should contain the word foo' );54 ok( defined $snippet, '--snippet-html=- returned something' ); 55 like( $snippet, '/<pre>/i', '--snippet-html=- contains <pre> tag' ); 56 unlike( $snippet, '/<html>/i', '--snippet-html=- should not contain any <html>' ); 57 like( $snippet, '/foo/i', '--snippet-html=- should contain the word foo' ); 56 58 57 59 #tests for --simple-html 58 60 my $simple = run_script '--simple-html=-'; 59 ok( defined $simple, '--simple-html=- returned something' );60 like( $simple, '/<pre>/i', '--simple-html=- should have <pre> tags');61 like( $simple, '/<html>/i', '--simple-html=- should contain <html>' );62 unlike( $simple, '/text\/javascript/i', '--simple-html=- should not contain any JS' );63 like( $simple, '/foo/i', '--simple-html=- should contain the word foo' );61 ok( defined $simple, '--simple-html=- returned something' ); 62 like( $simple, '/<pre>/i', '--simple-html=- should have <pre> tags' ); 63 like( $simple, '/<html>/i', '--simple-html=- should contain <html>' ); 64 unlike( $simple, '/text\/javascript/i', '--simple-html=- should not contain any JS' ); 65 like( $simple, '/foo/i', '--simple-html=- should contain the word foo' ); 64 66 65 67 #tests for ----full-html=- 66 68 my $full = run_script '--full-html=-'; 67 ok( defined $full, '--full-html=- returned something' );68 like( $full, '/<pre>/i', '--full-html=- should have <pre> tags');69 like( $full, '/<html>/i', '--full-html=- should contain <html>');70 like( $full, '/text\/javascript/i', '--full-html=- should contain JS' );71 like( $full, '/foo/i', '--full-html=- should contain the word foo');69 ok( defined $full, '--full-html=- returned something' ); 70 like( $full, '/<pre>/i', '--full-html=- should have <pre> tags' ); 71 like( $full, '/<html>/i', '--full-html=- should contain <html>' ); 72 like( $full, '/text\/javascript/i', '--full-html=- should contain JS' ); 73 like( $full, '/foo/i', '--full-html=- should contain the word foo' ); 72 74 73 75 #tests for --ansi-text 74 76 my $ansi = run_script '--ansi-text=-'; 75 ok( defined $ansi, '--ansi-text=- returned something'); 76 like( $ansi, '/\033\[.+?m/i', 77 '--ansi-text=- should contain ansi color escape sequences'); 78 like( $ansi, '/foo/i', '--ansi-text=- should contain the word foo'); 77 ok( defined $ansi, '--ansi-text=- returned something' ); 78 like( 79 $ansi, '/\033\[.+?m/i', 80 '--ansi-text=- should contain ansi color escape sequences' 81 ); 82 like( $ansi, '/foo/i', '--ansi-text=- should contain the word foo' ); 79 83 80 84 #tests for correct html escaping behavior 81 like( $snippet, '/<>/', 82 '--snippet-html=- & html escaping works'); 83 like( $snippet, '/&/', 84 '--snippet-html=- & html escaping works'); 85 like( $simple, '/"/', 86 '--simple-html=- html escaping works'); 87 like( $full, '/<>/', 88 '--full-html=- html escaping works'); 85 like( 86 $snippet, '/<>/', 87 '--snippet-html=- & html escaping works' 88 ); 89 like( 90 $snippet, '/&/', 91 '--snippet-html=- & html escaping works' 92 ); 93 like( 94 $simple, '/"/', 95 '--simple-html=- html escaping works' 96 ); 97 like( 98 $full, '/<>/', 99 '--full-html=- html escaping works' 100 ); 101 89 102 =cut
Note: See TracChangeset
for help on using the changeset viewer.
