Merge branch 'tidy-project'
[catagits/Gitalist.git] / t / 02git_object.t
CommitLineData
a8a8f8f9 1use strict;
2use warnings;
3use FindBin qw/$Bin/;
4use Test::More qw/no_plan/;
56908878 5use Test::Exception;
a8a8f8f9 6use Data::Dumper;
7
50394a3e 8use Path::Class;
9use Gitalist::Git::Project;
10my $project = Gitalist::Git::Project->new(
b5b638f7 11 dir("$Bin/lib/repositories/repo1"),
50394a3e 12);
13
a8a8f8f9 14BEGIN { use_ok 'Gitalist::Git::Object' }
15
16my $object = Gitalist::Git::Object->new(
50394a3e 17 project => $project,
a8a8f8f9 18 sha1 => '729a7c3f6ba5453b42d16a43692205f67fb23bc1',
19 type => 'tree',
20 file => 'dir1',
21 mode => 16384,
22);
23isa_ok($object, 'Gitalist::Git::Object');
50394a3e 24is($object->sha1,'729a7c3f6ba5453b42d16a43692205f67fb23bc1', 'sha1 is correct');
25is($object->type, 'tree', 'type is correct');
26is($object->file, 'dir1', 'file is correct');
a8a8f8f9 27is($object->mode, 16384, 'mode is correct');
28is($object->modestr, 'd---------', "modestr is correct" );
483b98b7 29is($object->size, 33, "size is correct");
a8a8f8f9 30
54368e9d 31# Create object from sha1.
50394a3e 32my $obj2 = Gitalist::Git::Object->new(
33 project => $project,
34 sha1 => '5716ca5987cbf97d6bb54920bea6adde242d87e6',
50394a3e 35);
36isa_ok($obj2, 'Gitalist::Git::Object');
37is($obj2->sha1,'5716ca5987cbf97d6bb54920bea6adde242d87e6', 'sha1 is correct');
38is($obj2->type, 'blob', 'type is correct');
54368e9d 39is($obj2->mode, 0, 'mode is correct');
40is($obj2->modestr, '?---------', "modestr is correct" );
56908878 41is($obj2->content, "bar\n", 'obj2 contents is correct');
483b98b7 42is($obj2->size, 4, "size is correct");
56908878 43dies_ok {
44 print $obj2->tree_sha1;
45} 'tree_sha1 on a blob is an exception';
46dies_ok {
47 print $obj2->comment;
48} 'comment is an empty string';