Compare commits

...

2 Commits

3 changed files with 66 additions and 6 deletions

View File

@ -94,7 +94,8 @@ func findTheme (name string, trail []string, warn bool, path ...string) (Theme,
instances := []string { }
for _, dir := range path {
entries, err := os.ReadDir(dir)
if err != nil { return Theme { }, err }
if err != nil { continue }
for _, entry := range entries {
if entry.Name() == name {
instances = append (
@ -143,7 +144,7 @@ func findTheme (name string, trail []string, warn bool, path ...string) (Theme,
if err != nil {
if warn {
log.Printf (
"xdg: could not parse inherited theme %s: %v",
"xdg: could not parse inherited theme '%s': %v",
parent, err)
}
continue

View File

@ -66,7 +66,7 @@ func Parse (reader io.Reader) (File, error) {
var specifiedValues map[string] struct { }
for {
line, err := buffer.ReadString('\n')
if errors.Is(err, io.EOF) { return file, nil }
if errors.Is(err, io.EOF) { break }
if err != nil { return nil, err }
line = strings.TrimSpace(line)
@ -109,15 +109,20 @@ func Parse (reader io.Reader) (File, error) {
group[key] = entry
} else {
// default value
_, exists := group[key]
if exists { return nil, ErrDuplicateEntry }
entry := newEntry()
_, specified := specifiedValues[key]
if specified { return nil, ErrDuplicateEntry }
entry, exists := group[key]
if !exists { entry = newEntry() }
entry.Value = value
group[key] = entry
specifiedValues[key] = struct { } { }
}
}
}
return file, nil
}
func newEntry () Entry {

View File

@ -168,3 +168,57 @@ File {
"Icon": testEntry("fooview-new"),
},
})}
func TestParseLocalized (test *testing.T) {
testParseString(test, `
[Group 0]
Name=something
Name[xx_XX]=other thing
Name[yy_YY]=another thing
Name[zz_ZZ]=yet another thing
[Group 1]
Name[xx_XX]=other thing
Name[yy_YY]=another thing
Name=something
Name[zz_ZZ]=yet another thing
`,
File {
"Group 0": Group {
"Name": Entry {
Value: "something",
Localized: map[locale.Locale] string {
locale.Locale {
Lang: "xx",
Country: "XX",
}: "other thing",
locale.Locale {
Lang: "yy",
Country: "YY",
}: "another thing",
locale.Locale {
Lang: "zz",
Country: "ZZ",
}: "yet another thing",
},
},
},
"Group 1": Group {
"Name": Entry {
Value: "something",
Localized: map[locale.Locale] string {
locale.Locale {
Lang: "xx",
Country: "XX",
}: "other thing",
locale.Locale {
Lang: "yy",
Country: "YY",
}: "another thing",
locale.Locale {
Lang: "zz",
Country: "ZZ",
}: "yet another thing",
},
},
},
})}