Sha256: 73df83cc860f98b9df4e9beef21918dfc343e54fca23c470d34028b89483a5cb

Contents?: true

Size: 1.71 KB

Versions: 32

Compression:

Stored size: 1.71 KB

Contents

require 'test_helper'
require 'tins/go'

module Tins
  class GoTest < Test::Unit::TestCase
    include Tins::GO

    def test_empty_string
      r = go '', args = %w[a b c]
      assert_equal({}, r)
      assert_equal %w[a b c], args
    end

    def test_empty_args
      r = go 'ab:', args = []
      assert_equal({ 'a' => false, 'b' => nil }, r)
      assert_equal [], args
    end

    def test_simple
      r = go 'ab:', args = %w[-b hello -a -c rest]
      assert_equal({ 'a' => 1, 'b' => 'hello' }, r)
      assert_equal %w[-c rest], args
    end

    def test_complex
      r = go 'ab:', args = %w[-a -b hello -a -bworld -c rest]
      assert_equal({ 'a' => 2, 'b' => 'hello' }, r)
      assert_equal %w[hello world], r['b'].to_a
      assert_equal %w[-c rest], args
    end

    def test_complex2
      r = go 'ab:', args = %w[-b hello -aa -b world -c rest]
      assert_equal({ 'a' => 2, 'b' => 'hello' }, r)
      assert_equal %w[hello world], r['b'].to_a
      assert_equal %w[-c rest], args
    end

    def test_complex_frozen
      args = %w[-b hello -aa -b world -c rest]
      args = args.map(&:freeze)
      r = go 'ab:', args
      assert_equal({ 'a' => 2, 'b' => 'hello' }, r)
      assert_equal %w[hello world], r['b'].to_a
      assert_equal %w[-c rest], args
    end

    def test_mixed_rest
      r = go 'ab:e:', args = %w[-b hello -c rest -aa -b world -d rest -e]
      assert_equal({ 'a' => 2, 'b' => 'hello', 'e' => nil }, r)
      assert_equal %w[hello world], r['b'].to_a
      assert_equal %w[-c rest -d rest -e], args
    end

    def test_concatenated_argument_at_end
      r = go 'ab:e:', args = %w[-a -bhello]
      assert_equal({ 'a' => 1, 'b' => 'hello', 'e' => nil }, r)
      assert_equal [], args
    end
  end
end

Version data entries

32 entries across 30 versions & 4 rubygems

Version Path
tdiary-5.0.11 vendor/bundle/gems/tins-1.16.3/tests/go_test.rb
tins-1.19.0 tests/go_test.rb
tins-1.18.0 tests/go_test.rb
tins-1.17.0 tests/go_test.rb
tdiary-5.0.9 vendor/bundle/gems/tins-1.16.3/tests/go_test.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/tins-1.16.3/tests/go_test.rb
tdiary-5.0.7 vendor/bundle/gems/tins-1.16.3/tests/go_test.rb
tins-1.16.3 tests/go_test.rb
tins-1.16.2 tests/go_test.rb
tins-1.16.1 tests/go_test.rb
tins-1.16.0 tests/go_test.rb
tins-1.15.1 tests/go_test.rb
tdiary-5.0.6 vendor/bundle/gems/tins-1.15.0/tests/go_test.rb
tins-1.15.0 tests/go_test.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/tins-1.13.2/tests/go_test.rb
tdiary-5.0.5 vendor/bundle/gems/tins-1.14.0/tests/go_test.rb
tdiary-5.0.5 vendor/bundle/gems/tins-1.13.2/tests/go_test.rb
tins-1.14.0 tests/go_test.rb
tins-1.13.3 tests/go_test.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/tins-1.13.2/tests/go_test.rb