Skip to content

Commit aeb6bc0

Browse files
committed
feat(config): update MergeConfigs to handle local language and UseEmoji merging
1 parent 5b25b69 commit aeb6bc0

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func LoadConfigWithHierarchy(globalPath string) (*Config, error) {
162162
func MergeConfigs(global, local *Config) *Config {
163163
result := *global
164164

165-
if local.Language != "" && local.Language != defaultLang {
165+
if local.Language != "" {
166166
result.Language = local.Language
167167
}
168168
if local.SuggestionsCount > 0 {

internal/config/config_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,69 @@ func TestValidateConfig(t *testing.T) {
360360
})
361361
}
362362
}
363+
364+
func TestMergeConfigs(t *testing.T) {
365+
t.Run("should merge local language over global when local is non-default", func(t *testing.T) {
366+
global := &Config{
367+
Language: "en",
368+
UseEmoji: true,
369+
}
370+
local := &Config{
371+
Language: "es",
372+
}
373+
374+
result := MergeConfigs(global, local)
375+
376+
if result.Language != "es" {
377+
t.Errorf("Language = %v, want %v", result.Language, "es")
378+
}
379+
})
380+
381+
t.Run("should merge local language over global when local is default (en)", func(t *testing.T) {
382+
global := &Config{
383+
Language: "es",
384+
UseEmoji: true,
385+
}
386+
local := &Config{
387+
Language: "en",
388+
}
389+
390+
result := MergeConfigs(global, local)
391+
392+
if result.Language != "en" {
393+
t.Errorf("Language = %v, want %v (local 'en' should override global 'es')", result.Language, "en")
394+
}
395+
})
396+
397+
t.Run("should not override global language when local is empty", func(t *testing.T) {
398+
global := &Config{
399+
Language: "es",
400+
UseEmoji: true,
401+
}
402+
local := &Config{
403+
Language: "",
404+
}
405+
406+
result := MergeConfigs(global, local)
407+
408+
if result.Language != "es" {
409+
t.Errorf("Language = %v, want %v (empty local should not override)", result.Language, "es")
410+
}
411+
})
412+
413+
t.Run("should merge UseEmoji from local", func(t *testing.T) {
414+
global := &Config{
415+
Language: "en",
416+
UseEmoji: true,
417+
}
418+
local := &Config{
419+
UseEmoji: false,
420+
}
421+
422+
result := MergeConfigs(global, local)
423+
424+
if result.UseEmoji != false {
425+
t.Errorf("UseEmoji = %v, want %v", result.UseEmoji, false)
426+
}
427+
})
428+
}

0 commit comments

Comments
 (0)