Class: RBS::Test::Tester::MethodCallTester

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/test/tester.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(self_class, builder, definition, kind:, sample_size:, unchecked_classes:) ⇒ MethodCallTester

Returns a new instance of MethodCallTester.



116
117
118
119
120
121
122
123
# File 'lib/rbs/test/tester.rb', line 116

def initialize(self_class, builder, definition, kind:, sample_size:, unchecked_classes:)
  @self_class = self_class
  @definition = definition
  @builder = builder
  @kind = kind
  @sample_size = sample_size
  @unchecked_classes = unchecked_classes
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



111
112
113
# File 'lib/rbs/test/tester.rb', line 111

def builder
  @builder
end

#definitionObject (readonly)

Returns the value of attribute definition.



110
111
112
# File 'lib/rbs/test/tester.rb', line 110

def definition
  @definition
end

#kindObject (readonly)

Returns the value of attribute kind.



112
113
114
# File 'lib/rbs/test/tester.rb', line 112

def kind
  @kind
end

#sample_sizeObject (readonly)

Returns the value of attribute sample_size.



113
114
115
# File 'lib/rbs/test/tester.rb', line 113

def sample_size
  @sample_size
end

#self_classObject (readonly)

Returns the value of attribute self_class.



109
110
111
# File 'lib/rbs/test/tester.rb', line 109

def self_class
  @self_class
end

#unchecked_classesObject (readonly)

Returns the value of attribute unchecked_classes.



114
115
116
# File 'lib/rbs/test/tester.rb', line 114

def unchecked_classes
  @unchecked_classes
end

Instance Method Details

#call(receiver, trace) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rbs/test/tester.rb', line 142

def call(receiver, trace)
  method_name = trace.method_name
  method = definition.methods[method_name]
  if method
    RBS.logger.debug { "Type checking `#{self_class}#{format_method_name(method_name)}`..."}
    errors = check.overloaded_call(method, format_method_name(method_name), trace, errors: [])

    if errors.empty?
      RBS.logger.debug { "No type error detected 👏" }
    else
      RBS.logger.debug { "Detected type error 🚨" }
      raise TypeError.new(errors)
    end
  else
    RBS.logger.error { "Type checking `#{self_class}#{method_name}` call but no method found in definition" }
  end
end

#checkObject



129
130
131
# File 'lib/rbs/test/tester.rb', line 129

def check
  @check ||= TypeCheck.new(self_class: self_class, builder: builder, sample_size: sample_size, unchecked_classes: unchecked_classes)
end

#envObject



125
126
127
# File 'lib/rbs/test/tester.rb', line 125

def env
  builder.env
end

#format_method_name(name) ⇒ Object



133
134
135
136
137
138
139
140
# File 'lib/rbs/test/tester.rb', line 133

def format_method_name(name)
  case kind
  when :instance
    "##{name}"
  when :singleton
    ".#{name}"
  end
end