summaryrefslogtreecommitdiff
path: root/i18n/i18n_test.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2025-08-25 10:59:37 +0200
committerJeroen Wijenbergh <jeroen.wijenbergh@geant.org>2025-08-25 13:06:41 +0200
commit27b95b4911da055fe9b5fb37b5fb4a33eda6b989 (patch)
treef6eb1143fa9bd2995d671b71d75c950e2c703660 /i18n/i18n_test.go
parentb4f4f5600298436c63b89f289c318d777300c499 (diff)
All: Remove util packages
Was giving linting errors and it's not a good idea anyways
Diffstat (limited to 'i18n/i18n_test.go')
-rw-r--r--i18n/i18n_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/i18n/i18n_test.go b/i18n/i18n_test.go
new file mode 100644
index 0000000..fc671a4
--- /dev/null
+++ b/i18n/i18n_test.go
@@ -0,0 +1,47 @@
+package i18n
+
+import "testing"
+
+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")
+ }
+}