@@ -214,18 +214,23 @@ fn test_control_line_break() {
214
214
assert_width ! ( '\r' , None , None ) ;
215
215
assert_width ! ( '\n' , None , None ) ;
216
216
assert_width ! ( "\r " , 1 , 1 ) ;
217
- assert_width ! ( "\n " , 1 , 1 ) ;
218
- assert_width ! ( "\r \n " , 1 , 1 ) ;
217
+ // This is 0 due to #60
218
+ assert_width ! ( "\n " , 0 , 0 ) ;
219
+ assert_width ! ( "\r \n " , 0 , 0 ) ;
219
220
assert_width ! ( "\0 " , 1 , 1 ) ;
220
- assert_width ! ( "1\t 2\r \n 3\u{85} 4" , 7 , 7 ) ;
221
- assert_width ! ( "\r \u{FE0F} \n " , 2 , 2 ) ;
222
- assert_width ! ( "\r \u{200D} \n " , 2 , 2 ) ;
221
+ assert_width ! ( "1\t 2\r \n 3\u{85} 4" , 6 , 6 ) ;
222
+ assert_width ! ( "\r \u{FE0F} \n " , 1 , 1 ) ;
223
+ assert_width ! ( "\r \u{200D} \n " , 1 , 1 ) ;
223
224
}
224
225
225
226
#[ test]
226
227
fn char_str_consistent ( ) {
227
228
let mut s = String :: with_capacity ( 4 ) ;
228
229
for c in '\0' ..=char:: MAX {
230
+ // Newlines are special cased (#60)
231
+ if c == '\n' {
232
+ continue ;
233
+ }
229
234
s. clear ( ) ;
230
235
s. push ( c) ;
231
236
assert_eq ! ( c. width( ) . unwrap_or( 1 ) , s. width( ) ) ;
@@ -418,6 +423,10 @@ fn test_khmer_coeng() {
418
423
assert_width ! ( format!( "\u{17D2} {c}" ) , 0 , 0 ) ;
419
424
assert_width ! ( format!( "\u{17D2} \u{200D} \u{200D} {c}" ) , 0 , 0 ) ;
420
425
} else {
426
+ // Newlines are special cased (#60)
427
+ if c == '\n' {
428
+ continue ;
429
+ }
421
430
assert_width ! (
422
431
format!( "\u{17D2} {c}" ) ,
423
432
c. width( ) . unwrap_or( 1 ) ,
@@ -588,6 +597,11 @@ fn emoji_test_file() {
588
597
}
589
598
}
590
599
600
+ #[ test]
601
+ fn test_newline_zero_issue_60 ( ) {
602
+ assert_width ! ( "a\n a" , 2 , 2 ) ;
603
+ }
604
+
591
605
// Test traits are unsealed
592
606
593
607
#[ cfg( feature = "cjk" ) ]
0 commit comments