Sha256: 2e1eccff072686c40faf86cae67ec813a4e69e51d5cc49db147505eff3e44c56

Contents?: true

Size: 1.2 KB

Versions: 43

Compression:

Stored size: 1.2 KB

Contents

#!/usr/bin/env ruby

$:.unshift(File.join(File.dirname(__FILE__), '..', '..'))

require 'test/unit'
require 'rex/parser/arguments'

class Rex::Parser::Arguments::UnitTest < Test::Unit::TestCase

	def test_parse
		args =
			[
				"-b",
				"foo",
				"-c",
				"-f",
				"-g",
				"arg",
				"none"
			]

		b = nil
		c = false
		f = false
		g = nil
		none = nil

		Rex::Parser::Arguments.new(
			'-b' => [ true,  "bee" ],
			'-c' => [ false, "cee" ],
			'-f' => [ false, "eff" ],
			'-g' => [ true,  "gee" ]).parse(args) { |opt, idx, val|
			case opt
				when nil
					none = val
				when '-b'
					b = val
				when '-c'
					c = true
				when '-f'
					f = true
				when '-g'
					g = val
			end
		}

		assert_equal(b, "foo")
		assert_equal(c, true)
		assert_equal(f, true)
		assert_equal(g, "arg")
		assert_equal(none, "none")
	end

	def test_from_s
		args = Rex::Parser::Arguments.from_s(
			"this is a test \"of the emergency pimping\" system \\\"buh lee dat\\\" yup")

		assert_equal(args[0], "this")
		assert_equal(args[3], "test")
		assert_equal(args[4], "of the emergency pimping")
		assert_equal(args[5], "system")
		assert_equal(args[6], "\"buh")
		assert_equal(args[8], "dat\"")
		assert_equal(args[9], "yup")
	end

end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
librex-0.0.65 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.63 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.54 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.53 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.52 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.51 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.50 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.49 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.48 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.47 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.46 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.44 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.43 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.42 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.41 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.40 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.39 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.38 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.37 lib/rex/parser/arguments.rb.ut.rb
librex-0.0.36 lib/rex/parser/arguments.rb.ut.rb