Files
bbs/internal/screens/samples_test.go
T
Claude 4c787da415 Samples: screens, menus and strings in color with tags
logon, welcome and goodbye .asc (shown to plain terminals, Commodores,
and 3270s without a .3270) in color like bulletins.asc; goodbye.3270
with a second color; bbs.conf.sample's menus with tagged titles and
labels and its [strings] with tagged prompts.  A test reads the samples
and fails on a tag that is not one, so a typo shows in the tests rather
than as braces on a caller's screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-13 22:08:30 +00:00

51 lines
1.3 KiB
Go

package screens
import (
"os"
"path/filepath"
"regexp"
"strings"
"testing"
)
// TestSamples: every tag in the sample screens and in bbs.conf.sample's
// menus and strings is one (a typo would show its braces).
func TestSamples(t *testing.T) {
var texts []string
for _, pat := range []string{"*.asc", "*.3270"} {
files, _ := filepath.Glob(filepath.Join("..", "..", "screens.sample", pat))
for _, f := range files {
b, err := os.ReadFile(f)
if err != nil {
t.Fatal(err)
}
texts = append(texts, string(b))
}
}
conf, err := os.ReadFile(filepath.Join("..", "..", "bbs.conf.sample"))
if err != nil {
t.Fatal(err)
}
// the menus' and the strings' lines (other settings have {placeholders})
c := string(conf)
from, to := strings.Index(c, ";[menu main]"), strings.Index(c, ";welcome = ")
if from < 0 || to < from {
t.Fatal("no sample menus and strings in bbs.conf.sample")
}
setting := regexp.MustCompile(`^;[a-z_]+ = `)
for _, l := range strings.Split(c[from:to], "\n") {
if setting.MatchString(l) && strings.Contains(l, "{") {
texts = append(texts, l)
}
}
if len(texts) < 10 {
t.Fatalf("only %d texts found", len(texts))
}
any := func(string) (string, bool) { return "x", true }
for _, s := range texts {
if left := String(s, any); strings.ContainsAny(left, "{}") {
t.Errorf("an unknown tag in %q: %q", s, left)
}
}
}