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