diff options
author | TechSY730 <csyoung@google.com> | 2019-09-17 09:21:44 -0500 |
---|---|---|
committer | c-parsons <cparsons@google.com> | 2019-09-17 10:21:44 -0400 |
commit | 3154dbbc41da755a345afd8545e3152726e17c16 (patch) | |
tree | 40a69ea94ebe9b8920cf63a40e5a7fae4b4494f5 /tests | |
parent | 58068fe0cc28d8d5e0115bf0e7d80189628f35db (diff) | |
download | bazel-skylib-3154dbbc41da755a345afd8545e3152726e17c16.tar.gz |
Add types.is_set() to test whether an arbitrary object is a set as defined by new_sets.bzl. (#181)
* Add sets.is_set() to test whether an arbitrary object is a set.
Since using sets requires special API, it can be useful to determine
whether an object is a set so special handling can be used.
For example, if a method wants to be able to take a list or a set.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/types_tests.bzl | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/types_tests.bzl b/tests/types_tests.bzl index 6681d1c..aaf7cab 100644 --- a/tests/types_tests.bzl +++ b/tests/types_tests.bzl @@ -15,6 +15,7 @@ load("//lib:types.bzl", "types") load("//lib:unittest.bzl", "asserts", "unittest") +load("//lib:new_sets.bzl", "sets") def _a_function(): """A dummy function for testing.""" @@ -215,6 +216,21 @@ def _is_depset_test(ctx): is_depset_test = unittest.make(_is_depset_test) +def _is_set_test(ctx): + """Unit test for types.is_set.""" + env = unittest.begin(ctx) + + asserts.true(env, types.is_set(sets.make())) + asserts.true(env, types.is_set(sets.make([1]))) + asserts.false(env, types.is_set(None)) + asserts.false(env, types.is_set({})) + asserts.false(env, types.is_set(struct(foo = 1))) + asserts.false(env, types.is_set(struct(_values = "not really values"))) + + return unittest.end(env) + +is_set_test = unittest.make(_is_set_test) + def types_test_suite(): """Creates the test targets and test suite for types.bzl tests.""" unittest.suite( @@ -228,4 +244,5 @@ def types_test_suite(): is_dict_test, is_function_test, is_depset_test, + is_set_test, ) |