Skip to content

Commit

Permalink
✅ Add tests to AppLanguage
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Colman Lopes <[email protected]>
  • Loading branch information
LeoColman committed Jan 29, 2025
1 parent fbdac98 commit 012e147
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package br.com.colman.petals.settings

import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe

class AppLanguageTest : FunSpec({
context("getAppLanguageName") {
withData(
nameFn = { (code, name) -> "for code '$code' returns '$name'" },
"de" to "Deutsch",
"en" to "English",
"fr" to "Français",
"es" to "Español",
"it" to "Italiano",
"nl" to "Nederlands",
"no" to "Norsk",
"pt" to "Português",
"ru" to "Русский",
"tr" to "Türkçe",
"uk" to "Українськ",
) { (code, expectedName) ->
AppLanguage.getAppLanguageName(code) shouldBe expectedName
}

context("edge cases") {
test("invalid code returns English default") {
AppLanguage.getAppLanguageName("xx") shouldBe "English"
}

test("empty code returns English default") {
AppLanguage.getAppLanguageName("") shouldBe "English"
}

test("case-sensitive - uppercase code returns English") {
AppLanguage.getAppLanguageName("DE") shouldBe "English"
}
}
}

context("getAppLanguageCode") {
withData(
nameFn = { (name, code) -> "for name '$name' returns '$code'" },
"Deutsch" to "de",
"English" to "en",
"Français" to "fr",
"Español" to "es",
"Italiano" to "it",
"Nederlands" to "nl",
"Norsk" to "no",
"Português" to "pt",
"Русский" to "ru",
"Türkçe" to "tr",
"Українськ" to "uk",
) { (languageName, expectedCode) ->
AppLanguage.getAppLanguageCode(languageName) shouldBe expectedCode
}

context("edge cases") {
test("invalid name returns English code") {
AppLanguage.getAppLanguageCode("Klingon") shouldBe "en"
}

test("empty name returns English code") {
AppLanguage.getAppLanguageCode("") shouldBe "en"
}

test("case-sensitive - lowercase name returns English") {
AppLanguage.getAppLanguageCode("deutsch") shouldBe "en"
}
}
}
})

0 comments on commit 012e147

Please sign in to comment.