1package config
2
3import (
4 "testing"
5
6 "github.com/bnema/neferwl/internal/ports"
7)
8
9func TestWorkspaceSize(t *testing.T) {
10 for _, tc := range []struct {
11 value string
12 want [2]int
13 valid bool
14 }{
15 {"1920x1080", [2]int{1920, 1080}, true},
16 {"inherit", [2]int{}, true},
17 {"auto", [2]int{}, false},
18 {"0x1080", [2]int{}, false},
19 {"1920x0", [2]int{}, false},
20 {"1920x1080@60", [2]int{}, false},
21 {"-1x1080", [2]int{}, false},
22 {"1920", [2]int{}, false},
23 {"999999999999999999999x1080", [2]int{}, false},
24 } {
25 t.Run(tc.value, func(t *testing.T) {
26 var ws ports.WorkspaceConfig
27 err := setWorkspace(&ws, "size", tc.value)
28 if (err == nil) != tc.valid || ws.Size != tc.want {
29 t.Fatalf("size %v, err %v; want %v valid=%v", ws.Size, err, tc.want, tc.valid)
30 }
31 })
32 }
33}
34
35func TestWorkspaceSizeParserAndInheritance(t *testing.T) {
36 cfg, warnings := parseString(t, "workspace.presentation.size = 1920x1080\nbind.Cmd+p = workspace presentation\n")
37 if len(warnings) != 0 || len(cfg.Workspaces) != 1 || cfg.Workspaces[0].Size != [2]int{1920, 1080} {
38 t.Fatalf("config %+v, warnings %v", cfg.Workspaces, warnings)
39 }
40 cfg, warnings = parseString(t, "workspace.presentation.size = 1920x1080\nworkspace.presentation.size = inherit\nbind.Cmd+p = workspace presentation\n")
41 // Duplicate keys may warn; the final value must restore inheritance.
42 if len(cfg.Workspaces) != 1 || cfg.Workspaces[0].Size != [2]int{} {
43 t.Fatalf("inherit %+v, warnings %v", cfg.Workspaces, warnings)
44 }
45}