string slice

This commit is contained in:
Jesse Bannon 2023-12-06 23:56:03 -08:00
parent 81034af97a
commit da182e0ebf
2 changed files with 20 additions and 0 deletions

View file

@ -16,6 +16,15 @@ class StringFunctions:
"""
return String(value=str(value.value))
@staticmethod
def slice(string: String, start: Integer, end: Optional[Integer] = None) -> String:
"""
Returns the slice of the Array.
"""
if end is not None:
return String(string.value[start.value : end.value])
return String(string.value[start.value :])
@staticmethod
def lower(string: String) -> String:
"""

View file

@ -98,3 +98,14 @@ class TestNumericFunctions:
def test_pad_zero(self, values: str, expected_output: str):
output = single_variable_output(f"{{%pad_zero({values})}}")
assert output == expected_output
@pytest.mark.parametrize(
"values, expected_output",
[
("'2012', 2", "12"),
("'2012', 1, 3", "01"),
],
)
def test_slice(self, values, expected_output):
output = single_variable_output(f"{{%slice({values})}}")
assert output == expected_output