@@ -46,23 +46,39 @@ describe("strings", function()
4646
4747 describe (" truncate" , function ()
4848 for _ , case in ipairs {
49- { args = { " abcde" , 6 }, expected = { single = " abcde" , double = " abcde" } },
50- { args = { " abcde" , 5 }, expected = { single = " abcde" , double = " abcde" } },
51- { args = { " abcde" , 4 }, expected = { single = " abc…" , double = " ab…" } },
52- { args = { " アイウエオ" , 11 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
53- { args = { " アイウエオ" , 10 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
54- { args = { " アイウエオ" , 9 }, expected = { single = " アイウエ…" , double = " アイウ…" } },
55- { args = { " アイウエオ" , 8 }, expected = { single = " アイウ…" , double = " アイウ…" } },
56- { args = { " ├─┤" , 7 }, expected = { single = " ├─┤" , double = " ├─┤" } },
57- { args = { " ├─┤" , 6 }, expected = { single = " ├─┤" , double = " ├─┤" } },
58- { args = { " ├─┤" , 5 }, expected = { single = " ├─┤" , double = " ├…" } },
59- { args = { " ├─┤" , 4 }, expected = { single = " ├─┤" , double = " ├…" } },
60- { args = { " ├─┤" , 3 }, expected = { single = " ├─┤" , double = " …" } },
61- { args = { " ├─┤" , 2 }, expected = { single = " ├…" , double = " …" } },
49+ -- truncations from the right
50+ { args = { " abcde" , 6 , nil , 1 }, expected = { single = " abcde" , double = " abcde" } },
51+ { args = { " abcde" , 5 , nil , 1 }, expected = { single = " abcde" , double = " abcde" } },
52+ { args = { " abcde" , 4 , nil , 1 }, expected = { single = " abc…" , double = " ab…" } },
53+ { args = { " アイウエオ" , 11 , nil , 1 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
54+ { args = { " アイウエオ" , 10 , nil , 1 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
55+ { args = { " アイウエオ" , 9 , nil , 1 }, expected = { single = " アイウエ…" , double = " アイウ…" } },
56+ { args = { " アイウエオ" , 8 , nil , 1 }, expected = { single = " アイウ…" , double = " アイウ…" } },
57+ { args = { " ├─┤" , 7 , nil , 1 }, expected = { single = " ├─┤" , double = " ├─┤" } },
58+ { args = { " ├─┤" , 6 , nil , 1 }, expected = { single = " ├─┤" , double = " ├─┤" } },
59+ { args = { " ├─┤" , 5 , nil , 1 }, expected = { single = " ├─┤" , double = " ├…" } },
60+ { args = { " ├─┤" , 4 , nil , 1 }, expected = { single = " ├─┤" , double = " ├…" } },
61+ { args = { " ├─┤" , 3 , nil , 1 }, expected = { single = " ├─┤" , double = " …" } },
62+ { args = { " ├─┤" , 2 , nil , 1 }, expected = { single = " ├…" , double = " …" } },
63+ -- truncations from the left
64+ { args = { " abcde" , 6 , nil , - 1 }, expected = { single = " abcde" , double = " abcde" } },
65+ { args = { " abcde" , 5 , nil , - 1 }, expected = { single = " abcde" , double = " abcde" } },
66+ { args = { " abcde" , 4 , nil , - 1 }, expected = { single = " …cde" , double = " …de" } },
67+ { args = { " アイウエオ" , 11 , nil , - 1 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
68+ { args = { " アイウエオ" , 10 , nil , - 1 }, expected = { single = " アイウエオ" , double = " アイウエオ" } },
69+ { args = { " アイウエオ" , 9 , nil , - 1 }, expected = { single = " …イウエオ" , double = " …ウエオ" } },
70+ { args = { " アイウエオ" , 8 , nil , - 1 }, expected = { single = " …ウエオ" , double = " …ウエオ" } },
71+ { args = { " ├─┤" , 7 , nil , - 1 }, expected = { single = " ├─┤" , double = " ├─┤" } },
72+ { args = { " ├─┤" , 6 , nil , - 1 }, expected = { single = " ├─┤" , double = " ├─┤" } },
73+ { args = { " ├─┤" , 5 , nil , - 1 }, expected = { single = " ├─┤" , double = " …┤" } },
74+ { args = { " ├─┤" , 4 , nil , - 1 }, expected = { single = " ├─┤" , double = " …┤" } },
75+ { args = { " ├─┤" , 3 , nil , - 1 }, expected = { single = " ├─┤" , double = " …" } },
76+ { args = { " ├─┤" , 2 , nil , - 1 }, expected = { single = " …┤" , double = " …" } },
6277 } do
6378 for _ , ambiwidth in ipairs { " single" , " double" } do
64- local msg = (" ambiwidth = %s, [%s, %d] -> %s" ):format (
79+ local msg = (" ambiwidth = %s, direction = %s, [%s, %d] -> %s" ):format (
6580 ambiwidth ,
81+ (case .args [4 ] > 0 ) and " right" or " left" ,
6682 case .args [1 ],
6783 case .args [2 ],
6884 case .expected [ambiwidth ]
0 commit comments