File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
src/tools/rust-analyzer/lib/smol_str/tests Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -209,14 +209,19 @@ fn test_from_char_iterator() {
209209 ( "사회과학원 어학연구소" , true ) ,
210210 // String containing diverse characters
211211 ( "表ポあA鷗ŒéB逍Üߪąñ丂㐀𠀀" , true ) ,
212- // String which has too many characters to even consider inlining
213- ( "☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺" , true ) ,
214212 ] ;
215213 for ( raw, is_heap) in & examples {
216214 let s: SmolStr = raw. chars ( ) . collect ( ) ;
217215 assert_eq ! ( s. as_str( ) , * raw) ;
218216 assert_eq ! ( s. is_heap_allocated( ) , * is_heap) ;
219217 }
218+ // String which has too many characters to even consider inlining: Chars::size_hint uses
219+ // (`len` + 3) / 4. With `len` = 89, this results in 23, so `from_iter` will immediately
220+ // heap allocate
221+ let raw: String = std:: iter:: repeat ( 'a' ) . take ( 22 * 4 + 1 ) . collect ( ) ;
222+ let s: SmolStr = raw. chars ( ) . collect ( ) ;
223+ assert_eq ! ( s. as_str( ) , raw) ;
224+ assert ! ( s. is_heap_allocated( ) ) ;
220225}
221226
222227#[ test]
You can’t perform that action at this time.
0 commit comments