Class: Rex::Parser::Arguments::UnitTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rex/parser/arguments.rb.ut.rb

Instance Method Summary collapse

Instance Method Details

#test_from_sObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rex/parser/arguments.rb.ut.rb', line 55

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

#test_parseObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rex/parser/arguments.rb.ut.rb', line 11

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