summaryrefslogtreecommitdiff
path: root/vendor/bandit/specs/matchers/contain.cpp
blob: 2c0b4b3b338bfac296136677dce4891d1c2efbe3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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