@@ -92,15 +92,41 @@ pub const SEVERITY_MISSING: u8 = 0xff;
92
92
93
93
#[ test]
94
94
fn test_structured_data_display ( ) {
95
- let expected_string = r#"[someid a="b" c="123456"]"# ;
95
+ let expected_string = r#"[someid a="a string" b="123456" c="true" d="123.456" e="-123456" f]"# ;
96
+ let expected_debug = r#"StructuredData { sd_id: Some("someid"), pairs: [("a", String("a string")), ("b", U64(123456)), ("c", Bool(true)), ("d", F64(123.456)), ("e", I64(-123456)), ("_f", Null)] }"# ;
96
97
let data = StructuredData {
97
98
sd_id : Some ( "someid" . to_string ( ) ) ,
98
99
pairs : vec ! [
99
- ( "a" . to_string( ) , SDValue :: String ( "b" . to_string( ) ) ) ,
100
- ( "c" . to_string( ) , SDValue :: U64 ( 123456 ) ) ,
100
+ ( "a" . to_string( ) , SDValue :: String ( "a string" . to_string( ) ) ) ,
101
+ ( "b" . to_string( ) , SDValue :: U64 ( 123456 ) ) ,
102
+ ( "c" . to_string( ) , SDValue :: Bool ( true ) ) ,
103
+ ( "d" . to_string( ) , SDValue :: F64 ( 123.456 ) ) ,
104
+ ( "e" . to_string( ) , SDValue :: I64 ( -123456 ) ) ,
105
+ ( "_f" . to_string( ) , SDValue :: Null ) ,
101
106
] ,
102
107
} ;
103
108
109
+ // Verify both debug and string conversion
104
110
let result = data. to_string ( ) ;
111
+ assert_eq ! ( format!( "{:?}" , data) , expected_debug) ;
105
112
assert_eq ! ( result, expected_string) ;
106
113
}
114
+
115
+ #[ test]
116
+ fn test_record_display ( ) {
117
+ let expected_debug = r#"Record { ts: 123.456, hostname: "hostname", facility: Some(3), severity: Some(8), appname: Some("app"), procid: Some("123"), msgid: None, msg: Some("msg"), full_msg: None, sd: None }"# ;
118
+ let record = Record {
119
+ ts : 123.456 ,
120
+ hostname : "hostname" . to_string ( ) ,
121
+ facility : Some ( 3 ) ,
122
+ severity : Some ( 8 ) ,
123
+ appname : Some ( "app" . to_string ( ) ) ,
124
+ procid : Some ( "123" . to_string ( ) ) ,
125
+ msgid : None ,
126
+ msg : Some ( "msg" . to_string ( ) ) ,
127
+ full_msg : None ,
128
+ sd : None ,
129
+ } ;
130
+
131
+ assert_eq ! ( format!( "{:?}" , record) , expected_debug) ;
132
+ }
0 commit comments