From d8d61b19da6001ec95cc26b5f5802ffe0c742b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kuchy=C5=88ka=20=28Anty=29?= Date: Mon, 2 Dec 2024 16:11:55 +0100 Subject: [PATCH] chore: add tests --- .../formats/po/in/PoToICUConverterTest.kt | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt b/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt index 68358995f7..0b40c4809c 100644 --- a/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt +++ b/backend/data/src/test/kotlin/io/tolgee/unit/formats/po/in/PoToICUConverterTest.kt @@ -39,6 +39,50 @@ class PoToICUConverterTest { ) } + @Test + fun testPhpPluralsWithHashtags() { + val result = + getPhpConvertor().convert( + rawData = + mapOf( + 0 to "Petr má jeden znak #.", + 1 to "Petr má %d znaky #.", + 2 to "Petr má %d znaků #.", + ), + languageTag = "cs", + convertPlaceholders = true, + ).message + assertThat(result).isEqualTo( + "{0, plural,\n" + + "one {Petr má jeden znak '#'.}\n" + + "few {Petr má # znaky '#'.}\n" + + "other {Petr má # znaků '#'.}\n" + + "}", + ) + } + + @Test + fun testPhpPluralsWithHashtagsAndDisabledPlaceholders() { + val result = + getPhpConvertor().convert( + rawData = + mapOf( + 0 to "Petr má jeden znak #.", + 1 to "Petr má %d znaky #.", + 2 to "Petr má %d znaků #.", + ), + languageTag = "cs", + convertPlaceholders = false, + ).message + assertThat(result).isEqualTo( + "{value, plural,\n" + + "one {Petr má jeden znak '#'.}\n" + + "few {Petr má %d znaky '#'.}\n" + + "other {Petr má %d znaků '#'.}\n" + + "}", + ) + } + private fun getPhpConvertor() = PoToIcuMessageConvertor { PhpToIcuPlaceholderConvertor() } @Test @@ -48,6 +92,20 @@ class PoToICUConverterTest { assertThat(result).isEqualTo("hello this is string {0}, this is digit {1, number}") } + @Test + fun testPhpMessageWithHashtag() { + val result = + getPhpConvertor().convert("hello this is hashtag # and it should not be escaped", "en").message + assertThat(result).isEqualTo("hello this is hashtag # and it should not be escaped") + } + + @Test + fun testPhpMessageWithHashtagAndDisabledPlaceholders() { + val result = + getPhpConvertor().convert("hello this is hashtag # and it should not be escaped", "en", convertPlaceholders = false).message + assertThat(result).isEqualTo("hello this is hashtag # and it should not be escaped") + } + @Test fun testPhpMessageEscapes() { val result =