Skip to content

Commit

Permalink
fix: x.comの置き換えがされない & picだけ残る問題の修正 (jaoafa#147)
Browse files Browse the repository at this point in the history
* fix: x.comの置き換えがされない & picだけ残る問題の修正

* test: テストケースの追加

* test: picが正しく置き換えられるテストの追加
  • Loading branch information
book000 authored Jun 15, 2024
1 parent 0f8cbe4 commit b0397ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/jaoafa/vcspeaker/tools/Twitter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object Twitter {
.setMaxLineLength(Integer.MAX_VALUE)
.setNewLine(null)
.toString()
val readText = getReadText(plainText)
val readText = getReadText(plainText).trim()
Tweet(
json.authorName,
json.html,
Expand All @@ -58,7 +58,7 @@ object Twitter {
return text
.replace("#(\\S+)".toRegex(), " ハッシュタグ「$1」 ")
.replace("<?(?:https?://)?t\\.co/[a-zA-Z0-9]+>?".toRegex(), "")
.replace("<?(?:https?://)?twitter\\.com/.+>?".toRegex(), "")
.replace("<?(?:https?://)?pic\\.twitter\\.com/[a-zA-Z0-9]+>?".toRegex(), "")
.replace("<?(?:https?://)?pic\\.(?:x|twitter)\\.com/[a-zA-Z0-9]+>?".toRegex(), "")
.replace("<?(?:https?://)?(?:x|twitter)\\.com/.+>?".toRegex(), "")
}
}
43 changes: 43 additions & 0 deletions src/test/kotlin/TwitterTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import com.jaoafa.vcspeaker.tools.Twitter
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.equals.shouldBeEqual
import io.kotest.matchers.nulls.shouldBeNull
import io.kotest.matchers.nulls.shouldNotBeNull

class TwitterTest : FunSpec({
test("getTweet") {
val tweet = Twitter.getTweet("jaoafa", "1685568414084124673")

tweet.shouldNotBeNull()
tweet.authorName.shouldNotBeNull()
tweet.html.shouldNotBeNull()
tweet.plainText.shouldNotBeNull()
tweet.readText.shouldNotBeNull()

tweet.authorName shouldBeEqual "jao Community"
tweet.html shouldBeEqual "<blockquote class=\"twitter-tweet\"><p lang=\"ja\" dir=\"ltr\">この度、jao Minecraft Serverでは2023年08月02日 22時00分をもって、Minecraft サーバのサービス提供を終了させていただくこととなりました。<br>利用者のみなさまには、突然のお知らせとなりますことをお詫びいたします。<br><br>7年間、本当にありがとうございました。<a href=\"https://twitter.com/hashtag/jaoafa?src=hash&amp;ref_src=twsrc%5Etfw\">#jaoafa</a></p>&mdash; jao Community (@jaoafa) <a href=\"https://twitter.com/jaoafa/status/1685568414084124673?ref_src=twsrc%5Etfw\">July 30, 2023</a></blockquote>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n\n"
tweet.plainText shouldBeEqual "この度、jao Minecraft Serverでは2023年08月02日 22時00分をもって、Minecraft サーバのサービス提供を終了させていただくこととなりました。\n利用者のみなさまには、突然のお知らせとなりますことをお詫びいたします。\n\n7年間、本当にありがとうございました。#jaoafa <https://twitter.com/hashtag/jaoafa?src=hash&ref_src=twsrc%5Etfw>"
tweet.readText shouldBeEqual "この度、jao Minecraft Serverでは2023年08月02日 22時00分をもって、Minecraft サーバのサービス提供を終了させていただくこととなりました。\n利用者のみなさまには、突然のお知らせとなりますことをお詫びいたします。\n\n7年間、本当にありがとうございました。 ハッシュタグ「jaoafa」"
}

test("getTweet (not found)") {
val tweet = Twitter.getTweet("jaoafa", "0")

tweet.shouldBeNull()
}

test("getTweet (with picture)") {
val tweet = Twitter.getTweet("jaoafa", "1775559092742021223")

tweet.shouldNotBeNull()
tweet.authorName.shouldNotBeNull()
tweet.html.shouldNotBeNull()
tweet.plainText.shouldNotBeNull()
tweet.readText.shouldNotBeNull()

tweet.authorName shouldBeEqual "jao Community"
tweet.html shouldBeEqual "<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">Do you remember when you joined X? I do! <a href=\"https://twitter.com/hashtag/MyXAnniversary?src=hash&amp;ref_src=twsrc%5Etfw\">#MyXAnniversary</a> <a href=\"https://t.co/JbXvgioO6o\">pic.twitter.com/JbXvgioO6o</a></p>&mdash; jao Community (@jaoafa) <a href=\"https://twitter.com/jaoafa/status/1775559092742021223?ref_src=twsrc%5Etfw\">April 3, 2024</a></blockquote>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n\n"
tweet.plainText shouldBeEqual "Do you remember when you joined X? I do! #MyXAnniversary <https://twitter.com/hashtag/MyXAnniversary?src=hash&ref_src=twsrc%5Etfw> pic.twitter.com/JbXvgioO6o <https://t.co/JbXvgioO6o>"
tweet.readText shouldBeEqual "Do you remember when you joined X? I do! ハッシュタグ「MyXAnniversary」"
}
})

0 comments on commit b0397ab

Please # to comment.