@@ -1170,6 +1170,68 @@ mod test {
11701170 ) ;
11711171 }
11721172
1173+ #[ test]
1174+ fn test_select_on_matches_crlf ( ) {
1175+ let r = Rope :: from_str ( "This\r \n String\r \n \r \n contains multiple\r \n lines" ) ;
1176+ let s = r. slice ( ..) ;
1177+
1178+ let start_of_line = rope:: RegexBuilder :: new ( )
1179+ . syntax ( rope:: Config :: new ( ) . multi_line ( true ) . crlf ( true ) )
1180+ . build ( r"^" )
1181+ . unwrap ( ) ;
1182+ let end_of_line = rope:: RegexBuilder :: new ( )
1183+ . syntax ( rope:: Config :: new ( ) . multi_line ( true ) . crlf ( true ) )
1184+ . build ( r"$" )
1185+ . unwrap ( ) ;
1186+
1187+ // line without ending
1188+ assert_eq ! (
1189+ select_on_matches( s, & Selection :: single( 0 , 4 ) , & start_of_line) ,
1190+ Some ( Selection :: single( 0 , 0 ) )
1191+ ) ;
1192+ assert_eq ! (
1193+ select_on_matches( s, & Selection :: single( 0 , 4 ) , & end_of_line) ,
1194+ None
1195+ ) ;
1196+ // line with ending
1197+ assert_eq ! (
1198+ select_on_matches( s, & Selection :: single( 0 , 5 ) , & start_of_line) ,
1199+ Some ( Selection :: single( 0 , 0 ) )
1200+ ) ;
1201+ assert_eq ! (
1202+ select_on_matches( s, & Selection :: single( 0 , 5 ) , & end_of_line) ,
1203+ Some ( Selection :: single( 4 , 4 ) )
1204+ ) ;
1205+ // line with start of next line
1206+ assert_eq ! (
1207+ select_on_matches( s, & Selection :: single( 0 , 7 ) , & start_of_line) ,
1208+ Some ( Selection :: new(
1209+ smallvec![ Range :: point( 0 ) , Range :: point( 6 ) ] ,
1210+ 0
1211+ ) )
1212+ ) ;
1213+ assert_eq ! (
1214+ select_on_matches( s, & Selection :: single( 0 , 6 ) , & end_of_line) ,
1215+ Some ( Selection :: single( 4 , 4 ) )
1216+ ) ;
1217+
1218+ // multiple lines
1219+ assert_eq ! (
1220+ select_on_matches(
1221+ s,
1222+ & Selection :: single( 0 , s. len_chars( ) ) ,
1223+ & rope:: RegexBuilder :: new( )
1224+ . syntax( rope:: Config :: new( ) . multi_line( true ) . crlf( true ) )
1225+ . build( r"^[a-z ]*$" )
1226+ . unwrap( )
1227+ ) ,
1228+ Some ( Selection :: new(
1229+ smallvec![ Range :: point( 14 ) , Range :: new( 16 , 33 ) , Range :: new( 35 , 40 ) ] ,
1230+ 0
1231+ ) )
1232+ ) ;
1233+ }
1234+
11731235 #[ test]
11741236 fn test_line_range ( ) {
11751237 let r = Rope :: from_str ( "\r \n Hi\r \n there!" ) ;
0 commit comments