Files
8bitMyGoUI/code/paint_internal_test.go
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

37 lines
1.0 KiB
Go

package code
import (
"strings"
"testing"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
func TestPaintColorsGoTokens(t *testing.T) {
src := "package main\n// hi\nfunc f() int { return len(\"x\") + 42 + nil }\nvar s = `a\nb` /* c\nd */"
slots := paint(src)
at := func(word string, nth int) pixel.Slot {
i := -1
for range nth + 1 {
i += 1 + strings.Index(src[i+1:], word)
}
return slots[i]
}
for _, tc := range []struct {
word string
nth int
want pixel.Slot
}{
{"package", 0, pixel.Accent}, {"main", 0, pixel.Ink}, {"// hi", 0, pixel.Faint}, {"func", 0, pixel.Accent},
{"f()", 0, pixel.Ink}, {"int", 0, pixel.Info}, {"len", 0, pixel.Info}, {`"x"`, 0, pixel.Good},
{"42", 0, pixel.Warn}, {"nil", 0, pixel.Magic}, {"+", 0, pixel.Ink}, {"b`", 0, pixel.Good}, {"d */", 0, pixel.Faint},
} {
if got := at(tc.word, tc.nth); got != tc.want {
t.Errorf("%q is %v, want %v", tc.word, got, tc.want)
}
}
if tidy("a\r\n\tb\n\n") != "a\n b" {
t.Fatalf("tidy = %q", tidy("a\r\n\tb\n\n"))
}
}