2005-06-04 18:32:51 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
2005-06-09 06:18:27 +00:00
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
2005-06-04 18:32:51 +00:00
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
require 'Rex/Transformer'
|
|
|
|
|
|
|
|
class Rex::Transformer::UnitTest < Test::Unit::TestCase
|
|
|
|
class Pizza
|
|
|
|
def Pizza.from_s(str)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-05 00:03:23 +00:00
|
|
|
class ArrayTester
|
|
|
|
def self.from_a(a)
|
|
|
|
a[0] + a[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-04 18:32:51 +00:00
|
|
|
def test_transformer
|
|
|
|
a = Rex::Transformer.transform([ 'yo', 'ho' ], Array, [ String ], 'Jones')
|
|
|
|
|
2005-06-05 00:03:23 +00:00
|
|
|
assert_equal(2, a.length, "invalid array length")
|
|
|
|
assert_equal('yo', a[0], "invalid first element")
|
|
|
|
assert_equal('ho', a[1], "invalid second element")
|
2005-06-04 18:32:51 +00:00
|
|
|
|
2005-06-04 18:55:20 +00:00
|
|
|
assert_raise(Rex::ArgumentError, "invalid transform") {
|
2005-06-04 18:32:51 +00:00
|
|
|
Rex::Transformer.transform('dog', Array, [ Pizza ], 'bob')
|
|
|
|
}
|
|
|
|
end
|
2005-06-05 00:03:23 +00:00
|
|
|
|
|
|
|
def test_from_a
|
|
|
|
a = Rex::Transformer.transform([ [ 'one', 'two' ] ], Array, [ ArrayTester ], 'Jimmy')
|
|
|
|
|
|
|
|
assert_equal('onetwo', a[0], "invalid from_a conversion")
|
|
|
|
end
|
2005-06-04 18:32:51 +00:00
|
|
|
end
|