1
0
Эх сурвалжийг харах

add few test cases for bool (#3949)

* add few test cases for bool

* use parametrize

* use a tuple of strings

Co-authored-by: Masen Furer <m_github@0x26.net>

---------

Co-authored-by: Masen Furer <m_github@0x26.net>
Khaleel Al-Adhami 8 сар өмнө
parent
commit
a8734d7392
1 өөрчлөгдсөн 15 нэмэгдсэн , 0 устгасан
  1. 15 0
      tests/test_var.py

+ 15 - 0
tests/test_var.py

@@ -958,6 +958,21 @@ def test_all_number_operations():
     )
 
 
+@pytest.mark.parametrize(
+    ("var", "expected"),
+    [
+        (Var.create(False), "false"),
+        (Var.create(True), "true"),
+        (Var.create("false"), '("false".split("").length !== 0)'),
+        (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():
     array_var = LiteralArrayVar.create([1, 2, 3, 4, 5])
     assert str(array_var[0]) == "[1, 2, 3, 4, 5].at(0)"