From d00d33b116f4499d3699a78a5d9e0ca92a1e0936 Mon Sep 17 00:00:00 2001 From: Selina Delgado Date: Thu, 14 Mar 2024 13:55:10 -0700 Subject: [PATCH 1/2] tests for LiteralBoolean --- python/selfie-lib/tests/LiteralBoolean_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 python/selfie-lib/tests/LiteralBoolean_test.py diff --git a/python/selfie-lib/tests/LiteralBoolean_test.py b/python/selfie-lib/tests/LiteralBoolean_test.py new file mode 100644 index 00000000..4a578eac --- /dev/null +++ b/python/selfie-lib/tests/LiteralBoolean_test.py @@ -0,0 +1,18 @@ +def _encode(value: bool, expected: str): + actual = "true" if value else "false" + assert actual == expected, f"Expected: {expected}, Got: {actual}" + + +def _decode(value: str, expected: bool): + actual = value.lower() == "true" + assert actual == expected, f"Expected: {expected}, Got: {actual}" + + +class TestLiteralBoolean: + def test_encode(self): + _encode(True, "true") + _encode(False, "false") + + def test_decode(self): + _decode("true", True) + _decode("false", False) From 961de074376dcfb93b3530415a216625d4cb1f66 Mon Sep 17 00:00:00 2001 From: Selina Delgado Date: Thu, 14 Mar 2024 14:38:11 -0700 Subject: [PATCH 2/2] updated tests --- python/selfie-lib/tests/LiteralBoolean_test.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/python/selfie-lib/tests/LiteralBoolean_test.py b/python/selfie-lib/tests/LiteralBoolean_test.py index 4a578eac..ef84b987 100644 --- a/python/selfie-lib/tests/LiteralBoolean_test.py +++ b/python/selfie-lib/tests/LiteralBoolean_test.py @@ -1,17 +1,25 @@ +from selfie_lib.Literals import LiteralBoolean, Language +from selfie_lib.EscapeLeadingWhitespace import EscapeLeadingWhitespace + + def _encode(value: bool, expected: str): - actual = "true" if value else "false" + literal_boolean = LiteralBoolean() + actual = literal_boolean.encode( + value, Language.PYTHON, EscapeLeadingWhitespace.NEVER + ) assert actual == expected, f"Expected: {expected}, Got: {actual}" def _decode(value: str, expected: bool): - actual = value.lower() == "true" + literal_boolean = LiteralBoolean() + actual = literal_boolean.parse(value, Language.PYTHON) assert actual == expected, f"Expected: {expected}, Got: {actual}" class TestLiteralBoolean: def test_encode(self): - _encode(True, "true") - _encode(False, "false") + _encode(True, "True") + _encode(False, "False") def test_decode(self): _decode("true", True)