upgrade gut

This commit is contained in:
anyreso 2026-02-19 03:14:22 -05:00
parent 6e724f67fe
commit 82aeebfd35
201 changed files with 8547 additions and 3871 deletions

View file

@ -1,77 +1,83 @@
var thepath = ''
var subpath = ''
var stubber = null
var spy = null
var gut = null
var from_singleton = null
var singleton_name = null
var is_partial = null
var double = null
var double_ref : WeakRef = null
var stubber_ref : WeakRef = null
var spy_ref : WeakRef = null
var gut_ref : WeakRef = null
var singleton_ref : WeakRef = null
var __gutdbl_values = {}
const NO_DEFAULT_VALUE = '!__gut__no__default__value__!'
func _init(values=null):
if(values != null):
double = values.double
func _init(double = null):
if(double != null):
var values = double.__gutdbl_values
__gutdbl_values = double.__gutdbl_values
double_ref = weakref(double)
thepath = values.thepath
subpath = values.subpath
stubber = from_id(values.stubber)
spy = from_id(values.spy)
gut = from_id(values.gut)
from_singleton = values.from_singleton
stubber_ref = weakref_from_id(values.stubber)
spy_ref = weakref_from_id(values.spy)
gut_ref = weakref_from_id(values.gut)
singleton_ref = weakref_from_id(values.singleton)
singleton_name = values.singleton_name
is_partial = values.is_partial
if(gut != null):
gut.get_autofree().add_free(double)
if(gut_ref.get_ref() != null):
gut_ref.get_ref().get_autofree().add_free(double_ref.get_ref())
func _get_stubbed_method_to_call(method_name, called_with):
var method = stubber.get_call_this(double, method_name, called_with)
var method = stubber_ref.get_ref().get_call_this(double_ref.get_ref(), method_name, called_with)
if(method != null):
method = method.bindv(called_with)
return method
return method
func from_id(inst_id):
func weakref_from_id(inst_id):
if(inst_id == -1):
return null
return weakref(null)
else:
return instance_from_id(inst_id)
return weakref(instance_from_id(inst_id))
func is_stubbed_to_call_super(method_name, called_with):
if(stubber != null):
return stubber.should_call_super(double, method_name, called_with)
if(stubber_ref.get_ref() != null):
return stubber_ref.get_ref().should_call_super(double_ref.get_ref(), method_name, called_with)
else:
return false
func handle_other_stubs(method_name, called_with):
if(stubber == null):
if(stubber_ref.get_ref() == null):
return
var method = _get_stubbed_method_to_call(method_name, called_with)
if(method != null):
return await method.call()
else:
return stubber.get_return(double, method_name, called_with)
return stubber_ref.get_ref().get_return(double_ref.get_ref(), method_name, called_with)
func spy_on(method_name, called_with):
if(spy != null):
spy.add_call(double, method_name, called_with)
if(spy_ref.get_ref() != null):
spy_ref.get_ref().add_call(double_ref.get_ref(), method_name, called_with)
func default_val(method_name, p_index, default_val=NO_DEFAULT_VALUE):
if(stubber != null):
return stubber.get_default_value(double, method_name, p_index)
else:
func default_val(method_name, p_index):
if(stubber_ref.get_ref() == null):
return null
else:
var result = stubber_ref.get_ref().get_default_value(double_ref.get_ref(), method_name, p_index)
return result
func vararg_warning():
if(gut != null):
gut.get_logger().warn(
"This method contains a vararg argument and the paramter count was not stubbed. " + \
"GUT adds extra parameters to this method which should fill most needs. " + \
"It is recommended that you stub param_count for this object's class to ensure " + \
"that there are not any parameter count mismatch errors.")
func get_singleton():
var to_return = singleton_ref.get_ref()
if(to_return == null):
push_error("Trying to get a singleton reference on a non-singleton double: ",
__gutdbl_values.singleton_name, "/", __gutdbl_values.singleton)
return to_return