mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-15 07:44:01 -04:00
78 lines
1.9 KiB
Go
78 lines
1.9 KiB
Go
package windowrules
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/configfrag"
|
|
)
|
|
|
|
func marshalKeys(t *testing.T, v any) map[string]json.RawMessage {
|
|
t.Helper()
|
|
data, err := json.Marshal(v)
|
|
if err != nil {
|
|
t.Fatalf("marshal: %v", err)
|
|
}
|
|
var out map[string]json.RawMessage
|
|
if err := json.Unmarshal(data, &out); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
return out
|
|
}
|
|
|
|
func TestDMSRulesStatusKeySpellings(t *testing.T) {
|
|
keys := marshalKeys(t, DMSRulesStatus{
|
|
Exists: true,
|
|
Included: true,
|
|
IncludePosition: 2,
|
|
TotalIncludes: 3,
|
|
RulesAfterDMS: 4,
|
|
Effective: true,
|
|
OverriddenBy: 4,
|
|
StatusMessage: "DMS window rules are active",
|
|
ConfigFormat: "lua",
|
|
ReadOnly: true,
|
|
})
|
|
|
|
want := []string{"exists", "included", "includePosition", "totalIncludes", "rulesAfterDms", "effective", "overriddenBy", "statusMessage", "configFormat", "readOnly"}
|
|
if len(keys) != len(want) {
|
|
t.Fatalf("key count = %d, want %d: %v", len(keys), len(want), keys)
|
|
}
|
|
for _, key := range want {
|
|
if _, ok := keys[key]; !ok {
|
|
t.Errorf("missing key %q", key)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDMSRulesStatusFromCarriesEveryField(t *testing.T) {
|
|
got := DMSRulesStatusFrom(configfrag.Status{
|
|
Exists: true,
|
|
Included: true,
|
|
IncludePosition: 2,
|
|
TotalIncludes: 3,
|
|
EntriesAfterDMS: 7,
|
|
Effective: true,
|
|
OverriddenBy: 7,
|
|
StatusMessage: "DMS window rules are active",
|
|
ConfigFormat: "lua",
|
|
ReadOnly: true,
|
|
})
|
|
|
|
want := DMSRulesStatus{
|
|
Exists: true,
|
|
Included: true,
|
|
IncludePosition: 2,
|
|
TotalIncludes: 3,
|
|
RulesAfterDMS: 7,
|
|
Effective: true,
|
|
OverriddenBy: 7,
|
|
StatusMessage: "DMS window rules are active",
|
|
ConfigFormat: "lua",
|
|
ReadOnly: true,
|
|
}
|
|
if *got != want {
|
|
t.Errorf("DMSRulesStatusFrom = %+v, want %+v", *got, want)
|
|
}
|
|
}
|