more tests
This commit is contained in:
parent
d135f603c0
commit
afe45e2dda
2 changed files with 16 additions and 8 deletions
|
|
@ -58,9 +58,6 @@ class CustomFunction(Function, NamedCustomFunction):
|
||||||
resolved_variables: Dict[Variable, Resolvable],
|
resolved_variables: Dict[Variable, Resolvable],
|
||||||
custom_functions: Dict[str, "VariableDependency"],
|
custom_functions: Dict[str, "VariableDependency"],
|
||||||
) -> Resolvable:
|
) -> Resolvable:
|
||||||
if NamedCustomFunction(name=self.name) in self.custom_functions:
|
|
||||||
raise CycleDetected("ackkk!")
|
|
||||||
|
|
||||||
resolved_args: List[Resolvable] = [
|
resolved_args: List[Resolvable] = [
|
||||||
self._resolve_argument_type(
|
self._resolve_argument_type(
|
||||||
arg=arg, resolved_variables=resolved_variables, custom_functions=custom_functions
|
arg=arg, resolved_variables=resolved_variables, custom_functions=custom_functions
|
||||||
|
|
@ -74,11 +71,14 @@ class CustomFunction(Function, NamedCustomFunction):
|
||||||
|
|
||||||
resolved_variables_with_args = copy.deepcopy(resolved_variables)
|
resolved_variables_with_args = copy.deepcopy(resolved_variables)
|
||||||
for i, arg in enumerate(resolved_args):
|
for i, arg in enumerate(resolved_args):
|
||||||
function_arg = FunctionArgument.from_idx(
|
function_arg = FunctionArgument.from_idx(idx=i, custom_function_name=self.name)
|
||||||
idx=i, custom_function_name=self.name
|
|
||||||
) # Function args are 0-based
|
if function_arg in resolved_variables_with_args:
|
||||||
# if function_arg in resolved_variables_with_args:
|
# function args should always be unique since they are only defined once
|
||||||
# raise StringFormattingException("nested custom functions???")
|
# in the custom function as %custom_function_name___idx
|
||||||
|
# and returned as a set from each custom function.
|
||||||
|
raise UNREACHABLE
|
||||||
|
|
||||||
resolved_variables_with_args[function_arg] = arg
|
resolved_variables_with_args[function_arg] = arg
|
||||||
|
|
||||||
return custom_functions[self.name].resolve(
|
return custom_functions[self.name].resolve(
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,14 @@ class TestFunction:
|
||||||
):
|
):
|
||||||
Script({"dne": "{%throw}"}).resolve()
|
Script({"dne": "{%throw}"}).resolve()
|
||||||
|
|
||||||
|
def test_custom_function_use_input_param_multiple_times(self):
|
||||||
|
assert Script(
|
||||||
|
{
|
||||||
|
"%custom_square": "{%mul($0, $0)}",
|
||||||
|
"output": "{%custom_square(3)}",
|
||||||
|
}
|
||||||
|
).resolve() == {"output": Integer(9)}
|
||||||
|
|
||||||
def test_custom_function_cycle(self):
|
def test_custom_function_cycle(self):
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
CycleDetected, match=re.escape("The custom function %cycle_func cannot call itself.")
|
CycleDetected, match=re.escape("The custom function %cycle_func cannot call itself.")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue