use is true for bool var (#3973)
This commit is contained in:
parent
dfad519bae
commit
73f3454b43
@ -194,14 +194,6 @@ class StringVar(Var[str]):
|
|||||||
"""
|
"""
|
||||||
return string_strip_operation(self)
|
return string_strip_operation(self)
|
||||||
|
|
||||||
def bool(self):
|
|
||||||
"""Boolean conversion.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
The boolean value of the string.
|
|
||||||
"""
|
|
||||||
return self.length() != 0
|
|
||||||
|
|
||||||
def reversed(self) -> StringVar:
|
def reversed(self) -> StringVar:
|
||||||
"""Reverse the string.
|
"""Reverse the string.
|
||||||
|
|
||||||
|
@ -962,6 +962,21 @@ def test_all_number_operations():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("var", "expected"),
|
||||||
|
[
|
||||||
|
(Var.create(False), "false"),
|
||||||
|
(Var.create(True), "true"),
|
||||||
|
(Var.create("false"), 'isTrue("false")'),
|
||||||
|
(Var.create([1, 2, 3]), "isTrue([1, 2, 3])"),
|
||||||
|
(Var.create({"a": 1, "b": 2}), 'isTrue(({ ["a"] : 1, ["b"] : 2 }))'),
|
||||||
|
(Var("mysterious_var"), "isTrue(mysterious_var)"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_boolify_operations(var, expected):
|
||||||
|
assert str(var.bool()) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_index_operation():
|
def test_index_operation():
|
||||||
array_var = LiteralArrayVar.create([1, 2, 3, 4, 5])
|
array_var = LiteralArrayVar.create([1, 2, 3, 4, 5])
|
||||||
assert str(array_var[0]) == "[1, 2, 3, 4, 5].at(0)"
|
assert str(array_var[0]) == "[1, 2, 3, 4, 5].at(0)"
|
||||||
|
Loading…
Reference in New Issue
Block a user