@@ -2,7 +2,7 @@ mod workspace {
2
2
use but_core:: ref_metadata:: Workspace ;
3
3
4
4
#[ test]
5
- fn add_new_stack_if_not_present ( ) {
5
+ fn add_new_stack_if_not_present_journey ( ) {
6
6
let mut ws = Workspace :: default ( ) ;
7
7
assert_eq ! ( ws. stacks. len( ) , 0 ) ;
8
8
@@ -18,6 +18,100 @@ mod workspace {
18
18
let c_ref = r ( "refs/heads/C" ) ;
19
19
assert ! ( ws. add_or_insert_new_stack_if_not_present( c_ref, None ) ) ;
20
20
assert_eq ! ( ws. stack_names( ) . collect:: <Vec <_>>( ) , [ b_ref, a_ref, c_ref] ) ;
21
+
22
+ assert ! ( ws. remove_segment( a_ref) ) ;
23
+ assert ! ( ws. remove_segment( b_ref) ) ;
24
+ assert ! ( !ws. remove_segment( b_ref) ) ;
25
+ assert ! ( ws. remove_segment( c_ref) ) ;
26
+ assert ! ( !ws. remove_segment( c_ref) ) ;
27
+
28
+ // Everything should be removed.
29
+ insta:: assert_debug_snapshot!( ws, @r"
30
+ Workspace {
31
+ ref_info: RefInfo { created_at: None, updated_at: None },
32
+ stacks: [],
33
+ target_ref: None,
34
+ push_remote: None,
35
+ }
36
+ " ) ;
37
+ }
38
+
39
+ #[ test]
40
+ fn insert_new_segment_above_anchor_if_not_present_journey ( ) {
41
+ let mut ws = Workspace :: default ( ) ;
42
+ assert_eq ! ( ws. stacks. len( ) , 0 ) ;
43
+
44
+ let a_ref = r ( "refs/heads/A" ) ;
45
+ let b_ref = r ( "refs/heads/B" ) ;
46
+ assert_eq ! (
47
+ ws. insert_new_segment_above_anchor_if_not_present( b_ref, a_ref) ,
48
+ None ,
49
+ "anchor doesn't exist"
50
+ ) ;
51
+ assert ! ( ws. add_or_insert_new_stack_if_not_present( a_ref, None ) ) ;
52
+ assert_eq ! (
53
+ ws. insert_new_segment_above_anchor_if_not_present( b_ref, a_ref) ,
54
+ Some ( true ) ,
55
+ "anchor existed and it was added"
56
+ ) ;
57
+ assert_eq ! (
58
+ ws. insert_new_segment_above_anchor_if_not_present( b_ref, a_ref) ,
59
+ Some ( false ) ,
60
+ "anchor existed and it was NOT added as it already existed"
61
+ ) ;
62
+
63
+ let c_ref = r ( "refs/heads/C" ) ;
64
+ assert_eq ! (
65
+ ws. insert_new_segment_above_anchor_if_not_present( c_ref, a_ref) ,
66
+ Some ( true )
67
+ ) ;
68
+
69
+ insta:: assert_snapshot!( but_testsupport:: sanitize_uuids_and_timestamps( format!( "{ws:#?}" ) ) , @r#"
70
+ Workspace {
71
+ ref_info: RefInfo { created_at: None, updated_at: None },
72
+ stacks: [
73
+ WorkspaceStack {
74
+ id: 1,
75
+ branches: [
76
+ WorkspaceStackBranch {
77
+ ref_name: FullName(
78
+ "refs/heads/B",
79
+ ),
80
+ archived: false,
81
+ },
82
+ WorkspaceStackBranch {
83
+ ref_name: FullName(
84
+ "refs/heads/C",
85
+ ),
86
+ archived: false,
87
+ },
88
+ WorkspaceStackBranch {
89
+ ref_name: FullName(
90
+ "refs/heads/A",
91
+ ),
92
+ archived: false,
93
+ },
94
+ ],
95
+ },
96
+ ],
97
+ target_ref: None,
98
+ push_remote: None,
99
+ }
100
+ "# ) ;
101
+
102
+ assert ! ( ws. remove_segment( b_ref) ) ;
103
+ assert ! ( ws. remove_segment( a_ref) ) ;
104
+ assert ! ( ws. remove_segment( c_ref) ) ;
105
+
106
+ // Everything should be removed.
107
+ insta:: assert_debug_snapshot!( ws, @r"
108
+ Workspace {
109
+ ref_info: RefInfo { created_at: None, updated_at: None },
110
+ stacks: [],
111
+ target_ref: None,
112
+ push_remote: None,
113
+ }
114
+ " ) ;
21
115
}
22
116
23
117
fn r ( name : & str ) -> & gix:: refs:: FullNameRef {
0 commit comments