Default ::Object attributes tree_sha1 and comment to '' when not present.
[catagits/Gitalist.git] / t / 02git_object.t
1 use strict;
2 use warnings;
3 use FindBin qw/$Bin/;
4 use Test::More qw/no_plan/;
5
6 use Data::Dumper;
7
8 use Path::Class;
9 use Gitalist::Git::Project;
10 my $project = Gitalist::Git::Project->new(
11     name => 'repo1',
12     path => dir("$Bin/lib/repositories/repo1"),
13 );
14
15 BEGIN { use_ok 'Gitalist::Git::Object' }
16
17 my $object = Gitalist::Git::Object->new(
18     project => $project,
19     sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
20     type => 'tree',
21     file => 'dir1',
22     mode => 16384,
23 );
24 isa_ok($object, 'Gitalist::Git::Object');
25 is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
26 is($object->type, 'tree', 'type is correct');
27 is($object->file, 'dir1', 'file is correct');
28 is($object->mode, 16384, 'mode is correct');
29 is($object->modestr, 'd---------', "modestr is correct" );
30 is($object->size, 33, "size is correct");
31
32 # Create object from sha1.
33 my $obj2 = Gitalist::Git::Object->new(
34     project => $project,
35     sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
36 );
37 isa_ok($obj2, 'Gitalist::Git::Object');
38 is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct');
39 is($obj2->type, 'blob', 'type is correct');
40 is($obj2->mode, 0, 'mode is correct');
41 is($obj2->modestr, '?---------', "modestr is correct" );
42 is($obj2->contents, "bar\n", 'obj2 contents is correct');
43 is($obj2->size, 4, "size is correct");
44 is($obj2->tree_sha1, '', 'tree_sha1 is an empty string');
45 is($obj2->comments, '', 'comments is an empty string');