Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new 'str' functionality #54

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion shublang/shublang.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 21 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down