-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathApprovalTestTests.cpp
59 lines (50 loc) · 1.96 KB
/
ApprovalTestTests.cpp
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
// begin-snippet: ut_main
#define APPROVALS_UT
#include "ApprovalTests.hpp"
// end-snippet
int main()
{
using namespace boost::ut;
using namespace ApprovalTests;
auto directory = Approvals::useApprovalsSubdirectory("approval_tests");
// begin-snippet: ut_main_usage
"ItCanVerifyAFile"_test = []() {
Approvals::verify("Approval Tests can verify text via the golden master method");
};
// end-snippet
test("AnotherWayItCanVerifyAFile") = []() {
Approvals::verify("Approval Tests can verify text via the golden master method");
};
// begin-snippet: ut_main_multiple
"ItCanUseMultipleVerify"_test = []() {
{
// Here we simulate test sections, so that Approval Tests uses different
// output file names for the different verify() calls.
auto section = NamerFactory::appendToOutputFilename("section 1");
Approvals::verify("Approval Tests can verify text via the golden master method");
}
{
auto section = NamerFactory::appendToOutputFilename("section 2");
Approvals::verify("Approval Tests can verify different text via the golden master method");
}
};
// end-snippet
"YouCanUseAWriter"_test = []() {
// begin-snippet: ut_use_custom_writer
using HtmlWriter = StringWriter;
HtmlWriter writer("<h1>hello world</h1>", ".html");
Approvals::verify(writer);
// end-snippet
};
"YouCanSpecifyYourFileExtension"_test = []() {
// begin-snippet: ut_use_custom_file_extension
Approvals::verifyWithExtension("<h1>hello world</h1>", ".html");
// end-snippet
};
"YouCanSpecifyYourFileExtensionWithToString"_test = []() {
Approvals::verifyWithExtension(1337, ".csv");
};
"YouCanSpecifyYourFileExtensionWithFormatter"_test = []() {
Approvals::verifyWithExtension(1337, [](auto value, auto& os) {os << "**value:** " << value; }, ".md");
};
}