feat: support named switchable layouts
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDefaultValid(t *testing.T) {
|
||||
if err := Default().Validate(); err != nil {
|
||||
@@ -15,6 +19,51 @@ func TestLayoutFallback(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
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"}
|
||||
|
||||
Reference in New Issue
Block a user