handle multiple non-wrapped long nodes following each other

This commit is contained in:
Arpad Ryszka 2020-11-10 01:33:46 +01:00
parent 26109c1941
commit d46324fe78
2 changed files with 28 additions and 8 deletions

View File

@ -115,23 +115,38 @@ func wrapNode(t, c0, c1 int, n node) node {
n.wrap = true
cc0, cc1 := c0, c1
for i, p := range n.parts {
lastWrapperIndex := -1
var trackBack bool
for i := 0; i < len(n.parts); i++ {
p := n.parts[i]
switch part := p.(type) {
case node:
part = wrapNode(t, cc0, cc1, part)
n.parts[i] = part
if part.wrap {
cc0 -= part.wrapLen.last
cc1 -= part.wrapLen.last
// This is an approximation: sometimes part.fullWrap.first is applied here,
// but usually those are the same.
cc0 -= part.wrapLen.first
cc1 -= part.wrapLen.first
} else {
cc0 -= part.len
cc1 -= part.len
}
if !trackBack && cc1 < 0 {
cc0 = 0
cc1 = 0
i = lastWrapperIndex
trackBack = true
}
case wrapper:
if len(part.items) > 0 {
cc0, cc1 = c0, c1
if len(part.items) == 0 {
continue
}
cc0, cc1 = c0, c1
trackBack = false
lastWrapperIndex = i
switch part.mode {
case line:
c0, c1 = c0-t, c1-t

View File

@ -910,11 +910,13 @@ func TestSortedMap(t *testing.T) {
}
func TestBytes(t *testing.T) {
const expectNotWrapped = `[]{00 01 02 03 04 05 06 07 08 09 0a 0b}`
const expectWrapped = `[]{
const (
expectNotWrapped = `[]{00 01 02 03 04 05 06 07 08 09 0a 0b}`
expectWrapped = `[]{
00 01 02 03 04 05
06 07 08 09 0a 0b
}`
)
b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
t.Run("not wrapped", func(t *testing.T) {
@ -940,7 +942,10 @@ func TestBytes(t *testing.T) {
}
func TestNonWrapperNodes(t *testing.T) {
const expect = `map[struct{foo int; bar int}]struct{
const expect = `map[struct{
foo int
bar int
}]struct{
foo int
bar int
}{}`