VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/lib/gems/2.5.0/gems/tins-1.28.0/tests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/lib/gems/2.5.0/gems/tins-1.28.0/tests/go_test.rb
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

    def test_defaults
      r = go('bv:', args = %w[ -v bar ], defaults: { ?b => true, ?v => 'foo' })
      assert_equal({ ?b => 1, 'v' => 'bar' }, r)
      assert_equal [], args
      r = go('bv:', args = %w[ -v bar ~b baz ], defaults: { ?b => true, ?v => 'foo' })
      assert_equal({ ?b => false, 'v' => 'bar' }, r)
      assert_equal %w[ baz ], args
      r = go('bv:', args = %w[ -b -v bar ], defaults: { ?b => 22, ?v => 'foo' })
      assert_equal({ ?b => 23, 'v' => 'bar' }, r)
      assert_equal [], args
      r = go('bv:', args = %w[ -b ], defaults: { ?b => false, ?v => 'foo' })
      assert_equal({ ?b => 1, 'v' => 'foo' }, r)
      assert_equal [], args
      r = go('bv:', args = %w[ ], defaults: { ?b => false, ?v => 'foo' })
      assert_equal({ ?b => false, 'v' => 'foo' }, r)
      assert_equal [], args
    end
  end
end

VaKeR 2022