95 lines
2.4 KiB
Go
95 lines
2.4 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestDefaultValid(t *testing.T) {
|
|
if err := Default().Validate(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestLayoutFallback(t *testing.T) {
|
|
c := Default()
|
|
if _, ok := c.LayoutFor(`\\.\DISPLAY99`); !ok {
|
|
t.Fatal("expected wildcard layout")
|
|
}
|
|
}
|
|
|
|
func TestActiveLayoutSelection(t *testing.T) {
|
|
c := Default()
|
|
c.Layouts = append(c.Layouts, Layout{Name: "wide", Monitor: "*", Zones: []Zone{{Name: "wide", Width: 100, Height: 100}}})
|
|
c.ActiveLayout = "wide"
|
|
got, ok := c.LayoutFor(`\\.\DISPLAY1`)
|
|
if !ok || got.Name != "wide" || len(got.Zones) != 1 {
|
|
t.Fatalf("wrong active layout: %+v, %v", got, ok)
|
|
}
|
|
}
|
|
|
|
func TestLegacyLayoutUpgrade(t *testing.T) {
|
|
c := Default()
|
|
c.ActiveLayout = ""
|
|
for i := range c.Layouts {
|
|
c.Layouts[i].Name = ""
|
|
}
|
|
c.upgradeLegacyLayouts()
|
|
if c.ActiveLayout != "default" || c.Layouts[0].Name != "default" {
|
|
t.Fatalf("legacy layout was not upgraded: %+v", c)
|
|
}
|
|
}
|
|
|
|
func TestLoadLegacyUnnamedLayout(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "legacy.yaml")
|
|
data := []byte("version: 1\ngap: 8\nshift_drag: true\nlayouts:\n - monitor: '*'\n zones:\n - {x: 0, y: 0, width: 100, height: 100}\n")
|
|
if err := os.WriteFile(path, data, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
c, err := Load(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c.ActiveLayout != "default" || c.Layouts[0].Name != "default" {
|
|
t.Fatalf("legacy file was not upgraded: %+v", c)
|
|
}
|
|
}
|
|
|
|
func TestMissingActiveLayoutFails(t *testing.T) {
|
|
c := Default()
|
|
c.ActiveLayout = "missing"
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("expected missing active layout to fail")
|
|
}
|
|
}
|
|
|
|
func TestExcluded(t *testing.T) {
|
|
c := Default()
|
|
c.Excluded = []string{"notepad", "exact.exe"}
|
|
if !c.IsExcluded(`C:\Windows\notepad.exe`) || !c.IsExcluded(`C:\x\exact.exe`) || c.IsExcluded(`C:\x\other.exe`) {
|
|
t.Fatal("bad exclusion matching")
|
|
}
|
|
}
|
|
|
|
func TestInvalidNumberedAction(t *testing.T) {
|
|
c := Default()
|
|
c.Hotkeys = []Hotkey{{Keys: "win+alt+1", Action: "zone_nope"}}
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("expected invalid numbered action to fail")
|
|
}
|
|
}
|
|
|
|
func TestOverlayValidation(t *testing.T) {
|
|
c := Default()
|
|
c.Overlay.Color = "blue"
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("expected invalid overlay color to fail")
|
|
}
|
|
c = Default()
|
|
c.Overlay.Opacity = 101
|
|
if err := c.Validate(); err == nil {
|
|
t.Fatal("expected invalid overlay opacity to fail")
|
|
}
|
|
}
|