Sha256: 9ff7679691f15b3f6e6254b972fc7f109b54c5b274e4d8e822b26e63a87b8109

Contents?: true

Size: 1.94 KB

Versions: 6

Compression:

Stored size: 1.94 KB

Contents

require File.join(File.dirname(__FILE__), '../test_helper')


describe HammerCLI::Options::Matcher do

  let(:option_a1) { Clamp::Option::Definition.new("--opt_a1", "OPT_A", "some option") }
  let(:option_a2) { Clamp::Option::Definition.new("--opt_a2", "OPT_A", "some option") }
  let(:option_a3) { Clamp::Option::Definition.new("--opt_a3", "OPT_A", "some option") }
  let(:option_b1) { Clamp::Option::Definition.new("--opt_b1", "OPT_B", "some option") }

  it "tests value" do
    matcher = HammerCLI::Options::Matcher.new(
      :long_switch => '--opt_a1'
    )
    _(matcher.matches?(option_a1)).must_equal true
    _(matcher.matches?(option_a2)).must_equal false
  end

  it "tests regex" do
    matcher = HammerCLI::Options::Matcher.new(
      :long_switch => /--opt_a.*/
    )
    _(matcher.matches?(option_a1)).must_equal true
    _(matcher.matches?(option_a2)).must_equal true
    _(matcher.matches?(option_b1)).must_equal false
  end

  it "tests multiple conditions" do
    matcher = HammerCLI::Options::Matcher.new(
      :long_switch => /--opt_.1/,
      :type => 'OPT_A'
    )
    _(matcher.matches?(option_a1)).must_equal true
    _(matcher.matches?(option_a2)).must_equal false
    _(matcher.matches?(option_a3)).must_equal false
    _(matcher.matches?(option_b1)).must_equal false
  end

  it "tests multiple values or regexes" do
    matcher = HammerCLI::Options::Matcher.new(
      :long_switch => [/--opt_.1/, "--opt_a3"]
    )
    _(matcher.matches?(option_a1)).must_equal true
    _(matcher.matches?(option_a2)).must_equal false
    _(matcher.matches?(option_a3)).must_equal true
    _(matcher.matches?(option_b1)).must_equal true
  end

  it "tests nil for unknown methods" do
    matcher = HammerCLI::Options::Matcher.new(
      :unknown_method => "some value"
    )
    _(matcher.matches?(option_a1)).must_equal false

    matcher = HammerCLI::Options::Matcher.new(
      :unknown_method => nil
    )
    _(matcher.matches?(option_a1)).must_equal true
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hammer_cli-3.14.0 test/unit/options/matcher_test.rb
hammer_cli-3.13.0 test/unit/options/matcher_test.rb
hammer_cli-3.12.0 test/unit/options/matcher_test.rb
hammer_cli-3.10.0 test/unit/options/matcher_test.rb
hammer_cli-3.9.0 test/unit/options/matcher_test.rb
hammer_cli-3.8.0 test/unit/options/matcher_test.rb