Ticket #1220: t.patch
| File t.patch, 14.6 KB (added by bowtie, 2 years ago) |
|---|
-
t/09-outline.t
9 9 use Test::More; 10 10 use Test::Differences; 11 11 use PPI; 12 use PPIx::EditorTools::Outline; 12 13 13 14 BEGIN { 14 15 if ( $PPI::VERSION =~ /_/ ) { … … 108 109 }, 109 110 ); 110 111 111 plan tests => @cases * 1; 112 ############## 113 # Moose outline testing follows 114 ############## 112 115 113 use PPIx::EditorTools::Outline; 116 push @cases, ( 117 { file => 't/outline/Mooclass.pm', 118 expected => [ 119 { 'modules' => [ 120 { 'name' => 'MooseX::Declare', 121 'line' => 1, 122 }, 123 ], 124 'methods' => [ 125 { 'name' => 'pub_sub', 126 'line' => 12, 127 }, 128 { 'name' => '_pri_sub', 129 'line' => 16, 130 }, 131 { 'name' => 'mm_before', 132 'line' => 20 133 }, 134 { 'name' => 'mm_after', 135 'line' => 24 136 }, 137 { 'name' => 'mm_around', 138 'line' => 28 139 }, 140 { 'name' => 'mm_override', 141 'line' => 32 142 }, 143 { 'name' => 'mm_augment', 144 'line' => 36 145 }, 146 ], 147 'line' => 3, 148 'name' => 'Mooclass', 149 'attributes' => [ 150 { 'name' => 'moo_att', 151 'line' => 5 152 }, 153 { 'name' => 'label', 154 'line' => 7 155 }, 156 { 'name' => 'progress', 157 'line' => 7 158 }, 159 { 'name' => 'butWarn', 160 'line' => 7 161 }, 162 { 'name' => 'butTime', 163 'line' => 7 164 }, 165 { 'name' => 'start_stop', 166 'line' => 7 167 }, 168 { 'name' => 'account', 169 'line' => 10 170 }, 171 ], 172 } 173 ], 174 }, 175 { file => 't/outline/Moorole.pm', 176 expected => [ 177 { 'modules' => [ 178 { 'name' => 'MooseX::Declare', 179 'line' => 1, 180 }, 181 ], 182 'line' => 3, 183 'name' => 'Moorole', 184 185 'attributes' => [ 186 { 'line' => 7, 187 'name' => 'balance' 188 }, 189 { 'line' => 13, 190 'name' => 'overdraft' 191 } 192 ], 193 'pragmata' => [ 194 { 'line' => 5, 195 'name' => 'version' 196 } 197 ] 198 } 199 ] 200 }, 201 { file => 't/outline/Moofirst.pm', 202 expected => [ 203 { 'attributes' => [ 204 { 'line' => 7, 205 'name' => 'balance' 206 }, 207 { 'line' => 13, 208 'name' => 'overdraft' 209 }, 210 { 'line' => 23, 211 'name' => 'name' 212 }, 213 { 'line' => 25, 214 'name' => 'account' 215 } 216 ], 217 'line' => 3, 218 'methods' => [ 219 { 'line' => 27, 220 'name' => '_build_overdraft' 221 } 222 ], 223 'modules' => [ 224 { 'line' => 1, 225 'name' => 'MooseX::Declare' 226 } 227 ], 228 'name' => 'Moofirst', 229 'pragmata' => [ 230 { 'line' => 5, 231 'name' => 'version' 232 } 233 ] 234 } 235 ] 236 }, 237 ); 238 239 plan tests => @cases * 1; 114 240 115 241 foreach my $c (@cases) { 116 242 my $code = $c->{code}; … … 121 247 } 122 248 my $outline = PPIx::EditorTools::Outline->new->find( code => $code ); 123 249 124 #diag explain $outline; 250 125 251 is_deeply $outline, $c->{expected} or diag explain $outline; 126 252 } 127 253 -
t/10-lexer.t
9 9 use Test::More; 10 10 use Test::Differences; 11 11 use PPI; 12 use Data::Dumper; 12 13 13 14 BEGIN { 14 15 if ( $PPI::VERSION =~ /_/ ) { … … 29 30 30 31 END_CODE 31 32 expected => [ 32 [ 'keyword', 33 1, 34 1, 35 3 36 ], 37 [ 'Whitespace', 38 1, 39 4, 40 1 41 ], 42 [ 'pragma', 43 1, 44 5, 45 6 46 ], 47 [ 'Structure', 48 1, 49 11, 50 1 51 ], 52 [ 'Whitespace', 53 1, 54 12, 55 1 56 ], 57 [ 'keyword', 58 1, 59 13, 60 3 61 ], 62 [ 'Whitespace', 63 1, 64 16, 65 1 66 ], 67 [ 'pragma', 68 1, 69 17, 70 8 71 ], 72 [ 'Structure', 73 1, 74 25, 75 1 76 ], 77 [ 'Whitespace', 78 1, 79 26, 80 1 81 ], 82 [ 'keyword', 83 2, 84 1, 85 3 86 ], 87 [ 'Whitespace', 88 2, 89 4, 90 1 91 ], 92 [ 'Word', 93 2, 94 5, 95 3 96 ], 97 [ 'Structure', 98 2, 99 8, 100 1 101 ], 102 [ 'Whitespace', 103 2, 104 9, 105 1 106 ], 107 [ 'Whitespace', 108 3, 109 1, 110 1 111 ], 112 [ 'keyword', 113 4, 114 1, 115 2 116 ], 117 [ 'Whitespace', 118 4, 119 3, 120 1 121 ], 122 [ 'Symbol', 123 4, 124 4, 125 7 126 ], 127 [ 'Whitespace', 128 4, 129 11, 130 1 131 ], 132 [ 'Operator', 133 4, 134 12, 135 1 136 ], 137 [ 'Whitespace', 138 4, 139 13, 140 1 141 ], 142 [ 'Number', 143 4, 144 14, 145 2 146 ], 147 [ 'Structure', 148 4, 149 16, 150 1 151 ], 152 [ 'Whitespace', 153 4, 154 17, 155 1 156 ], 157 [ 'Whitespace', 158 5, 159 1, 160 1 161 ], 162 [ 'keyword', 163 6, 164 1, 165 3 166 ], 167 [ 'Whitespace', 168 6, 169 4, 170 1 171 ], 172 [ 'Word', 173 6, 174 5, 175 4 176 ], 177 [ 'Whitespace', 178 6, 179 9, 180 1 181 ], 182 [ 'Structure', 183 6, 184 10, 185 1 186 ], 187 [ 'Whitespace', 188 6, 189 11, 190 1 191 ], 192 [ 'Structure', 193 7, 194 1, 195 1 196 ], 197 [ 'Whitespace', 198 7, 199 2, 200 1 201 ], 202 [ 'Whitespace', 203 8, 204 1, 205 1 206 ], 33 [ 'keyword', 1, 1, 3 ], 34 [ 'Whitespace', 1, 4, 1 ], 35 [ 'pragma', 1, 5, 6 ], 36 [ 'Structure', 1, 11, 1 ], 37 [ 'Whitespace', 1, 12, 1 ], 38 [ 'keyword', 1, 13, 3 ], 39 [ 'Whitespace', 1, 16, 1 ], 40 [ 'pragma', 1, 17, 8 ], 41 [ 'Structure', 1, 25, 1 ], 42 [ 'Whitespace', 1, 26, 1 ], 43 [ 'keyword', 2, 1, 3 ], 44 [ 'Whitespace', 2, 4, 1 ], 45 [ 'Word', 2, 5, 3 ], 46 [ 'Structure', 2, 8, 1 ], 47 [ 'Whitespace', 2, 9, 1 ], 48 [ 'Whitespace', 3, 1, 1 ], 49 [ 'keyword', 4, 1, 2 ], 50 [ 'Whitespace', 4, 3, 1 ], 51 [ 'Symbol', 4, 4, 7 ], 52 [ 'Whitespace', 4, 11, 1 ], 53 [ 'Operator', 4, 12, 1 ], 54 [ 'Whitespace', 4, 13, 1 ], 55 [ 'Number', 4, 14, 2 ], 56 [ 'Structure', 4, 16, 1 ], 57 [ 'Whitespace', 4, 17, 1 ], 58 [ 'Whitespace', 5, 1, 1 ], 59 [ 'keyword', 6, 1, 3 ], 60 [ 'Whitespace', 6, 4, 1 ], 61 [ 'Word', 6, 5, 4 ], 62 [ 'Whitespace', 6, 9, 1 ], 63 [ 'Structure', 6, 10, 1 ], 64 [ 'Whitespace', 6, 11, 1 ], 65 [ 'Structure', 7, 1, 1 ], 66 [ 'Whitespace', 7, 2, 1 ], 67 [ 'Whitespace', 8, 1, 1 ], 68 ], 69 }, 70 { code => <<'END_CODE', 71 sub return func method before after around override augment 72 END_CODE 73 expected => [ 74 [ 'keyword', 1, 1, 3 ], 75 [ 'Whitespace', 1, 4, 1 ], 76 [ 'keyword', 1, 5, 6 ], 77 [ 'Whitespace', 1, 11, 1 ], 78 [ 'Word', 1, 12, 4 ], 79 [ 'Whitespace', 1, 16, 1 ], 80 [ 'Word', 1, 17, 6 ], 81 [ 'Whitespace', 1, 23, 1 ], 82 [ 'Word', 1, 24, 6 ], 83 [ 'Whitespace', 1, 30, 1 ], 84 [ 'Word', 1, 31, 5 ], 85 [ 'Whitespace', 1, 36, 1 ], 86 [ 'Word', 1, 37, 6 ], 87 [ 'Whitespace', 1, 43, 1 ], 88 [ 'Word', 1, 44, 8 ], 89 [ 'Whitespace', 1, 52, 1 ], 90 [ 'Word', 1, 53, 7 ], 91 [ 'Whitespace', 1, 60, 1 ], 92 93 ], 94 }, 95 { code => <<'END_CODE', 96 undef shift defined bless 97 END_CODE 98 expected => [ 99 [ 'core', 1, 1, 5 ], 100 [ 'Whitespace', 1, 6, 1 ], 101 [ 'core', 1, 7, 5 ], 102 [ 'Whitespace', 1, 12, 1 ], 103 [ 'core', 1, 13, 7 ], 104 [ 'Whitespace', 1, 20, 1 ], 105 [ 'core', 1, 21, 5 ], 106 [ 'Whitespace', 1, 26, 1 ], 107 ], 108 }, 109 { code => <<'END_CODE', 110 new 111 END_CODE 112 expected => [ [ 'Word', 1, 1, 3 ], [ 'Whitespace', 1, 4, 1 ], ], 113 }, 114 { code => <<'END_CODE', 115 use no 116 END_CODE 117 expected => [ 118 [ 'keyword', 1, 1, 3 ], 119 [ 'Whitespace', 1, 4, 1 ], 120 [ 'keyword', 1, 5, 2 ], 121 [ 'Whitespace', 1, 7, 1 ], 122 ], 123 }, 124 { code => <<'END_CODE', 125 my local our 126 END_CODE 127 expected => [ 128 [ 'keyword', 1, 1, 2 ], 129 [ 'Whitespace', 1, 3, 1 ], 130 [ 'keyword', 1, 4, 5 ], 131 [ 'Whitespace', 1, 9, 1 ], 132 [ 'keyword', 1, 10, 3 ], 133 [ 'Whitespace', 1, 13, 1 ], 134 135 ], 136 }, 137 138 { code => <<'END_CODE', 139 if else elsif unless for foreach while my 140 END_CODE 141 expected => [ 142 [ 'keyword', 1, 1, 2 ], 143 [ 'Whitespace', 1, 3, 1 ], 144 [ 'keyword', 1, 4, 4 ], 145 [ 'Whitespace', 1, 8, 1 ], 146 [ 'keyword', 1, 9, 5 ], 147 [ 'Whitespace', 1, 14, 1 ], 148 [ 'keyword', 1, 15, 6 ], 149 [ 'Whitespace', 1, 21, 1 ], 150 [ 'keyword', 1, 22, 3 ], 151 [ 'Whitespace', 1, 25, 1 ], 152 [ 'keyword', 1, 26, 7 ], 153 [ 'Whitespace', 1, 33, 1 ], 154 [ 'keyword', 1, 34, 5 ], 155 [ 'Whitespace', 1, 39, 1 ], 156 [ 'keyword', 1, 40, 2 ], 157 [ 'Whitespace', 1, 42, 1 ], 158 207 159 ], 208 160 }, 161 { code => <<'END_CODE', 162 package 163 END_CODE 164 expected => [ [ 'keyword', 1, 1, 7 ], [ 'Whitespace', 1, 8, 1 ], ], 165 }, 209 166 ); 210 167 211 168 plan tests => @cases * 1; … … 215 172 my @result; 216 173 foreach my $c (@cases) { 217 174 @result = (); 218 PPIx::EditorTools::Lexer->new->lexer( code => $c->{code}, highlighter => \&highlighter ); 219 220 #diag explain @result; 221 is_deeply \@result, $c->{expected}; 175 PPIx::EditorTools::Lexer->new->lexer( 176 code => $c->{code}, 177 highlighter => \&highlighter 178 ); 179 is_deeply \@result, $c->{expected} or diag explain @result; 222 180 } 223 181 224 182 sub highlighter { 225 183 push @result, [@_]; 226 184 } 227 185 228 229 -
t/outline/Moofirst.pm
1 use MooseX::Declare; 2 3 role Moofirst { 4 requires '_build_overdraft'; 5 use version; our $VERSION = version->new('1.0.1'); 6 7 has 'balance' => ( 8 isa => 'Num', 9 is => 'rw', 10 default => 0 11 ); 12 13 has 'overdraft' => ( 14 isa => 'Bool', 15 is => 'rw', 16 lazy_build => 1, 17 init_arg => undef, 18 ); 19 } 20 21 class Mooclass { 22 23 has 'name' => ( isa => 'Str', is => 'rw', ); 24 25 has qw(account) => ( is => 'rw', ); 26 27 method _build_overdraft { 28 return; 29 } 30 } -
t/outline/Moorole.pm
1 use MooseX::Declare; 2 3 role Moorole { 4 requires '_build_overdraft'; 5 use version; our $VERSION = version->new('1.0.1'); 6 7 has 'balance' => ( 8 isa => 'Num', 9 is => 'rw', 10 default => 0 11 ); 12 13 has 'overdraft' => ( 14 isa => 'Bool', 15 is => 'rw', 16 lazy_build => 1, 17 init_arg => undef, 18 ); 19 } 20 -
t/outline/Mooclass.pm
1 use MooseX::Declare; 2 3 class Mooclass { 4 5 has 'moo_att' => ( is => 'rw', ); 6 7 has [qw/ label progress butWarn butTime start_stop /] => 8 ( isa => 'Ref', is => 'rw' ); 9 10 has qw(account) => ( is => 'rw', ); 11 12 method pub_sub { 13 return; 14 } 15 16 method _pri_sub { 17 return; 18 } 19 20 before mm_before { 21 return; 22 } 23 24 after mm_after { 25 return; 26 } 27 28 around mm_around { 29 return; 30 } 31 32 override mm_override { 33 return; 34 } 35 36 augment mm_augment { 37 return; 38 } 39 } 40 -
t/00-ppix-editortools.t
1 #!/usr/bin/eval perl 2 3 use strict; 4 use English '-no_match_vars'; 5 6 BEGIN { 7 $WARNING = 1; 8 } 9 use Test::More tests => 39; 10 use Test::Exception; 11 ###### 12 # let's check our requirments. 13 ###### 14 use_ok('Carp'); 15 16 ### you could do this but why? 17 # 18 #use Carp qw(croak); 19 #eval( use_ok( 'PPI', '1.215' ) ); 20 #if ($EVAL_ERROR) { croak; } 21 # 22 ### when you can just do this 23 use_ok( 'PPI', '1.215' ); 24 use_ok('PPI::Find'); 25 use_ok( 'Class::XSAccessor', '1.02' ); 26 use_ok('File::Spec'); 27 use_ok('File::Basename'); 28 use_ok('File::Find'); 29 use_ok('File::Temp'); 30 use_ok( 'Test::More', '0.88' ); 31 32 #use_ok( 'Test::Most'); # craps out !! 33 use_ok('Test::Differences'); 34 35 #use_ok( 'Test::NoWarnings', '0.084'); # craps out !! 36 37 ###### 38 # let's check our package. 39 ###### 40 my $pet_obj; 41 require PPIx::EditorTools; 42 $pet_obj = new_ok('PPIx::EditorTools'); 43 44 my @subs = 45 qw( new code ppi process_doc find_unmatched_brace get_all_variable_declarations element_depth find_token_at_location find_variable_declaration ); 46 use_ok( 'PPIx::EditorTools', @subs ); 47 48 foreach my $subs (@subs) { 49 can_ok( 'PPIx::EditorTools', $subs ); 50 } 51 52 #TODO need more pkg tests 53 use PPIx::EditorTools; 54 55 # Check that something died - we do not care why 56 dies_ok { PPIx::EditorTools->process_doc() } 'expecting PPIx::EditorTools->process_doc() to die'; 57 58 my %case = ( one => 'use strict;', two => 'use warnings', ); 59 my $obj = PPIx::EditorTools->new(); 60 $obj->code('use strict; use warnings'); 61 $obj->ppi(undef); 62 ok( $obj->process_doc(%case), 'process_doc(code)' ); 63 64 %case = ( one => 'ppi', two => 'PPI::Document', ); 65 $obj->ppi('PPI::Document'); 66 $obj->code(undef); 67 ok( $obj->process_doc(%case), 'process_doc(ppi)' ); 68 69 $obj->ppi(undef); 70 $obj->code(undef); 71 72 #not_ok ( $obj->process_doc( %case), 'process_doc(ppi)' ); 73 74 throws_ok { $obj->process_doc(%case) } '/arguments ppi or code required/', 'arguments ppi or code required'; 75 76 dies_ok { PPIx::EditorTools->find_unmatched_brace() } 'expecting PPIx::EditorTools->find_unmatched_brace() to die'; 77 dies_ok { PPIx::EditorTools->get_all_variable_declarations() } 78 'expecting PPIx::EditorTools->get_all_variable_declarations() to die'; 79 dies_ok { PPIx::EditorTools->element_depth() } 'expecting PPIx::EditorTools->element_depth() to die'; 80 dies_ok { PPIx::EditorTools->find_token_at_location() } 'expecting PPIx::EditorTools->find_token_at_location() to die'; 81 82 #dies_ok { PPIx::EditorTools->find_variable_declaration() } 'expecting PPIx::EditorTools->find_variable_declaration() to die'; 83 ###### 84 # let's check our lib's are here. 85 ###### 86 my $test_object; 87 require PPIx::EditorTools::FindUnmatchedBrace; 88 $test_object = new_ok('PPIx::EditorTools::FindUnmatchedBrace'); 89 90 require PPIx::EditorTools::FindVariableDeclaration; 91 $test_object = new_ok('PPIx::EditorTools::FindVariableDeclaration'); 92 93 require PPIx::EditorTools::IntroduceTemporaryVariable; 94 $test_object = new_ok('PPIx::EditorTools::IntroduceTemporaryVariable'); 95 96 require PPIx::EditorTools::RenamePackage; 97 $test_object = new_ok('PPIx::EditorTools::RenamePackage'); 98 99 require PPIx::EditorTools::RenamePackageFromPath; 100 $test_object = new_ok('PPIx::EditorTools::RenamePackageFromPath'); 101 102 require PPIx::EditorTools::RenameVariable; 103 $test_object = new_ok('PPIx::EditorTools::RenameVariable'); 104 105 require PPIx::EditorTools::FindUnmatchedBrace; 106 $test_object = new_ok('PPIx::EditorTools::FindUnmatchedBrace'); 107 108 require PPIx::EditorTools::Outline; 109 $test_object = new_ok('PPIx::EditorTools::Outline'); 110 111 require PPIx::EditorTools::Lexer; 112 $test_object = new_ok('PPIx::EditorTools::Lexer'); 113 114 require PPIx::EditorTools::ReturnObject; 115 $test_object = new_ok('PPIx::EditorTools::ReturnObject'); 116 117 done_testing()
