forgejo/modules/translation/translation_test.go
0ko 973ff28f44
Some checks are pending
/ release (push) Waiting to run
testing-integration / test-unit (push) Waiting to run
testing-integration / test-sqlite (push) Waiting to run
testing-integration / test-mariadb (v10.6) (push) Waiting to run
testing-integration / test-mariadb (v11.8) (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
chore(test): separate and move around i18n testing (#10539)
Closes #10534

The primary code change is that `TestMissingTranslationHandling` was converted to a unit test.

However translation unit tests were a mix of mostly unrelated old (INI) and new (JSON) code with unclear licensing. It was cleaned up with help of Git history.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10539
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2025-12-23 04:39:26 +01:00

49 lines
1.5 KiB
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package translation
import (
"testing"
"forgejo.org/modules/translation/i18n"
"github.com/stretchr/testify/assert"
)
func TestTrSize(t *testing.T) {
l := NewLocale("")
size := int64(1)
assert.Equal(t, "1 munits.data.b", l.TrSize(size).String())
size *= 2048
assert.Equal(t, "2 munits.data.kib", l.TrSize(size).String())
size *= 2048
assert.Equal(t, "4 munits.data.mib", l.TrSize(size).String())
size *= 2048
assert.Equal(t, "8 munits.data.gib", l.TrSize(size).String())
size *= 2048
assert.Equal(t, "16 munits.data.tib", l.TrSize(size).String())
size *= 2048
assert.Equal(t, "32 munits.data.pib", l.TrSize(size).String())
size *= 128
assert.Equal(t, "4 munits.data.eib", l.TrSize(size).String())
}
func TestPrettyNumber(t *testing.T) {
i18n.ResetDefaultLocales()
allLangMap = make(map[string]*LangType)
allLangMap["id-ID"] = &LangType{Lang: "id-ID", Name: "Bahasa Indonesia"}
l := NewLocale("id-ID")
assert.Equal(t, "1.000.000", l.PrettyNumber(1000000))
assert.Equal(t, "1.000.000,1", l.PrettyNumber(1000000.1))
assert.Equal(t, "1.000.000", l.PrettyNumber("1000000"))
assert.Equal(t, "1.000.000", l.PrettyNumber("1000000.0"))
assert.Equal(t, "1.000.000,1", l.PrettyNumber("1000000.1"))
l = NewLocale("nosuch")
assert.Equal(t, "1,000,000", l.PrettyNumber(1000000))
assert.Equal(t, "1,000,000.1", l.PrettyNumber(1000000.1))
}