Sha256: 5663e1dd4f29df587a4b1fbec92b32706728cc85b083be5ea49c57ca23dd77c8

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'test_helper'

PatternMatching.configure do |config|
  config.use_proc_helpers = true
  config.send_helper      = :foo
  config.call_helper      = :bar
end

module ConfigurationTests
  class RenamedProcHelpers < Minitest::Test
    include PatternMatching

    test "send helper is defined as foo" do
      assert_respond_to(self, :foo)
    end

    test "call helper is defined as bar" do
      assert_respond_to(self, :bar)
    end


    test "can use S as a shortcut for symbol-to-proc" do
      result = Pattern(42, "", 555)
      assert_match(result,  foo(:even?),  foo(:empty?), foo(:odd?))
      refute_match(result,  foo(:odd?),   foo(:empty?), foo(:odd?))
    end


    def contains_e?(str)
      str.kind_of?(String) && str.count('e') > 0
    end


    def forty_two?(val)
      42 == val
    end


    def triple_five?(val)
      555 == val
    end


    test "can use C as a shortcut for methods in current context" do
      result = Pattern(42, "streetlight", 555)
      assert_match(result,  bar(:forty_two?),  bar(:contains_e?), bar(:triple_five?))
      refute_match(result,  bar(:forty_two?),  bar(:forty_two?),  bar(:triple_five?))
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pattern_matching-0.1.0 test/configuration_tests/renamed_proc_helpers_test.rb