@@ -2,7 +2,7 @@ use but_core::RefMetadata;
2
2
use but_core:: ref_metadata:: { StackId , ValueInfo , WorkspaceStack , WorkspaceStackBranch } ;
3
3
use but_graph:: VirtualBranchesTomlMetadata ;
4
4
use but_testsupport:: gix_testtools:: tempfile:: { TempDir , tempdir} ;
5
- use std :: collections :: HashMap ;
5
+ use but_testsupport :: { debug_str , sanitize_uuids_and_timestamps_with_mapping } ;
6
6
use std:: ops:: Deref ;
7
7
use std:: path:: PathBuf ;
8
8
@@ -39,7 +39,7 @@ fn read_only() -> anyhow::Result<()> {
39
39
let ( mut store, _tmp) = vb_store_rw ( "virtual-branches-01" ) ?;
40
40
let ws = store. workspace ( "refs/heads/gitbutler/workspace" . try_into ( ) ?) ?;
41
41
assert ! ( !ws. is_default( ) , "value read from file" ) ;
42
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & ws. stacks ) ) ;
42
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & ws. stacks ) ) ;
43
43
insta:: assert_snapshot!( actual, @r#"
44
44
[
45
45
WorkspaceStack {
@@ -421,7 +421,7 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
421
421
422
422
// Assure `ws` is what we think it should be - a single stack with one branch.
423
423
let mut ws = store. workspace ( workspace_name. as_ref ( ) ) ?;
424
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & ws. stacks ) ) ;
424
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & ws. stacks ) ) ;
425
425
insta:: assert_snapshot!( actual, @r#"
426
426
[
427
427
WorkspaceStack {
@@ -461,7 +461,7 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
461
461
. expect ( "This is the way to add branches" ) ;
462
462
463
463
let mut ws = store. workspace ( workspace_name. as_ref ( ) ) ?;
464
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & ws. stacks ) ) ;
464
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & ws. stacks ) ) ;
465
465
insta:: assert_snapshot!( actual, @r#"
466
466
[
467
467
WorkspaceStack {
@@ -491,7 +491,8 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
491
491
drop ( store) ;
492
492
493
493
assert ! ( toml_path. exists( ) , "file was written due to change" ) ;
494
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( std:: fs:: read_to_string ( & toml_path) ?) ;
494
+ let ( actual, uuids) =
495
+ sanitize_uuids_and_timestamps_with_mapping ( std:: fs:: read_to_string ( & toml_path) ?) ;
495
496
insta:: assert_snapshot!( actual, @r#"
496
497
[branch_targets]
497
498
@@ -538,7 +539,7 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
538
539
ws. deref( ) ,
539
540
"It's still what it was before - it was persisted"
540
541
) ;
541
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & new_ws. stacks ) ) ;
542
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & new_ws. stacks ) ) ;
542
543
insta:: assert_snapshot!( actual, @r#"
543
544
[
544
545
WorkspaceStack {
@@ -576,7 +577,7 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
576
577
) ;
577
578
store. set_workspace ( & ws) ?;
578
579
let mut ws = store. workspace ( workspace_name. as_ref ( ) ) ?;
579
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & ws. stacks ) ) ;
580
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & ws. stacks ) ) ;
580
581
insta:: assert_snapshot!( actual, @r#"
581
582
[
582
583
WorkspaceStack {
@@ -639,7 +640,7 @@ fn create_workspace_and_stacks_with_branches_from_scratch() -> anyhow::Result<()
639
640
store. set_workspace ( & ws) ?;
640
641
let mut ws = store. workspace ( ws. as_ref ( ) ) ?;
641
642
// Two stacks are present now.
642
- let ( actual, uuids) = sanitize_uuids_and_timestamps ( debug_str ( & ws. stacks ) ) ;
643
+ let ( actual, uuids) = sanitize_uuids_and_timestamps_with_mapping ( debug_str ( & ws. stacks ) ) ;
643
644
insta:: assert_snapshot!( actual, @r#"
644
645
[
645
646
WorkspaceStack {
@@ -960,42 +961,3 @@ fn roundtrip_journey(metadata: &mut impl RefMetadata) -> anyhow::Result<()> {
960
961
assert_eq ! ( metadata. iter( ) . count( ) , 0 , "Nothing is left after deletion" ) ;
961
962
Ok ( ( ) )
962
963
}
963
-
964
- fn sanitize_uuids_and_timestamps ( input : String ) -> ( String , HashMap < String , usize > ) {
965
- let uuid_regex = regex:: Regex :: new (
966
- r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" ,
967
- )
968
- . unwrap ( ) ;
969
- let timestamp_regex = regex:: Regex :: new ( r#""\d{13}""# ) . unwrap ( ) ;
970
-
971
- let mut uuid_map: HashMap < String , usize > = HashMap :: new ( ) ;
972
- let mut uuid_counter = 1 ;
973
-
974
- let mut timestamp_map: HashMap < String , usize > = HashMap :: new ( ) ;
975
- let mut timestamp_counter = 12_345 ;
976
-
977
- let result = uuid_regex. replace_all ( & input, |caps : & regex:: Captures | {
978
- let uuid = caps. get ( 0 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
979
- let entry = uuid_map. entry ( uuid) . or_insert_with ( || {
980
- let num = uuid_counter;
981
- uuid_counter += 1 ;
982
- num
983
- } ) ;
984
- entry. to_string ( )
985
- } ) ;
986
- let result = timestamp_regex. replace_all ( & result, |caps : & regex:: Captures | {
987
- let timestamp = caps. get ( 0 ) . unwrap ( ) . as_str ( ) . to_string ( ) ;
988
- let entry = timestamp_map. entry ( timestamp) . or_insert_with ( || {
989
- let num = timestamp_counter;
990
- timestamp_counter += 1 ;
991
- num
992
- } ) ;
993
- entry. to_string ( )
994
- } ) ;
995
-
996
- ( result. to_string ( ) , uuid_map)
997
- }
998
-
999
- fn debug_str ( input : & dyn std:: fmt:: Debug ) -> String {
1000
- format ! ( "{:#?}" , input)
1001
- }
0 commit comments