mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-17 21:54:03 +00:00
The Go parser had its own copy of the edge name mapping, which had drifted from the Python one. Generate the Go mapping from the Python one so there is a single source of truth, and share the documentation of the spacing syntax between set-spacing and launch --spacing, documenting the long forms. Closes #10712
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
// License: GPLv3 Copyright: 2026, Kovid Goyal, <kovid at kovidgoyal.net>
|
|
|
|
package at
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestParseSetSpacing(t *testing.T) {
|
|
ten := float64(10)
|
|
for args, expected := range map[string]map[string]any{
|
|
"padding=default": {"padding-left": nil, "padding-top": nil, "padding-right": nil, "padding-bottom": nil},
|
|
"margin-h=10": {"margin-left": ten, "margin-right": ten},
|
|
"Margin-Horizontal=10 padding-vertical=default": {"margin-left": ten, "margin-right": ten, "padding-top": nil, "padding-bottom": nil},
|
|
"padding-v=10 margin-bottom=10": {"padding-top": ten, "padding-bottom": ten, "margin-bottom": ten},
|
|
} {
|
|
actual, err := parse_set_spacing(strings.Fields(args))
|
|
if err != nil {
|
|
t.Fatalf("parse_set_spacing(%#v) failed with error: %s", args, err)
|
|
}
|
|
if diff := cmp.Diff(expected, actual); diff != "" {
|
|
t.Fatalf("parse_set_spacing(%#v) returned unexpected result:\n%s", args, diff)
|
|
}
|
|
}
|
|
for _, arg := range []string{"margin", "margin-diagonal=10", "padding=x"} {
|
|
if actual, err := parse_set_spacing([]string{arg}); err == nil {
|
|
t.Fatalf("parse_set_spacing(%#v) accepted invalid input and returned: %v", arg, actual)
|
|
}
|
|
}
|
|
}
|