@@ -453,3 +453,106 @@ mod i16_key {
453
453
assert_eq ! ( json, input) ;
454
454
}
455
455
}
456
+
457
+ mod char_key {
458
+ use super :: * ;
459
+
460
+ type Map = super :: Map < char > ;
461
+ type Document = super :: Document < char > ;
462
+
463
+ fn key ( ) -> char {
464
+ 'k'
465
+ }
466
+
467
+ #[ test]
468
+ fn to_string_value ( ) {
469
+ let expected = str![ [ r#"{ k = "value" }"# ] ] ;
470
+ let input = [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ;
471
+ let toml = t ! ( crate :: to_string_value( & input) ) ;
472
+ assert_data_eq ! ( & toml, expected) ;
473
+ let roundtrip = t ! ( crate :: value_from_str:: <Map >( & toml) ) ;
474
+ assert_eq ! ( roundtrip, input) ;
475
+ let json = json_from_toml_value_str :: < Map > ( & toml) ;
476
+ assert_eq ! ( json, input) ;
477
+ }
478
+
479
+ #[ test]
480
+ fn to_string ( ) {
481
+ let expected = str![ [ r#"
482
+ k = "value"
483
+
484
+ "# ] ] ;
485
+ let input = [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ;
486
+ let toml = t ! ( crate :: to_string( & input) ) ;
487
+ assert_data_eq ! ( & toml, expected) ;
488
+ let roundtrip = t ! ( crate :: from_str:: <Map >( & toml) ) ;
489
+ assert_eq ! ( roundtrip, input) ;
490
+ let json = json_from_toml_str :: < Map > ( & toml) ;
491
+ assert_eq ! ( json, input) ;
492
+ }
493
+
494
+ #[ test]
495
+ fn to_string_pretty ( ) {
496
+ let expected = str![ [ r#"
497
+ k = "value"
498
+
499
+ "# ] ] ;
500
+ let input = [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ;
501
+ let toml = t ! ( crate :: to_string_pretty( & input) ) ;
502
+ assert_data_eq ! ( & toml, expected) ;
503
+ let roundtrip = t ! ( crate :: from_str:: <Map >( & toml) ) ;
504
+ assert_eq ! ( roundtrip, input) ;
505
+ let json = json_from_toml_str :: < Map > ( & toml) ;
506
+ assert_eq ! ( json, input) ;
507
+ }
508
+
509
+ #[ test]
510
+ fn nested_to_string_value ( ) {
511
+ let expected = str![ [ r#"{ map = { k = "value" } }"# ] ] ;
512
+ let input = Document {
513
+ map : [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ,
514
+ } ;
515
+ let toml = t ! ( crate :: to_string_value( & input) ) ;
516
+ assert_data_eq ! ( & toml, expected) ;
517
+ let roundtrip = t ! ( crate :: value_from_str:: <Document >( & toml) ) ;
518
+ assert_eq ! ( roundtrip, input) ;
519
+ let json = json_from_toml_value_str :: < Document > ( & toml) ;
520
+ assert_eq ! ( json, input) ;
521
+ }
522
+
523
+ #[ test]
524
+ fn nested_to_string ( ) {
525
+ let expected = str![ [ r#"
526
+ [map]
527
+ k = "value"
528
+
529
+ "# ] ] ;
530
+ let input = Document {
531
+ map : [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ,
532
+ } ;
533
+ let toml = t ! ( crate :: to_string( & input) ) ;
534
+ assert_data_eq ! ( & toml, expected) ;
535
+ let roundtrip = t ! ( crate :: from_str:: <Document >( & toml) ) ;
536
+ assert_eq ! ( roundtrip, input) ;
537
+ let json = json_from_toml_str :: < Document > ( & toml) ;
538
+ assert_eq ! ( json, input) ;
539
+ }
540
+
541
+ #[ test]
542
+ fn nested_to_string_pretty ( ) {
543
+ let expected = str![ [ r#"
544
+ [map]
545
+ k = "value"
546
+
547
+ "# ] ] ;
548
+ let input = Document {
549
+ map : [ ( key ( ) , "value" . to_owned ( ) ) ] . into_iter ( ) . collect :: < Map > ( ) ,
550
+ } ;
551
+ let toml = t ! ( crate :: to_string_pretty( & input) ) ;
552
+ assert_data_eq ! ( & toml, expected) ;
553
+ let roundtrip = t ! ( crate :: from_str:: <Document >( & toml) ) ;
554
+ assert_eq ! ( roundtrip, input) ;
555
+ let json = json_from_toml_str :: < Document > ( & toml) ;
556
+ assert_eq ! ( json, input) ;
557
+ }
558
+ }
0 commit comments