diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /vendor/bandit/specs/matchers/contain.cpp | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'vendor/bandit/specs/matchers/contain.cpp')
-rw-r--r-- | vendor/bandit/specs/matchers/contain.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/vendor/bandit/specs/matchers/contain.cpp b/vendor/bandit/specs/matchers/contain.cpp new file mode 100644 index 00000000..2c0b4b3b --- /dev/null +++ b/vendor/bandit/specs/matchers/contain.cpp @@ -0,0 +1,156 @@ +#include <set> + +#include <specs/specs.h> + +using namespace bandit::Matchers; + +SPEC_BEGIN(Matchers::Contain) + +describe("contain matcher", [&]{ + std::string element0("element0"); + std::string element1("element1"); + + describe("when the container is an STL vector", [&]{ + describe("which contains the element", [&]{ + std::vector<std::string> container {element0, element1}; + + it("must pass a positive match", [&]{ + container must contain(element1); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element1); }()); + }); + }); + + describe("which does not contain the element", [&]{ + std::vector<int> container; + + it("must pass a negative match", [&]{ + container must_not contain(4); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(4); }()); + }); + }); + }); + + describe("when the container is an STL map", [&]{ + describe("which contains the expected key", [&]{ + std::map<int, int> container {{5, 6}, {7,10}}; + + it("must pass a positive match", [&]{ + container must contain(5); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(5); }()); + }); + }); + + describe("which does not contain the expected value", [&]{ + std::map<int, int> container; + + it("must pass a negative match", [&]{ + container must_not contain(6); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(6); }()); + }); + }); + }); + + describe("when the container is an STL set", [&]{ + describe("which contains the element", [&]{ + std::set<int> container {5, 7}; + + it("must pass a positive match", [&]{ + container must contain(7); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(7); }()); + }); + }); + + describe("which does not contain the element", [&]{ + std::set<int> container; + + it("must pass a negative match", [&]{ + container must_not contain(7); + }); + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(7); }()); + }); + }); + }); + + describe("when the container is a C string", [&]{ + describe("which is null", [&]{ + char* container = NULL; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain("foo"); }()); + }); + }); + + describe("which contains the substring", [&]{ + char* container = (char*)"jack and jill"; + char* element = (char*)"jack"; + + it("must pass a positive match", [&]{ + container must contain(element); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element); }()); + }); + }); + + describe("which does not contain the substring", [&]{ + char* container = (char*)"batman and robin"; + char* element = (char*)"catwoman"; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(element); }()); + }); + + it("must pass a negative match", [&]{ + container must_not contain(element); + }); + }); + }); + + describe("when the container is a const C string", [&]{ + describe("which contains the substring", [&]{ + const char* container = (char*)"jack and jill"; + const char* element = (char*)"jack"; + + it("must pass a positive match", [&]{ + container must contain(element); + }); + + it("must reject a negative match", [&]{ + AssertThrows(std::exception, [&]{ container must_not contain(element); }()); + }); + }); + + describe("which does not contain the substring", [&]{ + const char* container = (char*)"batman and robin"; + const char* element = (char*)"catwoman"; + + it("must reject a positive match", [&]{ + AssertThrows(std::exception, [&]{ container must contain(element); }()); + }); + + it("must pass a negative match", [&]{ + container must_not contain(element); + }); + }); + }); +}); + +SPEC_END |