Delete tests for the old model, and add a few to the new model.
[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';
85762693 49
50my $commit_obj = Gitalist::Git::Object->new(
51 project => $project,
52 sha1 => '3f7567c7bdf7e7ebf410926493b92d398333116e',
53);
54isa_ok($commit_obj, 'Gitalist::Git::Object', "commit object type correct");
55my ($tree, $patch) = $commit_obj->diff(
56 parent => undef,
57 file => undef,
58 patch => 1,
59);
60$patch = $patch->[0];
61is($patch->{head}, 'diff --git a/file1 b/file1', 'patch->{head} is correct');
62is($patch->{a}, 'a/file1', 'patch->{a} is correct');
63is($patch->{b}, 'b/file1', 'patch->{b} is correct');
64is($patch->{file}, 'file1', 'patch->{file} is correct');
65is($patch->{mode}, '100644', 'patch->{mode} is correct');
66is($patch->{src}, '257cc5642cb1a054f08cc83f2d943e56fd3ebe99', 'patch->{src} is correct');
67is($patch->{index}, 'index 257cc5642cb1a054f08cc83f2d943e56fd3ebe99..5716ca5987cbf97d6bb54920bea6adde242d87e6 100644', 'patch->{index} is correct');
68is($patch->{diff}, '--- a/file1
69+++ b/file1
70@@ -1 +1 @@
71-foo
72+bar
73', 'patch->{diff} is correct');
74is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');