Skip to content

Commit

Permalink
Add support for repr/str to new_sets (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaclach authored and allevato committed May 4, 2018
1 parent 809940b commit 4eb28c4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/new_sets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ def _length(s):
"""
return len(s._values)

def _repr(s):
"""Returns a string value representing the set.
Args:
s: A set, as returned by `sets.make()`.
Returns:
A string representing the set.
"""
return repr(s._values.keys())


sets = struct(
make = _make,
Expand All @@ -235,4 +246,6 @@ sets = struct(
difference = _difference,
length = _length,
remove = _remove,
repr = _repr,
str = _repr,
)
19 changes: 19 additions & 0 deletions tests/new_sets_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@ def _remove_test(ctx):

remove_test = unittest.make(_remove_test)


def _repr_str_test(ctx):
"""Unit test for new_sets.repr and new_sets.str."""
env = unittest.begin(ctx)

asserts.equals(env, "[]", new_sets.repr(new_sets.make()))
asserts.equals(env, "[1]", new_sets.repr(new_sets.make([1])))
asserts.equals(env, "[1, 2]", new_sets.repr(new_sets.make([1, 2])))

asserts.equals(env, "[]", new_sets.str(new_sets.make()))
asserts.equals(env, "[1]", new_sets.str(new_sets.make([1])))
asserts.equals(env, "[1, 2]", new_sets.str(new_sets.make([1, 2])))

unittest.end(env)

repr_str_test = unittest.make(_repr_str_test)


def new_sets_test_suite():
"""Creates the test targets and test suite for new_sets.bzl tests."""
unittest.suite(
Expand All @@ -263,4 +281,5 @@ def new_sets_test_suite():
contains_test,
length_test,
remove_test,
repr_str_test,
)

0 comments on commit 4eb28c4

Please sign in to comment.