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

Added Identity function #61

Merged
merged 2 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion shublang/shublang.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def decode(iterable, encoding):
@Pipe
def find(iterable, sub, start=None, end=None):
"""Returns the lowest index in the string where the sub is found.
If specified, the start and end params serve to slice the string
If specified, the start and end params serve to slice the string
where sub should be searched.

:param iterable: collection of data to transform
Expand Down Expand Up @@ -332,6 +332,11 @@ def extract_currency(iterable):
def urljoin(iterable, base):
return (parse.urljoin(base, url) for url in iterable)

@Pipe
def identity(iterable, element):
""" Return the same element is passed as parameter."""
return element
VMRuiz marked this conversation as resolved.
Show resolved Hide resolved


filter = where
map = select
Expand Down
24 changes: 24 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,27 @@ def test_join(test_input, expected):
)
def test_urljoin(test_input, expected):
assert evaluate(*test_input) == expected

@pytest.mark.parametrize(
"test_input,expected",
[
(
['identity(True)',
[10, 'far', ['boo', 3]]],
True,
),
(
['identity("InStock")',
["In Stock.", "Only 3 in Stock", "Stock Ok"]],
"InStock",
),
(
['identity((1,2,3,4,5))',
"foo"],
(1,2,3,4,5),
),
]
)

def test_identity(test_input, expected):
assert evaluate(*test_input) == expected