@@ -9,26 +9,57 @@ mod changes_from_objects {
99
1010 #[ test]
1111 fn addition ( ) -> crate :: Result {
12- let _index = index_ro ( ) ?;
13- let changes = changes ( & _index, "initial commit" ) ?;
12+ let changes = changes ( & index_ro ( ) ?, ":/initial commit" ) ?;
1413 assert_eq ! ( changes. len( ) , 3228 ) ;
1514 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" )
1819 ) ) ;
1920 assert ! ( matches!(
2021 changes. last( ) . expect( "present" ) ,
2122 Change :: Added ( CrateVersion { name, ..} ) if name == "gizmo"
2223 ) ) ;
2324 Ok ( ( ) )
2425 }
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+ }
2559
26- fn changes ( index : & Index , commit_message : & str ) -> crate :: Result < Vec < Change > > {
60+ fn changes ( index : & Index , revspec : & str ) -> crate :: Result < Vec < Change > > {
2761 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 ( ) ;
3263 let ancestor_tree = commit
3364 . object ( ) ?
3465 . into_commit ( )
0 commit comments