feat: emoji-ktを追加

This commit is contained in:
usbharu 2024-01-07 12:55:52 +09:00
parent 855055d49a
commit a015566e52
3 changed files with 70 additions and 0 deletions

View File

@ -142,6 +142,15 @@ repositories {
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
maven {
name = "GitHubPackages2"
url = uri("https://maven.pkg.github.com/multim-dev/emoji-kt")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
kotlin {
@ -205,6 +214,8 @@ dependencies {
implementation("org.bytedeco:javacv-platform:1.5.9")
implementation("org.flywaydb:flyway-core")
implementation("dev.usbharu:emoji-kt:2.0.0")
implementation("io.ktor:ktor-client-logging-jvm:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")

View File

@ -0,0 +1,18 @@
package dev.usbharu.hideout.util
import Emojis
object EmojiUtil {
val emojiMap by lazy {
Emojis.allEmojis
.associate { it.code.replace(" ", "-") to it.char }
.filterValues { it != "" }
}
fun isEmoji(string: String): Boolean {
return emojiMap.any { it.value == string }
}
}

View File

@ -0,0 +1,41 @@
package dev.usbharu.hideout.util
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
class EmojiUtilTest {
@Test
fun 絵文字を判定できる() {
val emoji = ""
val actual = EmojiUtil.isEmoji(emoji)
assertThat(actual).isTrue()
}
@Test
fun ただの文字を判定できる() {
val moji = "blobblinkhyper"
val actual = EmojiUtil.isEmoji(moji)
assertThat(actual).isFalse()
}
@ParameterizedTest
@ValueSource(strings = ["", "🌄", "🤗", "", "🧑‍🤝‍🧑", "🖐🏿"])
fun `絵文字判定`(s: String) {
val actual = EmojiUtil.isEmoji(s)
assertThat(actual).isTrue()
}
@ParameterizedTest
@ValueSource(strings = ["", "", ""])
fun `文字判定`(s: String) {
val actual = EmojiUtil.isEmoji(s)
assertThat(actual).isFalse()
}
}