Commit c051fe36 authored by Anthony Fok's avatar Anthony Fok

Merge tag 'upstream/0.0_git20150905.0.bb797dc4'

Upstream version 0.0~git20150905.0.bb797dc4
parents 3fe0a18f bb797dc4
......@@ -36,7 +36,7 @@ version.go
windows.go
`[1:]
var tests = []struct{
var tests = []struct {
wid int
flag uint
src string
......
......@@ -31,7 +31,7 @@ func WrapBytes(b []byte, lim int) []byte {
// WrapWords is the low-level line-breaking algorithm, useful if you need more
// control over the details of the text wrapping process. For most uses, either
// Wrap or WrapBytes will be sufficient and more convenient.
// Wrap or WrapBytes will be sufficient and more convenient.
//
// WrapWords splits a list of words into lines with minimal "raggedness",
// treating each byte as one unit, accounting for spc units between adjacent
......@@ -58,7 +58,7 @@ func WrapWords(words [][]byte, spc, lim, pen int) [][][]byte {
cost[i] = math.MaxInt32
}
for i := n - 1; i >= 0; i-- {
if length[i][n-1] <= lim {
if length[i][n-1] <= lim || i == n-1 {
cost[i] = 0
nbrk[i] = n
} else {
......
......@@ -42,3 +42,21 @@ func TestWrapOneLine(t *testing.T) {
t.Fail()
}
}
func TestWrapBug1(t *testing.T) {
cases := []struct {
limit int
text string
want string
}{
{4, "aaaaa", "aaaaa"},
{4, "a aaaaa", "a\naaaaa"},
}
for _, test := range cases {
got := Wrap(test.text, test.limit)
if got != test.want {
t.Errorf("Wrap(%q, %d) = %q want %q", test.text, test.limit, got, test.want)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment