@@ -1078,19 +1078,47 @@ def test_first_word_too_long_but_placeholder_fits(self):
10781078
10791079
10801080class WideCharacterTestCase (BaseTestCase ):
1081- def test_wide_character (self ):
1082- def text_len (text ):
1083- n = 0
1084- for c in text :
1085- if unicodedata .east_asian_width (c ) in {'F' , 'W' }:
1086- n += 2
1087- else :
1088- n += 1
1089- return n
1081+ def text_len (self , text ):
1082+ n = 0
1083+ for c in text :
1084+ if unicodedata .east_asian_width (c ) in {'F' , 'W' }:
1085+ n += 2
1086+ else :
1087+ n += 1
1088+ return n
10901089
1090+ def check_shorten (self , text , width , expect , ** kwargs ):
1091+ result = shorten (text , width , ** kwargs )
1092+ self .check (result , expect )
1093+
1094+ def test_wrap (self ):
10911095 text = "123 π§"
1092- expected = ["123" , "π§" ]
1093- self .check_wrap (text , 5 , expected , text_len = text_len )
1096+ self .check_wrap (text , 5 , ["123 π§" ])
1097+ self .check_wrap (text , 5 , ["123" , "π§" ], text_len = self .text_len )
1098+
1099+ def test_wrap_initial_indent (self ):
1100+ text = "12 12"
1101+ self .check_wrap (text , 6 , ["π§12 12" ], initial_indent = "π§" )
1102+ self .check_wrap (text , 6 , ["π§12" , "12" ], initial_indent = "π§" ,
1103+ text_len = self .text_len )
1104+
1105+ def test_wrap_subsequent_indent (self ):
1106+ text = "12 12 12 12"
1107+ self .check_wrap (text , 6 , ["12 12" , "π§12 12" ], subsequent_indent = "π§" )
1108+ self .check_wrap (text , 6 , ["12 12" , "π§12" , "π§12" ],
1109+ subsequent_indent = "π§" , text_len = self .text_len )
1110+
1111+ def test_shorten (self ):
1112+ text = "123 1234π§"
1113+ expected = "123 [...]"
1114+ self .check_shorten (text , 9 , "123 1234π§" )
1115+ self .check_shorten (text , 9 , "123 [...]" , text_len = self .text_len )
1116+
1117+ def test_shorten_placeholder (self ):
1118+ text = "123 1 123"
1119+ self .check_shorten (text , 7 , "123 1 π§" , placeholder = " π§" )
1120+ self .check_shorten (text , 7 , "123 π§" , placeholder = " π§" ,
1121+ text_len = self .text_len )
10941122
10951123
10961124if __name__ == '__main__' :
0 commit comments