Skip to content

Commit

Permalink
AddDiceのPREFIX_PATTERNをより厳密に (#407)
Browse files Browse the repository at this point in the history
* AddDiceのPREFIX_PATTERNをより厳密に

* テストケースの追加
  • Loading branch information
blhsrwznrghfzpr authored Apr 4, 2021
1 parent cfee15a commit e997ab4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/bcdice/common_command/add_dice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module BCDice
module CommonCommand
module AddDice
PREFIX_PATTERN = /[+\-\dD(]+/.freeze
PREFIX_PATTERN = /[+\-(]*\d+/.freeze

class << self
def eval(command, game_system, randomizer)
Expand Down
5 changes: 4 additions & 1 deletion test/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DummySystem < BCDice::Base

class TestBase < Test::Unit::TestCase
def test_command_pattern
assert_equal(/^S?([+\-\dD(]+|\d+B\d+|C|choice|D66|(repeat|rep|x)\d+|\d+R\d+|\d+U\d+|BCDiceVersion|ABC|XYZ|IP\d+)/i, DummySystem.command_pattern)
assert_equal(/^S?([+\-(]*\d+|\d+B\d+|C|choice|D66|(repeat|rep|x)\d+|\d+R\d+|\d+U\d+|BCDiceVersion|ABC|XYZ|IP\d+)/i, DummySystem.command_pattern)

assert_match(DummySystem.command_pattern, "ABC+123")
assert_match(DummySystem.command_pattern, "XYZ[hoge]")
Expand All @@ -31,5 +31,8 @@ def test_command_pattern
assert_not_match(DummySystem.command_pattern, "[1...3]D100<=70")
assert_match(DummySystem.command_pattern, "-3+2D100<=70")
assert_match(DummySystem.command_pattern, "+3+2D100<=70")
assert_not_match(DummySystem.command_pattern, "D6")
assert_not_match(DummySystem.command_pattern, "+-")
assert_match(DummySystem.command_pattern, "+(---(-3+1))D")
end
end
2 changes: 1 addition & 1 deletion test/test_sai_fic_skill_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class DummySystem < BCDice::Base
end

def test_command_pattern
assert_equal(/^S?([+\-\dD(]+|\d+B\d+|C|choice|D66|(repeat|rep|x)\d+|\d+R\d+|\d+U\d+|BCDiceVersion|RTT[1-6]?|RCT)/i, DummySystem.command_pattern)
assert_equal(/^S?([+\-(]*\d+|\d+B\d+|C|choice|D66|(repeat|rep|x)\d+|\d+R\d+|\d+U\d+|BCDiceVersion|RTT[1-6]?|RCT)/i, DummySystem.command_pattern)
end
end

0 comments on commit e997ab4

Please sign in to comment.