Sha256: 038fa8457f541cd8e63af0d1771582e98fd7518309507995da1ba7dd584f178c

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

require 'test_helper'

class TC_testFlag < Clean::Test::TestCase
  include TestHelper

  def test_basics_simple
    Given flag_with_names(:f)
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be(nil)
  end

  def test_basics_kinda_complex
    Given flag_with_names([:f])
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be(nil)
  end

  def test_basics_complex
    Given flag_with_names([:f,:file,:filename])
    Then attributes_should_be_set
    And name_should_be(:f)
    And aliases_should_be([:file,:filename])
    And {
      assert_equal ["-f VAL","--file VAL","--filename VAL",/foobar/,Float],@flag.arguments_for_option_parser
    }
  end

  def flag_with_names(names)
    lambda do
      @options = {
        :desc => 'Filename',
        :long_desc => 'The Filename',
        :arg_name => 'file',
        :default_value => '~/.blah.rc',
        :must_match => /foobar/,
        :type => Float,
      }
      @flag = GLI::Flag.new(names,@options)
      @cli_option = @flag
    end
  end

  def attributes_should_be_set
    lambda {
      assert_equal(@options[:desc],@flag.description)
      assert_equal(@options[:long_desc],@flag.long_description)
      assert_equal(@options[:default_value],@flag.default_value)
      assert_equal(@options[:must_match],@flag.must_match)
      assert_equal(@options[:type],@flag.type)
      assert(@flag.usage != nil)
    }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gli-2.1.0 test/tc_flag.rb
gli-2.0.0 test/tc_flag.rb
gli-2.0.0.rc8 test/tc_flag.rb
gli-2.0.0.rc7 test/tc_flag.rb