PageRenderTime 83ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/plugins/state_machine/test/unit/matcher_test.rb

https://bitbucket.org/systech3/boxyroom
Ruby | 155 lines | 120 code | 35 blank | 0 comment | 0 complexity | 35bd5b5bc7dae0efc2aae2622dd82605 MD5 | raw file
Possible License(s): JSON, MIT
  1. require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
  2. class MatcherByDefaultTest < Test::Unit::TestCase
  3. def setup
  4. @matcher = StateMachine::Matcher.new
  5. end
  6. def test_should_have_no_values
  7. assert_equal [], @matcher.values
  8. end
  9. def test_should_filter_all_values
  10. assert_equal [], @matcher.filter([:parked, :idling])
  11. end
  12. end
  13. class MatcherWithValueTest < Test::Unit::TestCase
  14. def setup
  15. @matcher = StateMachine::Matcher.new(nil)
  16. end
  17. def test_should_have_values
  18. assert_equal [nil], @matcher.values
  19. end
  20. def test_should_filter_unknown_values
  21. assert_equal [nil], @matcher.filter([nil, :parked])
  22. end
  23. end
  24. class MatcherWithMultipleValuesTest < Test::Unit::TestCase
  25. def setup
  26. @matcher = StateMachine::Matcher.new([:parked, :idling])
  27. end
  28. def test_should_have_values
  29. assert_equal [:parked, :idling], @matcher.values
  30. end
  31. def test_should_filter_unknown_values
  32. assert_equal [:parked], @matcher.filter([:parked, :first_gear])
  33. end
  34. end
  35. class AllMatcherTest < Test::Unit::TestCase
  36. def setup
  37. @matcher = StateMachine::AllMatcher.instance
  38. end
  39. def test_should_have_no_values
  40. assert_equal [], @matcher.values
  41. end
  42. def test_should_always_match
  43. [nil, :parked, :idling].each {|value| assert @matcher.matches?(value)}
  44. end
  45. def test_should_not_filter_any_values
  46. assert_equal [:parked, :idling], @matcher.filter([:parked, :idling])
  47. end
  48. def test_should_generate_blacklist_matcher_after_subtraction
  49. matcher = @matcher - [:parked, :idling]
  50. assert_instance_of StateMachine::BlacklistMatcher, matcher
  51. assert_equal [:parked, :idling], matcher.values
  52. end
  53. def test_should_have_a_description
  54. assert_equal 'all', @matcher.description
  55. end
  56. end
  57. class WhitelistMatcherTest < Test::Unit::TestCase
  58. def setup
  59. @matcher = StateMachine::WhitelistMatcher.new([:parked, :idling])
  60. end
  61. def test_should_have_values
  62. assert_equal [:parked, :idling], @matcher.values
  63. end
  64. def test_should_filter_unknown_values
  65. assert_equal [:parked, :idling], @matcher.filter([:parked, :idling, :first_gear])
  66. end
  67. def test_should_match_known_values
  68. assert @matcher.matches?(:parked)
  69. end
  70. def test_should_not_match_unknown_values
  71. assert !@matcher.matches?(:first_gear)
  72. end
  73. def test_should_have_a_description
  74. assert_equal '[:parked, :idling]', @matcher.description
  75. matcher = StateMachine::WhitelistMatcher.new([:parked])
  76. assert_equal ':parked', matcher.description
  77. end
  78. end
  79. class BlacklistMatcherTest < Test::Unit::TestCase
  80. def setup
  81. @matcher = StateMachine::BlacklistMatcher.new([:parked, :idling])
  82. end
  83. def test_should_have_values
  84. assert_equal [:parked, :idling], @matcher.values
  85. end
  86. def test_should_filter_known_values
  87. assert_equal [:first_gear], @matcher.filter([:parked, :idling, :first_gear])
  88. end
  89. def test_should_match_unknown_values
  90. assert @matcher.matches?(:first_gear)
  91. end
  92. def test_should_not_match_known_values
  93. assert !@matcher.matches?(:parked)
  94. end
  95. def test_should_have_a_description
  96. assert_equal 'all - [:parked, :idling]', @matcher.description
  97. matcher = StateMachine::BlacklistMatcher.new([:parked])
  98. assert_equal 'all - :parked', matcher.description
  99. end
  100. end
  101. class LoopbackMatcherTest < Test::Unit::TestCase
  102. def setup
  103. @matcher = StateMachine::LoopbackMatcher.instance
  104. end
  105. def test_should_have_no_values
  106. assert_equal [], @matcher.values
  107. end
  108. def test_should_filter_all_values
  109. assert_equal [], @matcher.filter([:parked, :idling])
  110. end
  111. def test_should_match_if_from_context_is_same
  112. assert @matcher.matches?(:parked, :from => :parked)
  113. end
  114. def test_should_not_match_if_from_context_is_different
  115. assert !@matcher.matches?(:parked, :from => :idling)
  116. end
  117. def test_should_have_a_description
  118. assert_equal 'same', @matcher.description
  119. end
  120. end