mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
We are about to add gui.darkTheme and gui.lightTheme, with the same type as gui.theme. The schema generator stores a struct type as one definition that all its properties refer to, and setDefaultVals writes the defaults of each path into that definition. The overrides would then claim the defaults of gui.theme, both in the schema and in Config.md. Give each property whose struct definition is shared a copy of its own. In Config.md, print only the description of every copy after the first, so that the fields aren't listed several times. Nothing in the config shares a struct definition yet, so the generated files don't change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package jsonschema
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/karimkhaleel/jsonschema"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type testColors struct {
|
|
Border []string `yaml:"border"`
|
|
}
|
|
|
|
type testGui struct {
|
|
Theme testColors `yaml:"theme"`
|
|
DarkTheme testColors `yaml:"darkTheme"`
|
|
}
|
|
|
|
type testConfig struct {
|
|
Gui testGui `yaml:"gui"`
|
|
OtherTheme testColors `yaml:"otherTheme"`
|
|
}
|
|
|
|
func TestInlineSharedStructDefinitions(t *testing.T) {
|
|
r := &jsonschema.Reflector{FieldNameTag: "yaml"}
|
|
schema := r.Reflect(&testConfig{})
|
|
|
|
repeatedStructs := inlineSharedStructDefinitions(schema, "testConfig")
|
|
setDefaultVals(schema, schema.Definitions["testConfig"], testConfig{
|
|
Gui: testGui{Theme: testColors{Border: []string{"green"}}},
|
|
})
|
|
|
|
gui := getSubSchema(schema, schema.Definitions["testConfig"], "gui")
|
|
theme := getSubSchema(schema, gui, "theme")
|
|
darkTheme := getSubSchema(schema, gui, "darkTheme")
|
|
otherTheme := getSubSchema(schema, schema.Definitions["testConfig"], "otherTheme")
|
|
|
|
assert.Equal(t, []*jsonschema.Schema{darkTheme, otherTheme}, repeatedStructs)
|
|
assert.NotContains(t, schema.Definitions, "testColors")
|
|
|
|
assert.Equal(t, []string{"green"}, getSubSchema(schema, theme, "border").Default)
|
|
assert.Nil(t, getSubSchema(schema, darkTheme, "border").Default)
|
|
assert.Nil(t, getSubSchema(schema, otherTheme, "border").Default)
|
|
}
|