]> Dogcows Code - chaz/git-codeowners/blobdiff - t/file-codeowners.t
add rename_project function to File::Codeowners
[chaz/git-codeowners] / t / file-codeowners.t
index a50a050eb8dbebb859297879100481c7a72e80e8..7bfb53ca9636eb48e812f137b0e435bf1b18ad7b 100644 (file)
@@ -94,6 +94,30 @@ subtest 'parse errors', sub {
     like($@, qr/^Parse error on line 1/, 'parse error');
 };
 
+subtest 'handling projects', sub {
+    my $file = File::Codeowners->parse("$Bin/samples/kitchensink.CODEOWNERS");
+    my $r;
+
+    is_deeply($r = $file->projects, [
+        'Transportation',
+    ], 'projects listed') or diag explain $r;
+
+    $file->rename_project('Transportation', 'Getting Around');
+    is_deeply($r = $file->projects, [
+        'Getting Around',
+    ], 'project renamed') or diag explain $r;
+
+    is_deeply($r = [@{$file->_lines}[-3 .. -1]], [
+        {comment => ' Project: Getting Around', project => 'Getting Around'},
+        {},
+        {pattern => '/vehicles/**/batmobile.cad', 'owners' => ['@"Lucius Fox"'], project => 'Getting Around'},
+    ], 'renaming project properly modifies lines') or diag explain $r;
+
+    $file->update_owners_by_project('Getting Around', '@twoface');
+    ok( scalar grep { $_ eq '@twoface' }      @{$file->owners}, 'updating owner adds new owner');
+    ok(!scalar grep { $_ eq '@"Lucius Fox"' } @{$file->owners}, 'updating owner removes old owner');
+};
+
 subtest 'editing and writing files', sub {
     my $file = File::Codeowners->parse("$Bin/samples/basic.CODEOWNERS");
     my $r;
This page took 0.017768 seconds and 4 git commands to generate.