File tree Expand file tree Collapse file tree 3 files changed +82
-38
lines changed
git-repository/tests/object Expand file tree Collapse file tree 3 files changed +82
-38
lines changed Original file line number Diff line number Diff line change
1
+ use std:: cmp:: Ordering ;
2
+
3
+ use git_testtools:: hex_to_id;
4
+
5
+ use crate :: basic_repo;
6
+
7
+ #[ test]
8
+ fn short_id ( ) -> crate :: Result {
9
+ let repo = basic_repo ( ) ?;
10
+ let commit = repo. head_commit ( ) ?;
11
+ assert_eq ! ( commit. short_id( ) ?. cmp_oid( & commit. id) , Ordering :: Equal ) ;
12
+ Ok ( ( ) )
13
+ }
14
+
15
+ #[ test]
16
+ fn tree ( ) -> crate :: Result {
17
+ let repo = basic_repo ( ) ?;
18
+ let commit = repo. head_commit ( ) ?;
19
+
20
+ assert_eq ! ( commit. tree( ) ?. id, commit. tree_id( ) . expect( "id present" ) ) ;
21
+ assert_eq ! (
22
+ commit. tree_id( ) . ok( ) . map( |id| id. detach( ) ) ,
23
+ Some ( hex_to_id( "21d3ba9a26b790a4858d67754ae05d04dfce4d0c" ) )
24
+ ) ;
25
+ Ok ( ( ) )
26
+ }
27
+
28
+ #[ test]
29
+ fn decode ( ) -> crate :: Result {
30
+ let repo = basic_repo ( ) ?;
31
+ let commit = repo. head_commit ( ) ?;
32
+ assert_eq ! ( commit. decode( ) ?. message, commit. message_raw( ) ?) ;
33
+ assert_eq ! ( commit. decode( ) ?. message( ) , commit. message( ) ?) ;
34
+ assert_eq ! ( commit. decode( ) ?. message, "c2\n " ) ;
35
+ Ok ( ( ) )
36
+ }
Original file line number Diff line number Diff line change 1
- mod commit {
2
- use std:: cmp:: Ordering ;
3
-
4
- use git_testtools:: hex_to_id;
5
-
6
- use crate :: basic_repo;
7
-
8
- #[ test]
9
- fn short_id ( ) -> crate :: Result {
10
- let repo = basic_repo ( ) ?;
11
- let commit = repo. head_commit ( ) ?;
12
- assert_eq ! ( commit. short_id( ) ?. cmp_oid( & commit. id) , Ordering :: Equal ) ;
13
- Ok ( ( ) )
14
- }
15
-
16
- #[ test]
17
- fn tree ( ) -> crate :: Result {
18
- let repo = basic_repo ( ) ?;
19
- let commit = repo. head_commit ( ) ?;
20
-
21
- assert_eq ! ( commit. tree( ) ?. id, commit. tree_id( ) . expect( "id present" ) ) ;
22
- assert_eq ! (
23
- commit. tree_id( ) . ok( ) . map( |id| id. detach( ) ) ,
24
- Some ( hex_to_id( "21d3ba9a26b790a4858d67754ae05d04dfce4d0c" ) )
25
- ) ;
26
- Ok ( ( ) )
27
- }
28
-
29
- #[ test]
30
- fn decode ( ) -> crate :: Result {
31
- let repo = basic_repo ( ) ?;
32
- let commit = repo. head_commit ( ) ?;
33
- assert_eq ! ( commit. decode( ) ?. message, commit. message_raw( ) ?) ;
34
- assert_eq ! ( commit. decode( ) ?. message( ) , commit. message( ) ?) ;
35
- assert_eq ! ( commit. decode( ) ?. message, "c2\n " ) ;
36
- Ok ( ( ) )
37
- }
38
- }
1
+ mod commit;
2
+ mod tree;
39
3
40
4
#[ test]
41
5
fn object_ref_size_in_memory ( ) {
Original file line number Diff line number Diff line change
1
+ mod diff {
2
+ use crate :: remote;
3
+ use git_object:: bstr:: ByteSlice ;
4
+ use git_object:: tree:: EntryMode ;
5
+ use git_repository as git;
6
+ use git_repository:: object:: tree:: diff:: Event ;
7
+ use std:: convert:: Infallible ;
8
+
9
+ #[ test]
10
+ fn changes_against_tree_modified ( ) {
11
+ let repo = remote:: repo ( "base" ) ;
12
+ let from = tree_named ( & repo, "g" ) ;
13
+ let to = tree_named ( & repo, "h" ) ;
14
+ from. changes ( )
15
+ . for_each_to_obtain_tree ( & to, |event| -> Result < _ , Infallible > {
16
+ match event {
17
+ Event :: Modification {
18
+ previous_entry_mode,
19
+ previous_id,
20
+ entry_mode,
21
+ id,
22
+ } => {
23
+ assert_eq ! ( previous_entry_mode, EntryMode :: Blob ) ;
24
+ assert_eq ! ( entry_mode, EntryMode :: Blob ) ;
25
+ assert_eq ! ( previous_id. object( ) . unwrap( ) . data. as_bstr( ) , "g\n " ) ;
26
+ assert_eq ! ( id. object( ) . unwrap( ) . data. as_bstr( ) , "h\n " ) ;
27
+ Ok ( git:: diff:: tree:: visit:: Action :: Continue )
28
+ }
29
+ Event :: Deletion { .. } | Event :: Addition { .. } => unreachable ! ( "only modification is expected" ) ,
30
+ }
31
+ } )
32
+ . unwrap ( ) ;
33
+ }
34
+
35
+ fn tree_named < ' repo > ( repo : & ' repo git:: Repository , rev_spec : & str ) -> git:: Tree < ' repo > {
36
+ repo. rev_parse_single ( rev_spec)
37
+ . unwrap ( )
38
+ . object ( )
39
+ . unwrap ( )
40
+ . peel_to_kind ( git:: object:: Kind :: Tree )
41
+ . unwrap ( )
42
+ . into_tree ( )
43
+ }
44
+ }
You can’t perform that action at this time.
0 commit comments