Files
8bitMyGoUI/data/treevalue_test.go
T
ZacharyZhang-NY 51af14709d Add code components 366-385; ScrollArea Follow, editor sync
A terminal with history, a Go-colored code block, a log viewer that
follows, a hex viewer, a memory map, a JSON tree, a line diff, a GAME
OVER crash screen, an FPS meter, profiler bars, breakpoints,
variables, command history, a shortcut list, a debug grid, a pixel
editor that exports string art, a palette editor, a sprite sheet, a
glyph map and a 6502 register view.

layout.ScrollArea takes Follow, and ChatLog now uses it. data.TreeNode
takes a Value drawn in its Slot. pixel gains Has, and Sprite.Art
writes MustSprite art. pixel.Editor takes the caller's value at each
input event, so a value changed between frames is never typed onto.
2026-10-12 07:18:30 -04:00

41 lines
1.3 KiB
Go

package data_test
import (
"testing"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
func TestTreeDrawsValuesInTheirSlot(t *testing.T) {
sel := "0"
roots := []data.TreeNode{{Label: "name", Value: `"Aria"`, Slot: pixel.Good}, {Label: "hp", Value: "42", Slot: pixel.Warn}}
tt := view(300, 200, newClock(), false, func(c *ui.Context) {
data.Tree(c, "Doc", roots, &sel, data.TreeOptions{})
})
r, img := find(t, tt, "Doc"), tt.Image()
count := func(row int, s pixel.Slot) int {
n, want := 0, pixel.SpringDay.Colors[s]
for y := int(r.Y) + row*2*pixel.LineHeight; y < int(r.Y)+(row+1)*2*pixel.LineHeight; y++ {
for x := int(r.X); x < int(r.X+r.W); x++ {
if c := img.RGBAAt(x, y); c.R == want.R && c.G == want.G && c.B == want.B {
n++
}
}
}
return n
}
// The chosen row inks its value; the other keeps Warn.
if count(0, pixel.Good) != 0 || count(1, pixel.Warn) == 0 {
t.Fatalf("values: Good on the chosen row %d, Warn below %d", count(0, pixel.Good), count(1, pixel.Warn))
}
// A click on the middle chooses the second row.
click(t, tt, "Doc")
img = tt.Image()
if sel != "1" || count(0, pixel.Good) == 0 || count(1, pixel.Warn) != 0 {
t.Fatalf("choosing hp (%q) did not swap which value is inked", sel)
}
}