@@ -9,26 +9,57 @@ mod changes_from_objects {
9
9
10
10
#[ test]
11
11
fn addition ( ) -> crate :: Result {
12
- let _index = index_ro ( ) ?;
13
- let changes = changes ( & _index, "initial commit" ) ?;
12
+ let changes = changes ( & index_ro ( ) ?, ":/initial commit" ) ?;
14
13
assert_eq ! ( changes. len( ) , 3228 ) ;
15
14
assert ! ( matches!(
16
- changes. first( ) . expect( "present" ) ,
17
- Change :: Added ( CrateVersion { name, ..} ) if name == "gi-get-artifact"
15
+ changes
16
+ . first( )
17
+ . and_then( |c| c. added( ) . map( |v| v. name. as_str( ) ) ) ,
18
+ Some ( "gi-get-artifact" )
18
19
) ) ;
19
20
assert ! ( matches!(
20
21
changes. last( ) . expect( "present" ) ,
21
22
Change :: Added ( CrateVersion { name, ..} ) if name == "gizmo"
22
23
) ) ;
23
24
Ok ( ( ) )
24
25
}
26
+ #[ test]
27
+ fn deletion ( ) -> crate :: Result {
28
+ let changes = changes ( & index_ro ( ) ?, "@~326" ) ?;
29
+ assert_eq ! ( changes. len( ) , 1 ) ;
30
+ assert_eq ! ( changes. first( ) . and_then( |c| c. deleted( ) ) , Some ( "girl" ) ) ;
31
+ Ok ( ( ) )
32
+ }
33
+
34
+ #[ test]
35
+ fn new_version ( ) -> crate :: Result {
36
+ let changes = changes ( & index_ro ( ) ?, ":/Updating crate `git-repository#0.22.1`" ) ?;
37
+ assert_eq ! ( changes. len( ) , 1 ) ;
38
+ assert_eq ! (
39
+ changes
40
+ . first( )
41
+ . and_then( |c| c. added( ) . map( |v| v. name. as_str( ) ) ) ,
42
+ Some ( "git-repository" )
43
+ ) ;
44
+ Ok ( ( ) )
45
+ }
46
+
47
+ #[ test]
48
+ fn yanked ( ) -> crate :: Result {
49
+ let changes = changes ( & index_ro ( ) ?, ":/Yanking crate `github_release_rs#0.1.0`" ) ?;
50
+ assert_eq ! ( changes. len( ) , 1 ) ;
51
+ assert_eq ! (
52
+ changes
53
+ . first( )
54
+ . and_then( |c| c. yanked( ) . map( |v| v. name. as_str( ) ) ) ,
55
+ Some ( "github_release_rs" )
56
+ ) ;
57
+ Ok ( ( ) )
58
+ }
25
59
26
- fn changes ( index : & Index , commit_message : & str ) -> crate :: Result < Vec < Change > > {
60
+ fn changes ( index : & Index , revspec : & str ) -> crate :: Result < Vec < Change > > {
27
61
let repo = git:: open ( index. repository ( ) . path ( ) ) ?;
28
- let commit = repo
29
- . rev_parse ( format ! ( ":/{commit_message}" ) . as_str ( ) ) ?
30
- . single ( )
31
- . unwrap ( ) ;
62
+ let commit = repo. rev_parse ( revspec) ?. single ( ) . unwrap ( ) ;
32
63
let ancestor_tree = commit
33
64
. object ( ) ?
34
65
. into_commit ( )
0 commit comments