@@ -546,3 +546,180 @@ fn test_convert_command_output_to_android() {
546546 assert ! ( output. status. success( ) ) ;
547547 assert ! ( output_file. exists( ) ) ;
548548}
549+
550+ #[ test]
551+ fn test_merge_command_updated_behavior ( ) {
552+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
553+ let input_file1 = temp_dir. path ( ) . join ( "file1.strings" ) ;
554+ let input_file2 = temp_dir. path ( ) . join ( "file2.strings" ) ;
555+ let output_file = temp_dir. path ( ) . join ( "merged.strings" ) ;
556+
557+ // Create two .strings files with the same language but different keys
558+ let strings_content1 = r#"/* Greeting */
559+ "hello" = "Hello";"# ;
560+
561+ let strings_content2 = r#"/* Farewell */
562+ "goodbye" = "Goodbye";"# ;
563+
564+ fs:: write ( & input_file1, strings_content1) . unwrap ( ) ;
565+ fs:: write ( & input_file2, strings_content2) . unwrap ( ) ;
566+
567+ let output = Command :: new ( "cargo" )
568+ . args ( [
569+ "run" ,
570+ "--" ,
571+ "merge" ,
572+ "-i" ,
573+ input_file1. to_str ( ) . unwrap ( ) ,
574+ "-i" ,
575+ input_file2. to_str ( ) . unwrap ( ) ,
576+ "-o" ,
577+ output_file. to_str ( ) . unwrap ( ) ,
578+ "--strategy" ,
579+ "last" ,
580+ ] )
581+ . output ( )
582+ . unwrap ( ) ;
583+
584+ assert ! ( output. status. success( ) ) ;
585+ assert ! ( output_file. exists( ) ) ;
586+
587+ // Verify the output contains the expected merge count message
588+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
589+ assert ! (
590+ stdout. contains( "Merged 1 language groups" ) ,
591+ "Expected merge count message, got: {}" ,
592+ stdout
593+ ) ;
594+
595+ // Verify the output contains the success message
596+ assert ! (
597+ stdout. contains( "✅ Successfully merged 2 files into" ) ,
598+ "Expected success message, got: {}" ,
599+ stdout
600+ ) ;
601+
602+ // Verify the merged file contains both entries
603+ let merged_content = fs:: read_to_string ( & output_file) . unwrap ( ) ;
604+ assert ! ( merged_content. contains( "hello" ) ) ;
605+ assert ! ( merged_content. contains( "goodbye" ) ) ;
606+ }
607+
608+ #[ test]
609+ fn test_merge_command_with_language_override ( ) {
610+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
611+ let input_file1 = temp_dir. path ( ) . join ( "file1.strings" ) ;
612+ let input_file2 = temp_dir. path ( ) . join ( "file2.strings" ) ;
613+ let output_file = temp_dir. path ( ) . join ( "merged.strings" ) ;
614+
615+ // Create two .strings files with different content
616+ let strings_content1 = r#"/* Greeting */
617+ "hello" = "Hello";"# ;
618+
619+ let strings_content2 = r#"/* Farewell */
620+ "goodbye" = "Goodbye";"# ;
621+
622+ fs:: write ( & input_file1, strings_content1) . unwrap ( ) ;
623+ fs:: write ( & input_file2, strings_content2) . unwrap ( ) ;
624+
625+ let output = Command :: new ( "cargo" )
626+ . args ( [
627+ "run" ,
628+ "--" ,
629+ "merge" ,
630+ "-i" ,
631+ input_file1. to_str ( ) . unwrap ( ) ,
632+ "-i" ,
633+ input_file2. to_str ( ) . unwrap ( ) ,
634+ "-o" ,
635+ output_file. to_str ( ) . unwrap ( ) ,
636+ "-l" ,
637+ "en" ,
638+ "--strategy" ,
639+ "first" ,
640+ ] )
641+ . output ( )
642+ . unwrap ( ) ;
643+
644+ assert ! ( output. status. success( ) ) ;
645+ assert ! ( output_file. exists( ) ) ;
646+
647+ // Verify the output contains the expected merge count message
648+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
649+ assert ! (
650+ stdout. contains( "Merged 1 language groups" ) ,
651+ "Expected merge count message, got: {}" ,
652+ stdout
653+ ) ;
654+
655+ // Verify the output contains the success message
656+ assert ! (
657+ stdout. contains( "✅ Successfully merged 2 files into" ) ,
658+ "Expected success message, got: {}" ,
659+ stdout
660+ ) ;
661+
662+ // Verify the merged file contains both entries
663+ let merged_content = fs:: read_to_string ( & output_file) . unwrap ( ) ;
664+ assert ! ( merged_content. contains( "hello" ) ) ;
665+ assert ! ( merged_content. contains( "goodbye" ) ) ;
666+ }
667+
668+ #[ test]
669+ fn test_merge_command_multiple_languages_no_merges ( ) {
670+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
671+ let input_file1 = temp_dir. path ( ) . join ( "file1.strings" ) ;
672+ let input_file2 = temp_dir. path ( ) . join ( "file2.strings" ) ;
673+ let output_file = temp_dir. path ( ) . join ( "merged.strings" ) ;
674+
675+ // Create two .strings files with different keys (no conflicts)
676+ let content1 = r#"/* Greeting */
677+ "hello" = "Hello";"# ;
678+
679+ let content2 = r#"/* Farewell */
680+ "goodbye" = "Goodbye";"# ;
681+
682+ fs:: write ( & input_file1, content1) . unwrap ( ) ;
683+ fs:: write ( & input_file2, content2) . unwrap ( ) ;
684+
685+ let output = Command :: new ( "cargo" )
686+ . args ( [
687+ "run" ,
688+ "--" ,
689+ "merge" ,
690+ "-i" ,
691+ input_file1. to_str ( ) . unwrap ( ) ,
692+ "-i" ,
693+ input_file2. to_str ( ) . unwrap ( ) ,
694+ "-o" ,
695+ output_file. to_str ( ) . unwrap ( ) ,
696+ "--strategy" ,
697+ "last" ,
698+ ] )
699+ . output ( )
700+ . unwrap ( ) ;
701+
702+ assert ! ( output. status. success( ) ) ;
703+ assert ! ( output_file. exists( ) ) ;
704+
705+ // Since both files have the same language (empty, inferred from path), they should merge
706+ // Verify the output contains the expected merge count message (1 merge since same language)
707+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
708+ assert ! (
709+ stdout. contains( "Merged 1 language groups" ) ,
710+ "Expected 1 merge count message, got: {}" ,
711+ stdout
712+ ) ;
713+
714+ // Verify the output contains the success message
715+ assert ! (
716+ stdout. contains( "✅ Successfully merged 2 files into" ) ,
717+ "Expected success message, got: {}" ,
718+ stdout
719+ ) ;
720+
721+ // Verify the merged file contains both entries
722+ let merged_content = fs:: read_to_string ( & output_file) . unwrap ( ) ;
723+ assert ! ( merged_content. contains( "hello" ) ) ;
724+ assert ! ( merged_content. contains( "goodbye" ) ) ;
725+ }
0 commit comments