Changeset 12422


Ignore:
Timestamp:
09/02/10 00:01:45 (18 months ago)
Author:
azawawi
Message:

[S:H:P6] Perl tidy :)

Location:
trunk/Syntax-Highlight-Perl6
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Syntax-Highlight-Perl6/lib/Syntax/Highlight/Perl6.pm

    r12421 r12422  
    8787        $self->{parser} = STD->parse( 
    8888            $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}, 
    9292        ); 
    9393 
     
    430430            #now delegate printing to a callback 
    431431            #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}; 
    433433            $process_buffer->( $i, $buffer, $rule_to_color, $last_tree, $parser->lineof($i) ); 
    434434            $buffer = $c; 
  • trunk/Syntax-Highlight-Perl6/t/00-std.t

    r12415 r12422  
    1010 
    1111#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'); 
     12my $r = STD->parse( '', tmp_prefix => $tmp ); 
     13ok( defined $r, 'STD->parse() returned something on a empty string' ); 
     14isa_ok( $r, 'STD', 'STD->parse() return type' ); 
  • trunk/Syntax-Highlight-Perl6/t/01-syntax.t

    r12362 r12422  
    77 
    88#it can be used... 
    9 BEGIN {  
    10     use_ok('Syntax::Highlight::Perl6');  
     9BEGIN { 
     10    use_ok('Syntax::Highlight::Perl6'); 
    1111} 
    1212 
     
    1717#text option is a required option in new() 
    1818dies_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'); 
     19ok( defined Syntax::Highlight::Perl6->new( text => q{}, tmp_prefix => $tmp ), 'text option can be empty' ); 
    2020 
    2121#check if new(...) works 
    2222my $p = Syntax::Highlight::Perl6->new( 
    23     text        => 'my $foo;', 
    24     tmp_prefix => $tmp 
     23    text       => 'my $foo;', 
     24    tmp_prefix => $tmp 
    2525); 
    26 ok(defined $p, 'new() returned something'); 
    27 isa_ok( $p, 'Syntax::Highlight::Perl6', ' And it is the right class'); 
     26ok( defined $p, 'new() returned something' ); 
     27isa_ok( $p, 'Syntax::Highlight::Perl6', ' And it is the right class' ); 
    2828 
    2929#tests for snippet_html() 
    3030my $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'); 
     31ok( defined $snippet, 'snippet_html returned something' ); 
     32like( $snippet, '/<pre>/i', 'snippet_html contains <pre> tag' ); 
     33unlike( $snippet, '/<html>/i', 'snippet_html should not contain any <html>' ); 
     34like( $snippet, '/foo/i', 'snippet_html should contain the word foo' ); 
    3535 
    3636#tests for simple_html() 
    3737my $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'); 
     38ok( defined $simple, 'simple_html returned something' ); 
     39like( $simple, '/<pre>/i',  'simple_html should have <pre> tags' ); 
     40like( $simple, '/<html>/i', 'simple_html should contain <html>' ); 
     41unlike( $simple, '/text\/javascript/i', 'simple_html should not contain any JS' ); 
     42like( $simple, '/foo/i', 'simple_html should contain the word foo' ); 
    4343 
    4444#tests for full_html() 
    4545my $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'); 
     46ok( defined $full, 'full_html returned something' ); 
     47like( $full, '/<pre>/i',            'full_html should have <pre> tags' ); 
     48like( $full, '/<html>/i',           'full_html should contain <html>' ); 
     49like( $full, '/text\/javascript/i', 'full_html should contain JS' ); 
     50like( $full, '/foo/i',              'full_html should contain the word foo' ); 
    5151 
    5252#tests for ansi_text() 
    5353my $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'); 
     54ok( defined $ansi, 'ansi_text returned something' ); 
     55like( $ansi, '/\033\[.+?m/i', 'ansi_text should contain ansi color escape sequences' ); 
     56like( $ansi, '/foo/i',        'ansi_text should contain the word foo' ); 
    5757 
    5858#tests for tokens() 
    5959my @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'); 
     60ok( @tokens,      'tokens returned an array' ); 
     61ok( $#tokens > 0, 'and the tokens has some elements in it' ); 
     62isa_ok( $tokens[0], 'HASH', '$tokens[0] returned a hash' ); 
     63my %rec = %{ $tokens[0] }; 
     64ok( defined keys %rec,      '%rec has one or keys' ); 
     65ok( defined $rec{buffer},   '%rec has a buffer' ); 
     66ok( defined $rec{last_pos}, '%rec has a last_pos' ); 
     67ok( defined $rec{rule},     '%rec has a rule' ); 
     68ok( defined $rec{tree},     '%rec has a tree' ); 
     69ok( defined $rec{lineno},   '%rec has a lineno' ); 
    7070 
    7171#tests for static behavior between different instances 
    7272my $q = Syntax::Highlight::Perl6->new( 
    73     text        => q{my $bar = "&<>";}, 
    74     tmp_prefix => $tmp 
     73    text       => q{my $bar = "&<>";}, 
     74    tmp_prefix => $tmp 
    7575); 
    76 like( $q->snippet_html, '/bar/i', 'second instance worked perfectly'); 
    77 like( $p->snippet_html, '/foo/i', 'and first instance is not affected'); 
     76like( $q->snippet_html, '/bar/i', 'second instance worked perfectly' ); 
     77like( $p->snippet_html, '/foo/i', 'and first instance is not affected' ); 
    7878 
    7979#tests for correct _escape_html behavior 
    80 like( $q->snippet_html, '/&lt;&gt;/',  
    81     'snippet_html & html escaping works'); 
    82 like( $q->snippet_html, '/&amp;/',  
    83     'snippet_html & html escaping works'); 
    84 like( $q->simple_html, '/&quot;/',  
    85     'simple_html html escaping works'); 
    86 like( $q->full_html, '/&lt;&gt;/', 
    87     'full_html html escaping works'); 
     80like( 
     81    $q->snippet_html, '/&lt;&gt;/', 
     82    'snippet_html & html escaping works' 
     83); 
     84like( 
     85    $q->snippet_html, '/&amp;/', 
     86    'snippet_html & html escaping works' 
     87); 
     88like( 
     89    $q->simple_html, '/&quot;/', 
     90    'simple_html html escaping works' 
     91); 
     92like( 
     93    $q->full_html, '/&lt;&gt;/', 
     94    'full_html html escaping works' 
     95); 
  • trunk/Syntax-Highlight-Perl6/t/02-hilitep6.t

    r6171 r12422  
    99 
    1010#Skip tests on win32 platforms 
    11 if($OSNAME eq 'MSWin32') { 
    12     plan skip_all => 'IPC::Open2 does not like windows'; 
     11if ( $OSNAME eq 'MSWin32' ) { 
     12    plan skip_all => 'IPC::Open2 does not like windows'; 
    1313} else { 
    14     plan tests => 30; 
     14    plan tests => 30; 
    1515} 
    1616 
    17 my $hilitep6 = File::Spec->catfile( qw(blib script hilitep6) ); 
    18 if (not -e $hilitep6) { 
    19     $hilitep6 = File::Spec->catfile( qw(script hilitep6) ) 
     17my $hilitep6 = File::Spec->catfile(qw(blib script hilitep6)); 
     18if ( not -e $hilitep6 ) { 
     19    $hilitep6 = File::Spec->catfile(qw(script hilitep6)); 
    2020} 
    2121 
    2222sub 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 mode 
    29     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; 
    3232} 
    3333 
    3434#tests for --help 
    3535my $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'); 
     36ok( defined $help, '--help returned something' ); 
     37like( $help, '/USAGE/',          '--help contains USAGE' ); 
     38like( $help, '/--simple-html/',  '--help contains --simple-html' ); 
     39like( $help, '/--full-html/',    '--help contains --full-html' ); 
     40like( $help, '/--snippet-html/', '--help contains --snippet-html' ); 
     41like( $help, '/--ansi-text/',    '--help contains --ansi-text' ); 
    4242 
    4343#no arguments should default to --ansi-text=- 
    4444my $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'); 
     45ok( defined $default, 'no arguments returned something' ); 
     46like( 
     47    $default, '/\033\[.+?m/i', 
     48    'no arguments should contain ansi color escape sequences' 
     49); 
     50like( $default, '/foo/i', 'no arguments should contain the word foo' ); 
    4951 
    5052#tests for --snippet-html 
    5153my $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'); 
     54ok( defined $snippet, '--snippet-html=- returned something' ); 
     55like( $snippet, '/<pre>/i', '--snippet-html=- contains <pre> tag' ); 
     56unlike( $snippet, '/<html>/i', '--snippet-html=- should not contain any <html>' ); 
     57like( $snippet, '/foo/i', '--snippet-html=- should contain the word foo' ); 
    5658 
    5759#tests for --simple-html 
    5860my $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'); 
     61ok( defined $simple, '--simple-html=- returned something' ); 
     62like( $simple, '/<pre>/i',  '--simple-html=- should have <pre> tags' ); 
     63like( $simple, '/<html>/i', '--simple-html=- should contain <html>' ); 
     64unlike( $simple, '/text\/javascript/i', '--simple-html=- should not contain any JS' ); 
     65like( $simple, '/foo/i', '--simple-html=- should contain the word foo' ); 
    6466 
    6567#tests for ----full-html=- 
    6668my $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'); 
     69ok( defined $full, '--full-html=- returned something' ); 
     70like( $full, '/<pre>/i',            '--full-html=- should have <pre> tags' ); 
     71like( $full, '/<html>/i',           '--full-html=- should contain <html>' ); 
     72like( $full, '/text\/javascript/i', '--full-html=- should contain JS' ); 
     73like( $full, '/foo/i',              '--full-html=- should contain the word foo' ); 
    7274 
    7375#tests for --ansi-text 
    7476my $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'); 
     77ok( defined $ansi, '--ansi-text=- returned something' ); 
     78like( 
     79    $ansi, '/\033\[.+?m/i', 
     80    '--ansi-text=- should contain ansi color escape sequences' 
     81); 
     82like( $ansi, '/foo/i', '--ansi-text=- should contain the word foo' ); 
    7983 
    8084#tests for correct html escaping behavior 
    81 like( $snippet, '/&lt;&gt;/',  
    82     '--snippet-html=- & html escaping works'); 
    83 like( $snippet, '/&amp;/',  
    84     '--snippet-html=- & html escaping works'); 
    85 like( $simple, '/&quot;/',  
    86     '--simple-html=- html escaping works'); 
    87 like( $full, '/&lt;&gt;/', 
    88     '--full-html=- html escaping works'); 
     85like( 
     86    $snippet, '/&lt;&gt;/', 
     87    '--snippet-html=- & html escaping works' 
     88); 
     89like( 
     90    $snippet, '/&amp;/', 
     91    '--snippet-html=- & html escaping works' 
     92); 
     93like( 
     94    $simple, '/&quot;/', 
     95    '--simple-html=- html escaping works' 
     96); 
     97like( 
     98    $full, '/&lt;&gt;/', 
     99    '--full-html=- html escaping works' 
     100); 
     101 
    89102=cut 
Note: See TracChangeset for help on using the changeset viewer.