Module#constant_source_location [Feature #10771]

This commit is contained in:
Nobuyoshi Nakada 2018-12-13 21:49:05 +09:00
parent 5084233b88
commit 9384383019
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
4 changed files with 176 additions and 0 deletions

View file

@ -2375,6 +2375,23 @@ class TestModule < Test::Unit::TestCase
}
end
ConstLocation = [__FILE__, __LINE__]
def test_const_source_location
assert_equal(ConstLocation, self.class.const_source_location(:ConstLocation))
assert_equal(ConstLocation, self.class.const_source_location("ConstLocation"))
assert_equal(ConstLocation, Object.const_source_location("#{self.class.name}::ConstLocation"))
assert_raise(TypeError) {
self.class.const_source_location(nil)
}
assert_raise_with_message(NameError, /wrong constant name/) {
self.class.const_source_location("xxx")
}
assert_raise_with_message(TypeError, %r'does not refer to class/module') {
self.class.const_source_location("ConstLocation::FILE")
}
end
private
def assert_top_method_is_private(method)