@@ -519,7 +519,7 @@ fn test_bytes_or_string() {
519
519
#[ test]
520
520
fn string_with_separator ( ) {
521
521
use serde_with:: {
522
- formats:: { CommaSeparator , SpaceSeparator } ,
522
+ formats:: { CommaSeparator , DosLineSeparator , SpaceSeparator , UnixLineSeparator } ,
523
523
StringWithSeparator ,
524
524
} ;
525
525
@@ -529,26 +529,44 @@ fn string_with_separator() {
529
529
#[ serde_as( as = "StringWithSeparator::<SpaceSeparator, String>" ) ]
530
530
tags : Vec < String > ,
531
531
#[ serde_as( as = "StringWithSeparator::<CommaSeparator, String>" ) ]
532
- // more_tags: Vec<String>,
533
532
more_tags : BTreeSet < String > ,
533
+ #[ serde_as( as = "StringWithSeparator::<UnixLineSeparator, String>" ) ]
534
+ lf_tags : BTreeSet < String > ,
535
+ #[ serde_as( as = "StringWithSeparator::<DosLineSeparator, String>" ) ]
536
+ crlf_tags : BTreeSet < String > ,
534
537
}
535
538
536
539
let v: A = serde_json:: from_str (
537
540
r##"{
538
541
"tags": "#hello #world",
539
- "more_tags": "foo,bar,bar"
542
+ "more_tags": "foo,bar,bar",
543
+ "lf_tags": "foo\nbar\nbar",
544
+ "crlf_tags": "foo\r\nbar\r\nbar"
540
545
}"## ,
541
546
)
542
547
. unwrap ( ) ;
543
548
assert_eq ! ( vec![ "#hello" , "#world" ] , v. tags) ;
544
- assert_eq ! ( 2 , v. more_tags. len( ) ) ;
549
+ assert_eq ! (
550
+ BTreeSet :: from( [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
551
+ v. more_tags
552
+ ) ;
553
+ assert_eq ! (
554
+ BTreeSet :: from( [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
555
+ v. lf_tags
556
+ ) ;
557
+ assert_eq ! (
558
+ BTreeSet :: from( [ "foo" . to_string( ) , "bar" . to_string( ) ] ) ,
559
+ v. crlf_tags
560
+ ) ;
545
561
546
562
let x = A {
547
563
tags : vec ! [ "1" . to_string( ) , "2" . to_string( ) , "3" . to_string( ) ] ,
548
564
more_tags : BTreeSet :: default ( ) ,
565
+ lf_tags : BTreeSet :: default ( ) ,
566
+ crlf_tags : BTreeSet :: default ( ) ,
549
567
} ;
550
568
assert_eq ! (
551
- r#"{"tags":"1 2 3","more_tags":""}"# ,
569
+ r#"{"tags":"1 2 3","more_tags":"","lf_tags":"","crlf_tags":"" }"# ,
552
570
serde_json:: to_string( & x) . unwrap( )
553
571
) ;
554
572
}
0 commit comments