2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2021-04-03 13:09:47 -04:00
|
|
|
require_relative "constantize_test_helpers"
|
2014-08-10 02:56:03 -04:00
|
|
|
|
2011-09-22 15:17:42 -04:00
|
|
|
module Ace
|
|
|
|
module Base
|
|
|
|
class Case
|
2012-05-04 23:57:11 -04:00
|
|
|
class Dice
|
|
|
|
end
|
2011-09-22 15:17:42 -04:00
|
|
|
end
|
2012-05-04 23:57:11 -04:00
|
|
|
class Fase < Case
|
|
|
|
end
|
|
|
|
end
|
|
|
|
class Gas
|
|
|
|
include Base
|
2011-09-22 15:17:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-05 10:13:33 -04:00
|
|
|
class Object
|
|
|
|
module AddtlGlobalConstants
|
|
|
|
class Case
|
|
|
|
class Dice
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
include AddtlGlobalConstants
|
|
|
|
end
|
|
|
|
|
2011-09-22 15:17:42 -04:00
|
|
|
module ConstantizeTestCases
|
2021-04-03 13:09:47 -04:00
|
|
|
include ConstantizeTestHelpers
|
2014-08-10 02:56:03 -04:00
|
|
|
|
2011-09-22 15:17:42 -04:00
|
|
|
def run_constantize_tests_on
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Ace::Base::Case, yield("Ace::Base::Case")
|
|
|
|
assert_equal Ace::Base::Case, yield("::Ace::Base::Case")
|
|
|
|
assert_equal Ace::Base::Case::Dice, yield("Ace::Base::Case::Dice")
|
2014-06-07 14:28:38 -04:00
|
|
|
assert_equal Ace::Base::Case::Dice, yield("Ace::Base::Fase::Dice")
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Ace::Base::Fase::Dice, yield("Ace::Base::Fase::Dice")
|
2014-06-07 14:28:38 -04:00
|
|
|
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Ace::Gas::Case, yield("Ace::Gas::Case")
|
|
|
|
assert_equal Ace::Gas::Case::Dice, yield("Ace::Gas::Case::Dice")
|
2014-06-07 14:28:38 -04:00
|
|
|
assert_equal Ace::Base::Case::Dice, yield("Ace::Gas::Case::Dice")
|
|
|
|
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Case::Dice, yield("Case::Dice")
|
2014-06-07 14:28:38 -04:00
|
|
|
assert_equal AddtlGlobalConstants::Case::Dice, yield("Case::Dice")
|
|
|
|
assert_equal Object::AddtlGlobalConstants::Case::Dice, yield("Case::Dice")
|
|
|
|
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Case::Dice, yield("Object::Case::Dice")
|
2014-06-07 14:28:38 -04:00
|
|
|
assert_equal AddtlGlobalConstants::Case::Dice, yield("Object::Case::Dice")
|
|
|
|
assert_equal Object::AddtlGlobalConstants::Case::Dice, yield("Case::Dice")
|
|
|
|
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal ConstantizeTestCases, yield("ConstantizeTestCases")
|
|
|
|
assert_equal ConstantizeTestCases, yield("::ConstantizeTestCases")
|
2014-06-07 14:28:38 -04:00
|
|
|
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_raises(NameError) { yield("UnknownClass") }
|
|
|
|
assert_raises(NameError) { yield("UnknownClass::Ace") }
|
|
|
|
assert_raises(NameError) { yield("UnknownClass::Ace::Base") }
|
|
|
|
assert_raises(NameError) { yield("An invalid string") }
|
|
|
|
assert_raises(NameError) { yield("InvalidClass\n") }
|
|
|
|
assert_raises(NameError) { yield("Ace::ConstantizeTestCases") }
|
|
|
|
assert_raises(NameError) { yield("Ace::Base::ConstantizeTestCases") }
|
|
|
|
assert_raises(NameError) { yield("Ace::Gas::Base") }
|
|
|
|
assert_raises(NameError) { yield("Ace::Gas::ConstantizeTestCases") }
|
2013-06-13 09:33:26 -04:00
|
|
|
assert_raises(NameError) { yield("") }
|
|
|
|
assert_raises(NameError) { yield("::") }
|
2014-08-10 02:56:03 -04:00
|
|
|
assert_raises(NameError) { yield("Ace::gas") }
|
|
|
|
|
|
|
|
assert_raises(NameError) do
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
yield("RaisesNameError")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(NoMethodError) do
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
yield("RaisesNoMethodError")
|
|
|
|
end
|
|
|
|
end
|
2011-09-22 15:17:42 -04:00
|
|
|
end
|
2012-01-26 14:19:49 -05:00
|
|
|
|
2011-09-22 15:17:42 -04:00
|
|
|
def run_safe_constantize_tests_on
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_equal Ace::Base::Case, yield("Ace::Base::Case")
|
|
|
|
assert_equal Ace::Base::Case, yield("::Ace::Base::Case")
|
|
|
|
assert_equal Ace::Base::Case::Dice, yield("Ace::Base::Case::Dice")
|
|
|
|
assert_equal Ace::Base::Fase::Dice, yield("Ace::Base::Fase::Dice")
|
|
|
|
assert_equal Ace::Gas::Case, yield("Ace::Gas::Case")
|
|
|
|
assert_equal Ace::Gas::Case::Dice, yield("Ace::Gas::Case::Dice")
|
|
|
|
assert_equal Case::Dice, yield("Case::Dice")
|
|
|
|
assert_equal Case::Dice, yield("Object::Case::Dice")
|
|
|
|
assert_equal ConstantizeTestCases, yield("ConstantizeTestCases")
|
|
|
|
assert_equal ConstantizeTestCases, yield("::ConstantizeTestCases")
|
2013-06-13 09:33:26 -04:00
|
|
|
assert_nil yield("")
|
|
|
|
assert_nil yield("::")
|
2012-11-05 22:20:56 -05:00
|
|
|
assert_nil yield("UnknownClass")
|
|
|
|
assert_nil yield("UnknownClass::Ace")
|
|
|
|
assert_nil yield("UnknownClass::Ace::Base")
|
|
|
|
assert_nil yield("An invalid string")
|
|
|
|
assert_nil yield("InvalidClass\n")
|
|
|
|
assert_nil yield("blargle")
|
|
|
|
assert_nil yield("Ace::ConstantizeTestCases")
|
|
|
|
assert_nil yield("Ace::Base::ConstantizeTestCases")
|
|
|
|
assert_nil yield("Ace::Gas::Base")
|
|
|
|
assert_nil yield("Ace::Gas::ConstantizeTestCases")
|
|
|
|
assert_nil yield("#<Class:0x7b8b718b>::Nested_1")
|
2014-08-10 02:56:03 -04:00
|
|
|
assert_nil yield("Ace::gas")
|
2016-08-06 12:03:25 -04:00
|
|
|
assert_nil yield("Object::ABC")
|
|
|
|
assert_nil yield("Object::Object::Object::ABC")
|
|
|
|
assert_nil yield("A::Object::B")
|
|
|
|
assert_nil yield("A::Object::Object::Object::B")
|
2014-08-10 02:56:03 -04:00
|
|
|
|
2019-01-07 14:13:45 -05:00
|
|
|
assert_raises(LoadError) do
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
yield("RaisesLoadError")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-10 02:56:03 -04:00
|
|
|
assert_raises(NameError) do
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
yield("RaisesNameError")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raises(NoMethodError) do
|
|
|
|
with_autoloading_fixtures do
|
|
|
|
yield("RaisesNoMethodError")
|
|
|
|
end
|
|
|
|
end
|
2011-09-22 15:17:42 -04:00
|
|
|
end
|
2012-01-26 14:19:49 -05:00
|
|
|
end
|