Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SORT_KEYをテストする #399

Merged
merged 5 commits into from
Mar 20, 2021
Merged

SORT_KEYをテストする #399

merged 5 commits into from
Mar 20, 2021

Conversation

ysakasin
Copy link
Member

BCDice 3.1.0であやまったSORT_KEYを混入させてしまったので、仕様に適合するかチェックするかテストします。

@ysakasin ysakasin requested a review from ochaochaocha3 March 20, 2021 10:39
@codecov
Copy link

codecov bot commented Mar 20, 2021

Codecov Report

Merging #399 (36a9a1a) into master (ff1c486) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #399   +/-   ##
=======================================
  Coverage   94.61%   94.61%           
=======================================
  Files         280      280           
  Lines       18591    18591           
=======================================
  Hits        17590    17590           
  Misses       1001     1001           
Impacted Files Coverage Δ
...cdice/game_system/Cthulhu7th_ChineseTraditional.rb 14.94% <100.00%> (ø)
lib/bcdice/game_system/Cthulhu7th_Korean.rb 100.00% <100.00%> (ø)
...b/bcdice/game_system/Cthulhu_ChineseTraditional.rb 100.00% <100.00%> (ø)
lib/bcdice/game_system/Cthulhu_Korean.rb 100.00% <100.00%> (ø)
lib/bcdice/game_system/MeikyuKingdomBasic.rb 67.88% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff1c486...36a9a1a. Read the comment docs.

test/test_sort_key.rb Outdated Show resolved Hide resolved
Co-authored-by: Kosuke Yamashita <[email protected]>
@ochaochaocha3
Copy link
Member

ochaochaocha3 commented Mar 20, 2021

気づいていなかったのですが、意外と普通のシステムのソートキーに幅がありましたね。ひらがなから始まって、ひらがな・英数字・半角ドット・半角スペースのいずれかが0個以上続いて、ひらがな・英数字・半角ドットのいずれかで終わる、といった感じでしょうか。

@ochaochaocha3
Copy link
Member

だいぶ複雑になりましたが、こちらならば全システム通りました。

diff --git a/test/test_sort_key.rb b/test/test_sort_key.rb
index 1d2a5040..f336eccc 100644
--- a/test/test_sort_key.rb
+++ b/test/test_sort_key.rb
@@ -5,14 +5,14 @@ require "bcdice"
 require "bcdice/game_system"

 class TestSortKey < Test::Unit::TestCase
-  HIRAGANA_BASIC_CHARS = "[あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん]"
+  HIRAGANA_BASIC_CHARS = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん"

   data do
     BCDice.all_game_systems.map { |s| [s::ID, s::SORT_KEY] }.to_h
   end
   def test_sort_key(sort_key)
     assert_match(
-      /\A(?:#{HIRAGANA_BASIC_CHARS}+[\d.A-Za-z]*|国際化:[\w ]+:.+|\*たいすほつと)\z/,
+      /\A(?:[#{HIRAGANA_BASIC_CHARS}][ \d.A-Za-z#{HIRAGANA_BASIC_CHARS}]*[\d.A-Za-z#{HIRAGANA_BASIC_CHARS}]|国際化:[\w ]+:.+|\*たいすほつと)\z/,
       sort_key,
       "SORT_KEY \"#{sort_key}\" はSORT_KEYの規約に違反しています。規約は docs/dicebot_sort_key.md を参照してください"
     )

@ochaochaocha3
Copy link
Member

迷宮キングダムの基本ルールブックのソートキーに空白が入っていたのがルールからの逸脱だったようなので、上の正規表現をもう少し単純化できそうです。

diff --git a/test/test_sort_key.rb b/test/test_sort_key.rb
index 1d2a5040..e91da2d8 100644
--- a/test/test_sort_key.rb
+++ b/test/test_sort_key.rb
@@ -5,14 +5,14 @@ require "bcdice"
 require "bcdice/game_system"

 class TestSortKey < Test::Unit::TestCase
-  HIRAGANA_BASIC_CHARS = "[あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん]"
+  HIRAGANA_BASIC_CHARS = "あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん"

   data do
     BCDice.all_game_systems.map { |s| [s::ID, s::SORT_KEY] }.to_h
   end
   def test_sort_key(sort_key)
     assert_match(
-      /\A(?:#{HIRAGANA_BASIC_CHARS}+[\d.A-Za-z]*|国際化:[\w ]+:.+|\*たいすほつと)\z/,
+      /\A(?:[#{HIRAGANA_BASIC_CHARS}][\d.A-Za-z#{HIRAGANA_BASIC_CHARS}]*|国際化:[\w ]+:.+|\*たいすほつと)\z/,
       sort_key,
       "SORT_KEY \"#{sort_key}\" はSORT_KEYの規約に違反しています。規約は docs/dicebot_sort_key.md を参照してください"
     )

Copy link
Member

@ochaochaocha3 ochaochaocha3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これで大丈夫だと思います!

@ysakasin ysakasin merged commit 2ec6679 into master Mar 20, 2021
@ysakasin ysakasin deleted the test_sort_key branch March 20, 2021 14:18
@ysakasin
Copy link
Member Author

@ochaochaocha3 レビューありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants