From 875126ae0a79c375a179e65cad8200c5d1069b77 Mon Sep 17 00:00:00 2001 From: Renan Cunha Date: Mon, 24 Aug 2020 13:38:54 -0300 Subject: [PATCH] add new 'str' functionality --- shublang/shublang.py | 6 +++++- tests/test_functions.py | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/shublang/shublang.py b/shublang/shublang.py index a15eb21..32f6b5a 100644 --- a/shublang/shublang.py +++ b/shublang/shublang.py @@ -231,6 +231,10 @@ def length(iterable): def bool(iterable): return (builtins.bool(x) for x in iterable) +@Pipe +def str(iterable): + return (builtins.str(x) for x in iterable) + @Pipe def float(iterable): return (builtins.float(x) for x in iterable) @@ -294,7 +298,7 @@ def date_format(iterable, fmt): @Pipe def extract_price(iterable): - return (str(Price.fromstring(item).amount) for item in iterable) + return (builtins.str(Price.fromstring(item).amount) for item in iterable) @Pipe def extract_currency(iterable): diff --git a/tests/test_functions.py b/tests/test_functions.py index fbfec7a..416dd8d 100644 --- a/tests/test_functions.py +++ b/tests/test_functions.py @@ -4,6 +4,27 @@ from shublang import evaluate +@pytest.mark.parametrize( + "test_input,expected", + [ + ( + ['str', [1, 2, 3]], + ['1', '2', '3'] + ), + ( + ['str', [1.1, 2.2, 3.3]], + ['1.1', '2.2', '3.3'] + ), + ( + ['str', ['1', '2', '3']], + ['1', '2', '3'] + ), + ] +) +def test_str(test_input, expected): + assert evaluate(*test_input) == expected + + @pytest.mark.parametrize( "test_input,expected", [