-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathTemplatedCustomNamerExamples.cpp
37 lines (32 loc) · 1.45 KB
/
TemplatedCustomNamerExamples.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
#include "doctest/doctest.h"
#include "ApprovalTests/namers/TemplatedCustomNamer.h"
#include "ApprovalTests/Approvals.h"
TEST_CASE("Test StringTemplates")
{
// begin-snippet: templated_custom_namer_example
ApprovalTests::TemplatedCustomNamer namer(
"/my/source/directory/{ApprovedOrReceived}/"
"{TestFileName}.{TestCaseName}.{FileExtension}");
// end-snippet
CHECK(namer.getApprovedFileAsPath(".txt").toString("/") ==
"/my/source/directory/approved/"
"TemplatedCustomNamerExamples.Test_StringTemplates.txt");
CHECK(namer.getReceivedFileAsPath(".txt").toString("/") ==
"/my/source/directory/received/"
"TemplatedCustomNamerExamples.Test_StringTemplates.txt");
}
TEST_CASE("Test Namer Injection")
{
// clang-format off
// begin-snippet: templated_custom_namer_injection_via_options
auto namer = ApprovalTests::TemplatedCustomNamer::create(
"{TestSourceDirectory}/{ApprovalsSubdirectory}/CustomName.{ApprovedOrReceived}.{FileExtension}");
ApprovalTests::Approvals::verify("Hello", ApprovalTests::Options().withNamer(namer));
// end-snippet
// begin-snippet: templated_custom_namer_injection
auto default_namer_disposer = ApprovalTests::TemplatedCustomNamer::useAsDefaultNamer(
"{TestSourceDirectory}/{ApprovalsSubdirectory}/CustomName.{ApprovedOrReceived}.{FileExtension}");
// end-snippet
// clang-format on
ApprovalTests::Approvals::verify("Hello");
}