test(markdown,guildstree,qr,root): use identifier-based names and subtests

This commit is contained in:
ayn2op 2026-09-02 18:07:02 -04:00
parent 9d38982a8f
commit 8b9c28ce56
5 changed files with 102 additions and 94 deletions

View file

@ -9,7 +9,8 @@ import (
"github.com/gdamore/tcell/v3"
)
func TestRendererMasksSpoilers(t *testing.T) {
func TestRendererRenderText(t *testing.T) {
t.Run("masks spoilers", func(t *testing.T) {
source := []byte("before ||secret|| after")
node := md.Parse(source)
@ -31,4 +32,5 @@ func TestRendererMasksSpoilers(t *testing.T) {
t.Fatalf("mask=%t: got %q, want %q", test.mask, got.String(), test.want)
}
}
})
}

View file

@ -8,7 +8,8 @@ import (
"github.com/ayn2op/tview/tree"
)
func TestMoveDMToFront(t *testing.T) {
func TestModelMoveDMToFront(t *testing.T) {
t.Run("moves rendered channel to front", func(t *testing.T) {
firstID := discord.ChannelID(1)
secondID := discord.ChannelID(2)
thirdID := discord.ChannelID(3)
@ -32,9 +33,9 @@ func TestMoveDMToFront(t *testing.T) {
if !slices.Equal(dmRoot.Children(), want) {
t.Fatalf("children = %v, want %v", dmRoot.Children(), want)
}
}
})
func TestMoveDMToFrontIgnoresUnrenderedChannel(t *testing.T) {
t.Run("ignores unrendered channel", func(t *testing.T) {
firstID := discord.ChannelID(1)
first := tree.NewNode("first").SetReference(firstID)
dmRoot := tree.NewNode("Direct Messages").SetChildren([]*tree.Node{first})
@ -49,4 +50,5 @@ func TestMoveDMToFrontIgnoresUnrenderedChannel(t *testing.T) {
if len(children) != 1 || children[0] != first {
t.Fatalf("children = %v, want the original DM node", children)
}
})
}

View file

@ -7,7 +7,8 @@ import (
"github.com/skip2/go-qrcode"
)
func TestSetRectRendersContent(t *testing.T) {
func TestModelSetRect(t *testing.T) {
t.Run("renders content", func(t *testing.T) {
m := NewModel()
code, err := qrcode.New("test", qrcode.Low)
if err != nil {
@ -19,4 +20,5 @@ func TestSetRectRendersContent(t *testing.T) {
if !strings.Contains(text, m.status) || !strings.ContainsAny(text, "█▀▄") {
t.Fatal("missing content")
}
})
}

View file

@ -3,6 +3,7 @@ package qr
import "testing"
func TestDecodeMessage(t *testing.T) {
t.Run("decodes messages", func(t *testing.T) {
tests := []struct {
data string
want any
@ -21,10 +22,11 @@ func TestDecodeMessage(t *testing.T) {
t.Errorf("decodeMessage(%s) = %#v, want %#v", test.data, got, test.want)
}
}
}
})
func TestDecodeMessageRejectsDuplicateNames(t *testing.T) {
t.Run("rejects duplicate names", func(t *testing.T) {
if _, ok := decodeMessage([]byte(`{"op":"cancel","op":"hello"}`)).(errMsg); !ok {
t.Fatal("duplicate name was accepted")
}
})
}

View file

@ -8,13 +8,13 @@ import (
"github.com/gdamore/tcell/v3"
)
func TestHelpEnabled(t *testing.T) {
func TestNewModel(t *testing.T) {
cfg, err := config.Load(filepath.Join(t.TempDir(), "missing.toml"))
if err != nil {
t.Fatal(err)
}
t.Run("enabled", func(t *testing.T) {
t.Run("help enabled", func(t *testing.T) {
cfg := *cfg
cfg.Help.Enabled = true
m := NewModel(&cfg)
@ -51,7 +51,7 @@ func TestHelpEnabled(t *testing.T) {
}
})
t.Run("disabled", func(t *testing.T) {
t.Run("help disabled", func(t *testing.T) {
cfg := *cfg
cfg.Help.Enabled = false
m := NewModel(&cfg)