handle multiple non-wrapped long nodes following each other
This commit is contained in:
parent
26109c1941
commit
d46324fe78
25
fprint.go
25
fprint.go
@ -115,23 +115,38 @@ func wrapNode(t, c0, c1 int, n node) node {
|
|||||||
|
|
||||||
n.wrap = true
|
n.wrap = true
|
||||||
cc0, cc1 := c0, c1
|
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) {
|
switch part := p.(type) {
|
||||||
case node:
|
case node:
|
||||||
part = wrapNode(t, cc0, cc1, part)
|
part = wrapNode(t, cc0, cc1, part)
|
||||||
n.parts[i] = part
|
n.parts[i] = part
|
||||||
if part.wrap {
|
if part.wrap {
|
||||||
cc0 -= part.wrapLen.last
|
// This is an approximation: sometimes part.fullWrap.first is applied here,
|
||||||
cc1 -= part.wrapLen.last
|
// but usually those are the same.
|
||||||
|
cc0 -= part.wrapLen.first
|
||||||
|
cc1 -= part.wrapLen.first
|
||||||
} else {
|
} else {
|
||||||
cc0 -= part.len
|
cc0 -= part.len
|
||||||
cc1 -= part.len
|
cc1 -= part.len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !trackBack && cc1 < 0 {
|
||||||
|
cc0 = 0
|
||||||
|
cc1 = 0
|
||||||
|
i = lastWrapperIndex
|
||||||
|
trackBack = true
|
||||||
|
}
|
||||||
case wrapper:
|
case wrapper:
|
||||||
if len(part.items) > 0 {
|
if len(part.items) == 0 {
|
||||||
cc0, cc1 = c0, c1
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cc0, cc1 = c0, c1
|
||||||
|
trackBack = false
|
||||||
|
lastWrapperIndex = i
|
||||||
switch part.mode {
|
switch part.mode {
|
||||||
case line:
|
case line:
|
||||||
c0, c1 = c0-t, c1-t
|
c0, c1 = c0-t, c1-t
|
||||||
|
@ -910,11 +910,13 @@ func TestSortedMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBytes(t *testing.T) {
|
func TestBytes(t *testing.T) {
|
||||||
const expectNotWrapped = `[]{00 01 02 03 04 05 06 07 08 09 0a 0b}`
|
const (
|
||||||
const expectWrapped = `[]{
|
expectNotWrapped = `[]{00 01 02 03 04 05 06 07 08 09 0a 0b}`
|
||||||
|
expectWrapped = `[]{
|
||||||
00 01 02 03 04 05
|
00 01 02 03 04 05
|
||||||
06 07 08 09 0a 0b
|
06 07 08 09 0a 0b
|
||||||
}`
|
}`
|
||||||
|
)
|
||||||
|
|
||||||
b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||||
t.Run("not wrapped", func(t *testing.T) {
|
t.Run("not wrapped", func(t *testing.T) {
|
||||||
@ -940,7 +942,10 @@ func TestBytes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNonWrapperNodes(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
|
foo int
|
||||||
bar int
|
bar int
|
||||||
}{}`
|
}{}`
|
||||||
|
Loading…
Reference in New Issue
Block a user