blob: cc973ead02efe8392dcb0eba6d82a8aba3c221ba [file] [log] [blame]
onqtam4a655632016-05-26 14:20:52 +03001#include "doctest.h"
2
onqtam7cc0e962017-04-17 23:30:36 +03003#include "header.h"
4
onqtamabf39d22017-10-28 21:30:45 +03005DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_BEGIN
onqtam4a655632016-05-26 14:20:52 +03006#include <iostream>
7#include <vector>
8using namespace std;
onqtamabf39d22017-10-28 21:30:45 +03009DOCTEST_MAKE_STD_HEADERS_CLEAN_FROM_WARNINGS_ON_WALL_END
onqtam4a655632016-05-26 14:20:52 +030010
onqtam4a655632016-05-26 14:20:52 +030011TEST_CASE("lots of nested subcases") {
12 cout << endl << "root" << endl;
13 SUBCASE("") {
14 cout << "1" << endl;
15 SUBCASE("") { cout << "1.1" << endl; }
16 }
17 SUBCASE("") {
18 cout << "2" << endl;
19 SUBCASE("") { cout << "2.1" << endl; }
20 SUBCASE("") {
21 // whops! all the subcases below shouldn't be discovered and executed!
onqtam7cc0e962017-04-17 23:30:36 +030022 FAIL("");
onqtam4a655632016-05-26 14:20:52 +030023
24 cout << "2.2" << endl;
25 SUBCASE("") {
26 cout << "2.2.1" << endl;
27 SUBCASE("") { cout << "2.2.1.1" << endl; }
28 SUBCASE("") { cout << "2.2.1.2" << endl; }
29 }
30 }
31 SUBCASE("") { cout << "2.3" << endl; }
32 SUBCASE("") { cout << "2.4" << endl; }
33 }
34}
35
onqtam378d6702017-04-19 11:30:03 +030036static void call_func() {
onqtam5dbcb1e2017-05-02 23:07:56 +030037 SUBCASE("from function...") {
38 MESSAGE("print me twice");
39 SUBCASE("sc1") {
40 MESSAGE("hello! from sc1");
41 }
42 SUBCASE("sc2") {
43 MESSAGE("hello! from sc2");
44 }
onqtam378d6702017-04-19 11:30:03 +030045 }
46}
47
48TEST_CASE("subcases can be used in a separate function as well") {
49 call_func();
onqtama82c1e42017-05-07 17:36:41 +030050 MESSAGE("lala");
onqtam378d6702017-04-19 11:30:03 +030051}
52
onqtam4a655632016-05-26 14:20:52 +030053SCENARIO("vectors can be sized and resized") {
54 GIVEN("A vector with some items") {
55 std::vector<int> v(5);
56
onqtamf90739e2016-09-14 01:01:45 +030057 REQUIRE(v.size() == 5);
58 REQUIRE(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030059
60 WHEN("the size is increased") {
onqtamf90739e2016-09-14 01:01:45 +030061 v.resize(10);
onqtam4a655632016-05-26 14:20:52 +030062
63 THEN("the size and capacity change") {
onqtamf90739e2016-09-14 01:01:45 +030064 CHECK(v.size() == 20);
65 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030066 }
67 }
68 WHEN("the size is reduced") {
69 v.resize(0);
70
71 THEN("the size changes but not capacity") {
onqtamf90739e2016-09-14 01:01:45 +030072 CHECK(v.size() == 0);
73 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030074 }
75 }
76 WHEN("more capacity is reserved") {
77 v.reserve(10);
78
79 THEN("the capacity changes but not the size") {
onqtamf90739e2016-09-14 01:01:45 +030080 CHECK(v.size() == 5);
81 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030082 }
83 }
84 WHEN("less capacity is reserved") {
85 v.reserve(0);
86
87 THEN("neither size nor capacity are changed") {
onqtamf90739e2016-09-14 01:01:45 +030088 CHECK(v.size() == 10);
89 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030090 }
91 }
92 }
93}