@@ -828,6 +828,99 @@ rgtest!(f1404_nothing_searched_ignored, |dir: Dir, mut cmd: TestCommand| {
828828 eqnice!( expected, stderr) ;
829829} ) ;
830830
831+ // See: https://github.com/BurntSushi/ripgrep/issues/1842
832+ rgtest ! ( f1842_field_context_separator, |dir: Dir , _: TestCommand | {
833+ dir. create( "sherlock" , SHERLOCK ) ;
834+
835+ // Test the default.
836+ let base = & [ "-n" , "-A1" , "Doctor Watsons" , "sherlock" ] ;
837+ let expected = "\
838+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
839+ 2-Holmeses, success in the province of detective work must always
840+ " ;
841+ eqnice!( expected, dir. command( ) . args( base) . stdout( ) ) ;
842+
843+ // Test that it can be overridden.
844+ let mut args = vec![ "--field-context-separator" , "!" ] ;
845+ args. extend( base) ;
846+ let expected = "\
847+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
848+ 2!Holmeses, success in the province of detective work must always
849+ " ;
850+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
851+
852+ // Test that it can use multiple bytes.
853+ let mut args = vec![ "--field-context-separator" , "!!" ] ;
854+ args. extend( base) ;
855+ let expected = "\
856+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
857+ 2!!Holmeses, success in the province of detective work must always
858+ " ;
859+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
860+
861+ // Test that unescaping works.
862+ let mut args = vec![ "--field-context-separator" , r"\x7F" ] ;
863+ args. extend( base) ;
864+ let expected = "\
865+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
866+ 2\x7F Holmeses, success in the province of detective work must always
867+ " ;
868+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
869+
870+ // Test that an empty separator is OK.
871+ let mut args = vec![ "--field-context-separator" , r"" ] ;
872+ args. extend( base) ;
873+ let expected = "\
874+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
875+ 2Holmeses, success in the province of detective work must always
876+ " ;
877+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
878+ } ) ;
879+
880+ // See: https://github.com/BurntSushi/ripgrep/issues/1842
881+ rgtest ! ( f1842_field_match_separator, |dir: Dir , _: TestCommand | {
882+ dir. create( "sherlock" , SHERLOCK ) ;
883+
884+ // Test the default.
885+ let base = & [ "-n" , "Doctor Watsons" , "sherlock" ] ;
886+ let expected = "\
887+ 1:For the Doctor Watsons of this world, as opposed to the Sherlock
888+ " ;
889+ eqnice!( expected, dir. command( ) . args( base) . stdout( ) ) ;
890+
891+ // Test that it can be overridden.
892+ let mut args = vec![ "--field-match-separator" , "!" ] ;
893+ args. extend( base) ;
894+ let expected = "\
895+ 1!For the Doctor Watsons of this world, as opposed to the Sherlock
896+ " ;
897+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
898+
899+ // Test that it can use multiple bytes.
900+ let mut args = vec![ "--field-match-separator" , "!!" ] ;
901+ args. extend( base) ;
902+ let expected = "\
903+ 1!!For the Doctor Watsons of this world, as opposed to the Sherlock
904+ " ;
905+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
906+
907+ // Test that unescaping works.
908+ let mut args = vec![ "--field-match-separator" , r"\x7F" ] ;
909+ args. extend( base) ;
910+ let expected = "\
911+ 1\x7F For the Doctor Watsons of this world, as opposed to the Sherlock
912+ " ;
913+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
914+
915+ // Test that an empty separator is OK.
916+ let mut args = vec![ "--field-match-separator" , r"" ] ;
917+ args. extend( base) ;
918+ let expected = "\
919+ 1For the Doctor Watsons of this world, as opposed to the Sherlock
920+ " ;
921+ eqnice!( expected, dir. command( ) . args( & args) . stdout( ) ) ;
922+ } ) ;
923+
831924rgtest ! ( no_context_sep, |dir: Dir , mut cmd: TestCommand | {
832925 dir. create( "test" , "foo\n ctx\n bar\n ctx\n foo\n ctx" ) ;
833926 cmd. args( & [ "-A1" , "--no-context-separator" , "foo" , "test" ] ) ;
0 commit comments