gofmt: format all remaining files with the go1.27 toolchain

The tree was formatted with an older gofmt; go1.27's gofmt additionally
wants: EOF exactly one newline (no trailing blank lines), imports sorted
alphabetically within a block, mixed-precedence binary expressions
re-spaced for grouping ((a+b)/c), single-field composite literals
un-aligned, adjacent one-line method signatures aligned, and one-line
bodies containing a compound statement expanded. Applied repo-wide
(31 files under internal/); pure formatting, no semantic changes —
build and the full test suite pass.
This commit is contained in:
gmp
2026-08-23 10:03:27 -04:00
parent 180fa966c8
commit 06b1444207
31 changed files with 279 additions and 247 deletions
+7 -7
View File
@@ -14,10 +14,10 @@ func TestWriteFailureTracking(t *testing.T) {
state := NewState()
filename := "test.txt"
state.Editor.Filename = filename
// Simulate a write failure
state.Editor.SetWriteFailed(filename, true)
if !state.Editor.WriteFailed() {
t.Errorf("Expected WriteFailed() to be true")
}
@@ -34,7 +34,7 @@ func TestWriteFailureTracking(t *testing.T) {
func TestAutoSave_RetryFails(t *testing.T) {
// Setup: New Logic, set mock FS to fail
l := NewLogic(nil, "/", func(string) {})
// Start a goroutine to drain frameChan to prevent deadlocks
go func() {
for range l.frameChan {
@@ -50,16 +50,16 @@ func TestAutoSave_RetryFails(t *testing.T) {
if !ok {
t.Fatal("mockFS is not a *mock.FileSystem")
}
mfs.SetWriteError(true)
mfs.SetWriteError(true)
// 1. Manually dispatch a write task
task := pool.NewWriteFileTask(filename, []byte("hello"), l.mockFS)
l.workerPool.Dispatch(task)
// 2. Manually process the result to trigger the failure state
res := <-l.workerPool.ResultChan()
l.handleWorkerResult(res)
// 3. Assert failure
if !l.state.Editor.WriteFailed() {
t.Errorf("Expected WriteFailed() to be true")
+1 -1
View File
@@ -25,7 +25,7 @@ func TestBackspace(t *testing.T) {
state := NewState()
TheState = state
state.Editor.Buffer = "Hello"
state.Editor.CursorPosition = 5
state.Editor.CursorPosition = 5
HandleBackspace() // Assuming we create this function
+3 -3
View File
@@ -189,9 +189,9 @@ func TestLargeFileChunkBoundary(t *testing.T) {
// (The old fixed-slot model treated each chunk as an independent buffer and
// did NOT shift later chunks; that was the bug this design replaces.)
expectedStr := string(initialContent)
expectedStr = expectedStr[:65000] + "CHUNK1" + expectedStr[65000:] // insert 1 @65000
expectedStr = expectedStr[:65535] + "BOUNDARY" + expectedStr[65535:] // insert 2 @65535
expectedStr = expectedStr[:262000] + "CHUNK3" + expectedStr[262000:] // insert 3 @262000
expectedStr = expectedStr[:65000] + "CHUNK1" + expectedStr[65000:] // insert 1 @65000
expectedStr = expectedStr[:65535] + "BOUNDARY" + expectedStr[65535:] // insert 2 @65535
expectedStr = expectedStr[:262000] + "CHUNK3" + expectedStr[262000:] // insert 3 @262000
expected := []byte(expectedStr)
if len(savedContent) != len(expected) {
+9 -9
View File
@@ -1,26 +1,26 @@
package editor
import (
"testing"
"pad/internal/ui"
"testing"
)
func TestEditorLayout_Filename(t *testing.T) {
// Setup: Reset state
TheState = NewState()
// Set a filename
expectedFilename := "test.txt"
TheState.Editor.Filename = expectedFilename
// Run layout
screenWidth := ui.Dp(400)
screenHeight := ui.Dp(800)
elements := EditorLayout(screenWidth, screenHeight, false)
// Find top bar (assuming it's the first container element)
topBar := elements[0].(ui.Container)
// Find the filename label in the top bar (the back icon precedes it).
var filenameLabel ui.Label
for _, c := range topBar.Children {
@@ -37,18 +37,18 @@ func TestEditorLayout_Filename(t *testing.T) {
func TestEditorLayout_DefaultFilename(t *testing.T) {
// Setup: Reset state
TheState = NewState()
// Filename is empty
TheState.Editor.Filename = ""
// Run layout
screenWidth := ui.Dp(400)
screenHeight := ui.Dp(800)
elements := EditorLayout(screenWidth, screenHeight, false)
// Find top bar (assuming it's the first container element)
topBar := elements[0].(ui.Container)
// Find the filename label in the top bar (the back icon precedes it).
var filenameLabel ui.Label
for _, c := range topBar.Children {
+2 -2
View File
@@ -40,8 +40,8 @@ func newChunkedState(t *testing.T, content string, chunkSize int) *State {
func TestRuneIndexToByteStr(t *testing.T) {
cases := []struct {
s string
n int
s string
n int
want int
}{
{"", 0, 0},
+39 -39
View File
@@ -20,45 +20,45 @@ func absFloat(x ui.Dp) float64 {
func TestFragmentStartYCalculation(t *testing.T) {
// Setup test scenario
lineHeight := ui.Dp(16.8) // 14 * 1.2
// Test case 1: Scroll to line 0 (top)
scrollOffset := ui.Dp(0)
expectedVisualLine := 0
expectedFragmentStartY := ui.Dp(0)
visualLine := int(scrollOffset / lineHeight)
fragmentStartY := ui.Dp(visualLine) * lineHeight
if visualLine != expectedVisualLine {
t.Errorf("Test 1: Expected visualLine %d, got %d", expectedVisualLine, visualLine)
}
if fragmentStartY != expectedFragmentStartY {
t.Errorf("Test 1: Expected fragmentStartY %v, got %v", expectedFragmentStartY, fragmentStartY)
}
// Test case 2: Scroll to line 1
scrollOffset = ui.Dp(16.8)
expectedVisualLine = 1
expectedFragmentStartY = ui.Dp(16.8)
visualLine = int(scrollOffset / lineHeight)
fragmentStartY = ui.Dp(visualLine) * lineHeight
if visualLine != expectedVisualLine {
t.Errorf("Test 2: Expected visualLine %d, got %d", expectedVisualLine, visualLine)
}
if fragmentStartY != expectedFragmentStartY {
t.Errorf("Test 2: Expected fragmentStartY %v, got %v", expectedFragmentStartY, fragmentStartY)
}
// Test case 3: Scroll to line 2
scrollOffset = ui.Dp(33.6)
expectedVisualLine = 2
expectedFragmentStartY = ui.Dp(33.6)
visualLine = int(scrollOffset / lineHeight)
fragmentStartY = ui.Dp(visualLine) * lineHeight
if visualLine != expectedVisualLine {
t.Errorf("Test 3: Expected visualLine %d, got %d", expectedVisualLine, visualLine)
}
@@ -77,24 +77,24 @@ func TestVisualLineIndexCreation(t *testing.T) {
Advance: []ui.Dp{10, 10, 10, 10},
LineHeight: ui.Dp(16.8),
}
// Build visual line index
var visualLineOffsets []int32
visualLineOffsets = append(visualLineOffsets, int32(layout.ByteOffsets[0]))
for i := 1; i < len(layout.Y); i++ {
if layout.Y[i] != layout.Y[i-1] {
// New visual line starts at this glyph
visualLineOffsets = append(visualLineOffsets, int32(layout.ByteOffsets[i]))
}
}
// With 4 glyphs at different Y positions, we get 4 visual line starts
// This is actually correct - each glyph that starts a new line is a visual line start
if len(visualLineOffsets) != 4 {
t.Errorf("Expected 4 visual line starts, got %d", len(visualLineOffsets))
}
// Check byte offsets - should match all the byte offsets where Y changes
expectedOffsets := []int32{0, 7, 14, 21}
for i := 0; i < len(visualLineOffsets) && i < len(expectedOffsets); i++ {
@@ -107,14 +107,14 @@ func TestVisualLineIndexCreation(t *testing.T) {
// TestWordWrapFragmentStartY tests fragmentStartY calculation with word wrap enabled
func TestWordWrapFragmentStartY(t *testing.T) {
lineHeight := ui.Dp(16.8) // 14 * 1.2
// Test case: Word wrap enabled, scroll to visual line 5
// With word wrap, visual lines don't correspond 1:1 with logical lines
wordWrap := true
_ = wordWrap // Mark as used for this test
_ = wordWrap // Mark as used for this test
scrollOffset := ui.Dp(5 * float64(lineHeight)) // Scroll to visual line 5
visualLine := int(scrollOffset / lineHeight)
// With word wrap, we should use a different estimation
// because one logical line can span multiple visual lines
if wordWrap {
@@ -122,7 +122,7 @@ func TestWordWrapFragmentStartY(t *testing.T) {
// to avoid skipping wrapped lines
estimatedBytesPerVisualLine := 10 // Very small step
expectedStartByteOffset := visualLine * estimatedBytesPerVisualLine
if expectedStartByteOffset != 50 { // 5 * 10
t.Errorf("Word wrap case: expected start byte offset %d, got %d", 50, expectedStartByteOffset)
}
@@ -130,12 +130,12 @@ func TestWordWrapFragmentStartY(t *testing.T) {
// Without word wrap, use bytes per logical line estimate
estimatedBytesPerLogicalLine := 50
expectedStartByteOffset := visualLine * estimatedBytesPerLogicalLine
if expectedStartByteOffset != 250 { // 5 * 50
t.Errorf("No word wrap case: expected start byte offset %d, got %d", 250, expectedStartByteOffset)
}
}
// fragmentStartY should always be visualLine * lineHeight
expectedFragmentStartY := ui.Dp(visualLine) * lineHeight
if expectedFragmentStartY != ui.Dp(5*16.8) {
@@ -150,31 +150,31 @@ func TestByteOffsetAndYFromScroll(t *testing.T) {
visualLineIndex := &types.VisualLineIndex{
Offsets: []int32{0, 7, 14, 21}, // 4 lines
}
layout := ui.GlyphLayout{
ByteOffsets: []int{0, 7, 14, 21},
X: []ui.Dp{0, 0, 0, 0},
Y: []ui.Dp{0, 16.8, 33.6, 50.4},
Advance: []ui.Dp{10, 10, 10, 10},
LineHeight: lineHeight,
ByteOffsets: []int{0, 7, 14, 21},
X: []ui.Dp{0, 0, 0, 0},
Y: []ui.Dp{0, 16.8, 33.6, 50.4},
Advance: []ui.Dp{10, 10, 10, 10},
LineHeight: lineHeight,
VisualLineIndex: visualLineIndex,
}
// Test scrolling to different positions
testCases := []struct {
scrollOffset ui.Dp
expectedByte int
expectedY ui.Dp
scrollOffset ui.Dp
expectedByte int
expectedY ui.Dp
}{
{ui.Dp(0), 0, ui.Dp(0)}, // Top of document
{ui.Dp(16.8), 7, ui.Dp(16.8)}, // Start of line 1
{ui.Dp(33.6), 14, ui.Dp(33.6)}, // Start of line 2
{ui.Dp(50.4), 21, ui.Dp(50.4)}, // Start of line 3
{ui.Dp(0), 0, ui.Dp(0)}, // Top of document
{ui.Dp(16.8), 7, ui.Dp(16.8)}, // Start of line 1
{ui.Dp(33.6), 14, ui.Dp(33.6)}, // Start of line 2
{ui.Dp(50.4), 21, ui.Dp(50.4)}, // Start of line 3
}
for _, tc := range testCases {
byteOffset, y := ByteOffsetAndYFromScrollWithLayout(tc.scrollOffset, layout)
if byteOffset != tc.expectedByte {
t.Errorf("Scroll %v: expected byte offset %d, got %d", tc.scrollOffset, tc.expectedByte, byteOffset)
}
@@ -191,17 +191,17 @@ func ByteOffsetAndYFromScrollWithLayout(scrollOffset ui.Dp, layout ui.GlyphLayou
if lineHeight == 0 {
lineHeight = editor.EditorLineHeight()
}
// Calculate which visual line should be at the given scroll offset
visualLine := int(scrollOffset / lineHeight)
// If we have a visual line index, use it for accurate byte offset
if layout.VisualLineIndex != nil && visualLine < len(layout.VisualLineIndex.Offsets) {
byteOffset := int(layout.VisualLineIndex.Offsets[visualLine])
lineTop := ui.Dp(visualLine) * lineHeight
return byteOffset, lineTop
}
// Fallback to the original logic using layout.Y values
// 1. Find the index of the line whose top is <= scrollOffset
idx := sort.Search(len(layout.Y), func(i int) bool {
@@ -226,4 +226,4 @@ func ByteOffsetAndYFromScrollWithLayout(scrollOffset ui.Dp, layout ui.GlyphLayou
lineTop := layout.Y[lineStartIdx] - lineHeight
return layout.ByteOffsets[lineStartIdx], lineTop
}
}
-1
View File
@@ -202,4 +202,3 @@ func byteOffsetOfLine(content string, i int) int {
}
return o
}