1package core_test
2
3import (
4 "slices"
5 "strings"
6 "testing"
7
8 "github.com/bnema/neferwl/internal/adapters/config"
9 "github.com/bnema/neferwl/internal/core"
10 "github.com/bnema/neferwl/internal/ports"
11)
12
13// altCmdDefaults is the default config with keyboard.cmd = alt. The loader
14// drops binds that use both cmd and alt then; so does this helper.
15func altCmdDefaults() ports.Config {
16 cfg := config.Defaults()
17 cfg.Keyboard.CmdKey = "alt"
18 for combo := range cfg.Binds {
19 parts := strings.Split(combo, "+")
20 mods := parts[:len(parts)-1]
21 if slices.Contains(mods, "Alt") && slices.Contains(mods, "Cmd") {
22 delete(cfg.Binds, combo)
23 }
24 }
25 return cfg
26}
27
28func TestDefaultBindsAccepted(t *testing.T) {
29 for _, cmd := range []string{"super", "alt"} {
30 cfg := config.Defaults()
31 if cmd == "alt" {
32 cfg = altCmdDefaults()
33 }
34 if _, err := core.New(cfg, core.Channels{Scenes: make(chan []ports.Scene, 1)}); err != nil {
35 t.Fatalf("cmd=%s: %v", cmd, err)
36 }
37 }
38}
39
40func TestResizeArg(t *testing.T) {
41 for _, tc := range []struct {
42 a core.Action
43 axis, pct int
44 ok bool
45 }{
46 {"set-column-width +10%", core.ResizeWidth, 10, true},
47 {"set-column-width -5%", core.ResizeWidth, -5, true},
48 {"set-window-height +100%", core.ResizeHeight, 100, true},
49 {"set-window-height -1%", core.ResizeHeight, -1, true},
50 {"set-column-width 10%", 0, 0, false},
51 {"set-column-width +0%", 0, 0, false},
52 {"set-column-width +101%", 0, 0, false},
53 {"set-column-width +10", 0, 0, false},
54 {"set-column-width +-1%", 0, 0, false},
55 {"set-column-width ++1%", 0, 0, false},
56 {"set-window-height", 0, 0, false},
57 {"cycle-column-width", 0, 0, false},
58 } {
59 axis, pct, ok := core.ResizeArg(tc.a)
60 if axis != tc.axis || pct != tc.pct || ok != tc.ok {
61 t.Errorf("%q: %d %d %v", tc.a, axis, pct, ok)
62 }
63 }
64}