table unit test

git-svn-id: file:///home/svn/incoming/trunk@2665 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-07 14:20:54 +00:00
parent 02361dde24
commit d8ba7df38a
3 changed files with 68 additions and 2 deletions

View File

@ -20,6 +20,8 @@ require 'Rex/Socket/Udp.rb.ut'
require 'Rex/Socket/Parameters.rb.ut'
require 'Rex/Socket/Comm/Local.rb.ut'
require 'Rex/Ui/Text/Table.rb.ut'
class Rex::TestSuite
def self.suite
suite = Test::Unit::TestSuite.new("Rex")
@ -44,6 +46,9 @@ class Rex::TestSuite
suite << Rex::Socket::Udp::UnitTest.suite
suite << Rex::Socket::Comm::Local::UnitTest.suite
# Ui
suite << Rex::Ui::Text::Table::UnitTest.suite
return suite;
end
end

View File

@ -123,8 +123,14 @@ protected
barline = nameline
columns.each_with_index { |col,idx|
nameline += col + pad(' ', col, idx)
barline += ('-' * col.length) + (' ' * cellpad)
nameline += col + pad(' ', col, idx)
remainder = colprops[idx]['MaxWidth'] - col.length
if (remainder < 0)
remainder = 0
end
barline += ('-' * col.length) + (' ' * (cellpad + remainder))
}
return "#{nameline}\n#{barline}"

View File

@ -0,0 +1,55 @@
#!/usr/bin/ruby
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
require 'test/unit'
require 'Rex/Ui/Text/Table'
class Rex::Ui::Text::Table::UnitTest < Test::Unit::TestCase
def new_table(opts = {})
if (opts['Columns'] == nil)
opts['Columns'] =
[
'col1',
'col2',
'col3'
]
end
tbl = Rex::Ui::Text::Table.new(opts)
tbl << [ "r1cell1", "r1cell2", "r1cell3" ]
tbl << [ "r2cell1", "r2cell2", "r2cell3" ]
return tbl
end
def test_basic
tbl = new_table
dstr = <<End
col1 col2 col3
---- ---- ----
r1cell1 r1cell2 r1cell3
r2cell1 r2cell2 r2cell3
End
assert_equal(tbl.to_s, dstr)
end
def test_indent
tbl = new_table(
'Indent' => 4)
dstr = <<End
col1 col2 col3
---- ---- ----
r1cell1 r1cell2 r1cell3
r2cell1 r2cell2 r2cell3
End
assert_equal(tbl.to_s, dstr)
end
end