Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Util: Test GetLanguageMatched
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Aug 26, 2024
1 parent bec4a0a commit bd8c7f6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,47 @@ func TestCalculateGateway(t *testing.T) {
}
}
}

func TestGetLanguageMatched(t *testing.T) {
// exact match
returned := GetLanguageMatched(map[string]string{"en": "test", "de": "test2"}, "en")
if returned != "test" {
t.Fatalf("Got: %s, want: %s", returned, "test")
}

// starts with language tag
returned = GetLanguageMatched(map[string]string{"en-US-test": "test", "de": "test2"}, "en-US")
if returned != "test" {
t.Fatalf("Got: %s, want: %s", returned, "test")
}

// starts with en-
returned = GetLanguageMatched(map[string]string{"en-UK": "test", "en": "test2"}, "en-US")
if returned != "test" {
t.Fatalf("Got: %s, want: %s", returned, "test")
}

// exact match for en
returned = GetLanguageMatched(map[string]string{"de": "test", "en": "test2"}, "en-US")
if returned != "test2" {
t.Fatalf("Got: %s, want: %s", returned, "test2")
}

// We default to english
returned = GetLanguageMatched(map[string]string{"es": "test", "en": "test2"}, "nl-NL")
if returned != "test2" {
t.Fatalf("Got: %s, want: %s", returned, "test2")
}

// We default to english with a - as well
returned = GetLanguageMatched(map[string]string{"est": "test", "en-": "test2"}, "en-US")
if returned != "test2" {
t.Fatalf("Got: %s, want: %s", returned, "test2")
}

// None found just return one
returned = GetLanguageMatched(map[string]string{"es": "test"}, "en-US")
if returned != "test" {
t.Fatalf("Got: %s, want: %s", returned, "test")
}
}

0 comments on commit bd8c7f6

Please sign in to comment.