* Support comparisons between floats and ints.
This commit is contained in:
+14
-6
@@ -338,12 +338,20 @@ class TreeProcessor(lark.visitors.Interpreter):
|
||||
if operand1 is None or operand2 is None:
|
||||
self.warn_or_stop(f"Undefined value used in comparison: '{escape_single_quotes(desc)}'")
|
||||
return False
|
||||
if (
|
||||
isinstance(operand1, (str, int, float, bool))
|
||||
and isinstance(operand2, (str, int, float, bool))
|
||||
and operand1.__class__ != operand2.__class__
|
||||
):
|
||||
self.warn_or_stop(f"Mixed type values used in comparison: '{escape_single_quotes(desc)}'")
|
||||
compatible_types = [
|
||||
(str, str),
|
||||
(int, int),
|
||||
(float, float),
|
||||
(bool, bool),
|
||||
(int, float),
|
||||
(float, int),
|
||||
(str, list),
|
||||
(int, list),
|
||||
(float, list),
|
||||
(bool, list),
|
||||
]
|
||||
if not any(isinstance(operand1, t1) and isinstance(operand2, t2) for t1, t2 in compatible_types):
|
||||
self.warn_or_stop(f"Mixed type values ({type(operand1).__name__}, {type(operand2).__name__}) used in comparison: '{escape_single_quotes(desc)}'")
|
||||
return False
|
||||
return operation(operand1, operand2)
|
||||
|
||||
|
||||
@@ -195,6 +195,15 @@ class TestVarCommands(TestPromptPostProcessorBase):
|
||||
variables={"v1[]": "val1, val2, val3", "v1[#]": "3"},
|
||||
)
|
||||
|
||||
def test_array_variable_10(self): # array variable set with expanded values from wildcards in command format
|
||||
self.process(
|
||||
PromptPair(
|
||||
"<ppp:set v1[]>*__yaml/wildcard1__<ppp:/set><ppp:set v1[] add>*__yaml/wildcard2__<ppp:/set>${v1[2]:defval}",
|
||||
"",
|
||||
),
|
||||
PromptPair("choice3", ""),
|
||||
variables={"v1[]": "choice2, choice1, choice3, choice1"},
|
||||
)
|
||||
|
||||
# Operator tests
|
||||
|
||||
@@ -632,6 +641,18 @@ class TestVarCommands(TestPromptPostProcessorBase):
|
||||
PromptPair("OK", ""),
|
||||
)
|
||||
|
||||
# Float values
|
||||
|
||||
def test_float_value(self):
|
||||
self.process(
|
||||
PromptPair(
|
||||
"${a=1.5}<ppp:if a gt 1>OK<ppp:else>not OK<ppp:/if>",
|
||||
"",
|
||||
),
|
||||
PromptPair("OK", ""),
|
||||
)
|
||||
|
||||
|
||||
# NaN/undefined variable integer comparison tests
|
||||
|
||||
def test_cmd_if_undefined_var_int_compare_warn(self): # undefined var integer compare with on_warning=warn
|
||||
|
||||
Reference in New Issue
Block a user