2022-01-26 23:38:46 -08:00
|
|
|
package engine
|
2021-03-27 04:04:43 -07:00
|
|
|
|
|
|
|
import (
|
2022-01-26 06:54:36 -08:00
|
|
|
"oh-my-posh/segments"
|
2021-03-27 04:04:43 -07:00
|
|
|
"testing"
|
|
|
|
|
2021-11-22 06:25:56 -08:00
|
|
|
"github.com/gookit/config/v2"
|
2022-01-26 06:54:36 -08:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2021-03-27 04:04:43 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSettingsExportJSON(t *testing.T) {
|
2021-11-22 06:25:56 -08:00
|
|
|
defer testClearDefaultConfig()
|
2022-01-26 23:38:46 -08:00
|
|
|
content := ExportConfig("../themes/jandedobbeleer.omp.json", "json")
|
2021-03-27 04:04:43 -07:00
|
|
|
assert.NotContains(t, content, "\\u003ctransparent\\u003e")
|
|
|
|
assert.Contains(t, content, "<transparent>")
|
|
|
|
}
|
2021-11-22 06:25:56 -08:00
|
|
|
|
|
|
|
func testClearDefaultConfig() {
|
|
|
|
config.Default().ClearAll()
|
|
|
|
}
|
2022-01-26 06:54:36 -08:00
|
|
|
|
|
|
|
func TestParseMappedLocations(t *testing.T) {
|
|
|
|
defer testClearDefaultConfig()
|
|
|
|
cases := []struct {
|
|
|
|
Case string
|
|
|
|
JSON string
|
|
|
|
}{
|
|
|
|
{Case: "new format", JSON: `{ "properties": { "mapped_locations": {"folder1": "one","folder2": "two"} } }`},
|
|
|
|
{Case: "old format", JSON: `{ "properties": { "mapped_locations": [["folder1", "one"], ["folder2", "two"]] } }`},
|
|
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
|
|
config.ClearAll()
|
|
|
|
config.WithOptions(func(opt *config.Options) {
|
|
|
|
opt.DecoderConfig = &mapstructure.DecoderConfig{
|
|
|
|
TagName: "config",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
err := config.LoadStrings(config.JSON, tc.JSON)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
var segment Segment
|
|
|
|
err = config.BindStruct("", &segment)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
mappedLocations := segment.Properties.GetKeyValueMap(segments.MappedLocations, make(map[string]string))
|
|
|
|
assert.Equal(t, "two", mappedLocations["folder2"])
|
|
|
|
}
|
|
|
|
}
|