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:) ⇒ MethodCallTester

Returns a new instance of MethodCallTester.



71
72
73
74
75
76
77
# File 'lib/rbs/test/tester.rb', line 71

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

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



67
68
69
# File 'lib/rbs/test/tester.rb', line 67

def builder
  @builder
end

#definitionObject (readonly)

Returns the value of attribute definition.



66
67
68
# File 'lib/rbs/test/tester.rb', line 66

def definition
  @definition
end

#kindObject (readonly)

Returns the value of attribute kind.



68
69
70
# File 'lib/rbs/test/tester.rb', line 68

def kind
  @kind
end

#sample_sizeObject (readonly)

Returns the value of attribute sample_size.



69
70
71
# File 'lib/rbs/test/tester.rb', line 69

def sample_size
  @sample_size
end

#self_classObject (readonly)

Returns the value of attribute self_class.



65
66
67
# File 'lib/rbs/test/tester.rb', line 65

def self_class
  @self_class
end

Instance Method Details

#call(receiver, trace) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/rbs/test/tester.rb', line 96

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



83
84
85
# File 'lib/rbs/test/tester.rb', line 83

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

#envObject



79
80
81
# File 'lib/rbs/test/tester.rb', line 79

def env
  builder.env
end

#format_method_name(name) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/rbs/test/tester.rb', line 87

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