File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,10 @@ fn error_to_event<E: ReconcilerError>(err: &E) -> Event {
28
28
}
29
29
}
30
30
} ;
31
+ dbg ! ( full_msg. len( ) ) ;
31
32
message:: truncate_with_ellipsis ( & mut full_msg, 1024 ) ;
33
+ dbg ! ( full_msg. len( ) ) ;
34
+ assert ! ( full_msg. len( ) <= 1024 ) ;
32
35
Event {
33
36
type_ : EventType :: Warning ,
34
37
reason : err. category ( ) . to_string ( ) ,
@@ -87,11 +90,13 @@ mod message {
87
90
const ELLIPSIS_LEN : usize = ELLIPSIS . len_utf8 ( ) ;
88
91
let len = msg. len ( ) ;
89
92
if len > max_len {
90
- msg. truncate ( find_start_of_char ( msg, len. saturating_sub ( ELLIPSIS_LEN ) ) ) ;
93
+ let start_of_trunc_char = find_start_of_char ( msg, max_len. saturating_sub ( ELLIPSIS_LEN ) ) ;
94
+ msg. truncate ( start_of_trunc_char) ;
91
95
if ELLIPSIS_LEN <= max_len {
92
96
msg. push ( ELLIPSIS ) ;
93
97
}
94
98
}
99
+ debug_assert ! ( msg. len( ) <= max_len) ;
95
100
}
96
101
97
102
fn find_start_of_char ( s : & str , mut pos : usize ) -> usize {
@@ -120,7 +125,10 @@ mod message {
120
125
fn truncate_should_ellipsize_large_string ( ) {
121
126
let mut x = "hello" . to_string ( ) ;
122
127
truncate_with_ellipsis ( & mut x, 4 ) ;
123
- assert_eq ! ( & x, "he…" ) ;
128
+ assert_eq ! ( & x, "h…" ) ;
129
+ x = "hello, this is a much larger string" . to_string ( ) ;
130
+ truncate_with_ellipsis ( & mut x, 4 ) ;
131
+ assert_eq ! ( & x, "h…" ) ;
124
132
}
125
133
126
134
#[ test]
You can’t perform that action at this time.
0 commit comments