#!/usr/local/bin/ruby
# Ruby Unit Tests

# Copyright 2001 by Jim Weirich (jweirich@one.net).
# All rights reserved.

# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.

require 'runit/testcase'
require 'runit/cui/testrunner'

require 'gem/listmodels'

$last_suite = RUNIT::TestSuite.new

# --------------------------------------------------------------------

class TestClassBrowser < RUNIT::TestCase
  def setup
    @finder = Gem::MethodFinder.new
    @cbm = Gem::ClassBrowserModel.new (@finder)
    @cbm.fill
  end

  def teardown
    @cbm = nil
  end

  def test_create
    assert @cbm != nil
    assert @cbm.class_model != nil
    assert @cbm.method_model != nil
    assert @cbm.module_model != nil
    assert @cbm.child_model != nil
  end

  def test_classes
    assert @cbm.class_model.items.member? ("Array")
  end

  def test_connections
    @cbm.class_model.select_name ("Integer")
    assert @cbm.child_model.items.member?(Bignum)
    assert @cbm.child_model.items.member?(Fixnum)
    assert @cbm.module_model.items.member?(Kernel)
    assert @cbm.module_model.items.member?(Comparable)
    assert @cbm.module_model.items.member?(Precision)
    assert @cbm.method_model.items.collect{|m|m.to_s}.member?("ceil")
  end

  def test_selections
    @cbm.class_model.select_name ("Integer")
    @cbm.child_model.select(0)
    assert_equal "Bignum", @cbm.class_model.selection
    @cbm.class_model.select_name ("Integer")
    @cbm.module_model.select(0)
    assert_equal "Kernel", @cbm.class_model.selection
  end

end

$last_suite.add_test (TestClassBrowser.suite)



# --------------------------------------------------------------------

if __FILE__ == $0 then
  RUNIT::CUI::TestRunner.quiet_mode = true
  RUNIT::CUI::TestRunner.run ($last_suite)
end
