diff options
Diffstat (limited to 'spec/ruby/core/basicobject/fixtures')
4 files changed, 283 insertions, 0 deletions
diff --git a/spec/ruby/core/basicobject/fixtures/classes.rb b/spec/ruby/core/basicobject/fixtures/classes.rb new file mode 100644 index 0000000000..ed5a2dda17 --- /dev/null +++ b/spec/ruby/core/basicobject/fixtures/classes.rb @@ -0,0 +1,255 @@ +module BasicObjectSpecs + class IVars + def initialize + @secret = 99 + end + end + + module InstExec + def self.included(base) + base.instance_exec { @@count = 2 } + end + end + + module InstExecIncluded + include InstExec + end + + module InstEval + module CVar + module Get + class ReceiverScope + @@cvar = :value_defined_in_receiver_scope + end + + class BlockDefinitionScope + @@cvar = :value_defined_in_block_definition_scope + + def block + -> * { @@cvar } + end + end + + class CallerScope + @@cvar = :value_defined_in_caller_scope + + def get_class_variable_with_string(obj) + obj.instance_eval("@@cvar") + end + + def get_class_variable_with_block(obj, block) + obj.instance_eval(&block) + end + end + + class CallerWithoutCVarScope + def get_class_variable_with_string(obj) + obj.instance_eval("@@cvar") + end + end + + ReceiverWithCVarDefinedInSingletonClass = Class.new.new.tap do |obj| + obj.singleton_class.class_variable_set(:@@cvar, :value_defined_in_receiver_singleton_class) + end + end + + module Set + class ReceiverScope + end + + class BlockDefinitionScope + def self.get_class_variable + @@cvar + end + + def block_to_assign(value) + -> * { @@cvar = value } + end + end + + class CallerScope + def self.get_class_variable + @@cvar + end + + def set_class_variable_with_string(obj, value) + obj.instance_eval("@@cvar=#{value.inspect}") + end + + def set_class_variable_with_block(obj, block) + obj.instance_eval(&block) + end + end + end + end + end + + module InstEval + module Constants + module ConstantInReceiverSingletonClass + module ReceiverScope + FOO = :ReceiverScope + + class ReceiverParent + FOO = :ReceiverParent + end + + class Receiver < ReceiverParent + FOO = :Receiver + + def initialize + self.singleton_class.const_set(:FOO, :singleton_class) + end + end + end + + module CallerScope + FOO = :CallerScope + + class CallerParent + FOO = :CallerParent + end + + class Caller < CallerParent + FOO = :Caller + + def get_constant_with_string(receiver) + receiver.instance_eval("FOO") + end + end + end + end + + module ConstantInReceiverClass + module ReceiverScope + FOO = :ReceiverScope + + class ReceiverParent + FOO = :ReceiverParent + end + + class Receiver < ReceiverParent + FOO = :Receiver + end + end + + module CallerScope + FOO = :CallerScope + + class CallerParent + FOO = :CallerParent + end + + class Caller < CallerParent + FOO = :Caller + + def get_constant_with_string(receiver) + receiver.instance_eval("FOO") + end + end + end + end + + module ConstantInCallerClass + module ReceiverScope + FOO = :ReceiverScope + + class ReceiverParent + FOO = :ReceiverParent + end + + class Receiver < ReceiverParent + # FOO is not declared in a receiver class + end + end + + module CallerScope + FOO = :CallerScope + + class CallerParent + FOO = :CallerParent + end + + class Caller < CallerParent + FOO = :Caller + + def get_constant_with_string(receiver) + receiver.instance_eval("FOO") + end + end + end + end + + module ConstantInCallerOuterScopes + module ReceiverScope + FOO = :ReceiverScope + + class ReceiverParent + FOO = :ReceiverParent + end + + class Receiver < ReceiverParent + # FOO is not declared in a receiver class + end + end + + module CallerScope + FOO = :CallerScope + + class CallerParent + FOO = :CallerParent + end + + class Caller < CallerParent + # FOO is not declared in a caller class + + def get_constant_with_string(receiver) + receiver.instance_eval("FOO") + end + end + end + end + + module ConstantInReceiverParentClass + module ReceiverScope + FOO = :ReceiverScope + + class ReceiverParent + FOO = :ReceiverParent + end + + class Receiver < ReceiverParent + # FOO is not declared in a receiver class + end + end + + module CallerScope + # FOO is not declared in a caller outer scopes + + class CallerParent + FOO = :CallerParent + end + + class Caller < CallerParent + # FOO is not declared in a caller class + + def get_constant_with_string(receiver) + receiver.instance_eval("FOO") + end + end + end + end + end + end + + class InstEvalConst + INST_EVAL_CONST_X = 2 + end + + module InstEvalOuter + module Inner + obj = InstEvalConst.new + X_BY_BLOCK = obj.instance_eval { INST_EVAL_CONST_X } rescue nil + end + end +end diff --git a/spec/ruby/core/basicobject/fixtures/common.rb b/spec/ruby/core/basicobject/fixtures/common.rb new file mode 100644 index 0000000000..3447a3a5e7 --- /dev/null +++ b/spec/ruby/core/basicobject/fixtures/common.rb @@ -0,0 +1,9 @@ +module BasicObjectSpecs + class BOSubclass < BasicObject + def self.kernel_defined? + defined?(Kernel) + end + + include ::Kernel + end +end diff --git a/spec/ruby/core/basicobject/fixtures/remove_method_missing.rb b/spec/ruby/core/basicobject/fixtures/remove_method_missing.rb new file mode 100644 index 0000000000..095b982d3a --- /dev/null +++ b/spec/ruby/core/basicobject/fixtures/remove_method_missing.rb @@ -0,0 +1,9 @@ +class BasicObject + remove_method :method_missing +end + +begin + Object.new.test_method +rescue NoMethodError => e + puts e.class.name +end diff --git a/spec/ruby/core/basicobject/fixtures/singleton_method.rb b/spec/ruby/core/basicobject/fixtures/singleton_method.rb new file mode 100644 index 0000000000..0e00e035fa --- /dev/null +++ b/spec/ruby/core/basicobject/fixtures/singleton_method.rb @@ -0,0 +1,10 @@ +module BasicObjectSpecs + class SingletonMethod + def self.singleton_method_added name + ScratchPad.record [:singleton_method_added, name] + end + + def self.singleton_method_to_alias + end + end +end |
