#!/usr/bin/env ruby
# -*- ruby -*-

# Copyright 2000, 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/methodfinder'
require 'gem/mockclasses'

$last_suite = RUNIT::TestSuite.new


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

class TestMethodFinder < RUNIT::TestCase
  def setup
    @finder = Gem::MethodFinder.new
  end

  def teardown
    @finder = nil
  end

  def test_normal
    assert_equal ['pub'], @finder.methods(Parent)
    assert_equal ['cpub'], @finder.methods(Child)
  end

  def test_private
    @finder.show_private = true
    assert_equal ['pub',  'prot', 'priv'].sort,  @finder.methods(Parent)
    assert_equal ['cpub', 'cpriv'].sort, @finder.methods(Child)
  end

  def test_flat
    @finder.flat = true
    assert_equal ['pub', 'm1'].sort,  @finder.methods(Parent)
    assert_equal ['pub', 'cpub', 'm1', 'm2'].sort, @finder.methods(Child)
  end

  def test_flat_private
    @finder.flat = true
    @finder.show_private = true
    assert_equal ['pub', 'prot', 'priv', 'm1'].sort,
      @finder.methods(Parent)
    assert_equal ['pub', 'prot', 'priv', 'cpub', 'cpriv', 'm1', 'm2'].sort,
      @finder.methods(Child)
  end
  
  def test_class
    @finder.use_class_methods = true
    assert_equal ['pc'], @finder.methods(Parent)
    assert_equal ['cc'], @finder.methods(Child)
  end
  
  def test_flat_class
    @finder.use_class_methods = true
    @finder.flat = true
    assert_equal ['pc'], @finder.methods(Parent)
    assert_equal ['pc', 'cc'].sort, @finder.methods(Child)
  end

  def test_object
    assert_equal [], @finder.methods(Object)
    @finder.flat = true
    assert_equal [], @finder.methods(Object)
  end

  def test_kernel
    assert @finder.methods(Kernel).member?("clone")
    @finder.flat = true
    assert_equal [], @finder.methods(Kernel)
  end
end

$last_suite.add_test (TestMethodFinder.suite)



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

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