@@ -2973,3 +2973,36 @@ def test_preserve_whitespace():
29732973 expected = "\n " .join (["h1 h2 h3" , "---- ---- ----" , "foo bar foo" ])
29742974 result = tabulate (test_table , table_headers )
29752975 assert_equal (expected , result )
2976+
2977+ def test_break_long_words ():
2978+ "Output: Default table output, with breakwords true."
2979+ table_headers = ["h1" , "h2" , "h3" ]
2980+ test_table = [[" foo1" , " bar2 " , "foo3" ]]
2981+
2982+ # Table is not wrapped
2983+ tabulate_module .BREAK_LONG_WORDS = False
2984+ expected = "h1 h2 h3\n ---- ---- ----\n foo1 bar2 foo3"
2985+ result = tabulate (test_table , table_headers , maxcolwidths = 3 )
2986+ assert_equal (expected , result )
2987+
2988+ # Table is wrapped on 2 letters
2989+ tabulate_module .BREAK_LONG_WORDS = True
2990+ expected = "h1 h2 h3\n ---- ---- ----\n f ba foo\n oo1 r2 3"
2991+ result = tabulate (test_table , table_headers , maxcolwidths = 3 )
2992+ assert_equal (expected , result )
2993+
2994+ def test_break_on_hyphens ():
2995+ "Output: Default table output, with break on hyphens true."
2996+ tabulate_module .BREAK_ON_HYPHENS = False
2997+ table_headers = ["h1" , "h2" , "h3" ]
2998+ test_table = [[" foo-bar" , " bar-bar " , "foo-foo" ]]
2999+ # Table is wrapped on 2 letters
3000+ expected = "h1 h2 h3\n ---- ---- -----\n foo bar- foo-f\n -bar bar oo"
3001+ result = tabulate (test_table , table_headers , maxcolwidths = 5 )
3002+ assert_equal (expected , result )
3003+
3004+ # Table is no longer wrapped
3005+ tabulate_module .BREAK_ON_HYPHENS = True
3006+ expected = "h1 h2 h3\n ---- ---- ----\n foo- bar- foo-\n bar bar foo"
3007+ result = tabulate (test_table , table_headers , maxcolwidths = 5 )
3008+ assert_equal (expected , result )
0 commit comments