-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathOptionsTests.cpp
75 lines (62 loc) · 2.24 KB
/
OptionsTests.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "doctest/doctest.h"
#include "ApprovalTests/core/Options.h"
#include "ApprovalTests/reporters/QuietReporter.h"
#include "ApprovalTests/Approvals.h"
using namespace ApprovalTests;
namespace
{
void checkSameType(std::type_info const& type1,
std::type_info const& type2,
const std::string& message)
{
CHECK_MESSAGE(std::string(type1.name()) == std::string(type2.name()), message);
}
}
TEST_CASE("Options - Reporter features")
{
Options options;
const Reporter& initialReporter = options.getReporter();
checkSameType(typeid(initialReporter),
typeid(DefaultReporter),
"Initial reporter was not expected type");
// Check that setting the reporter gets back the same object
{
QuietReporter new_reporter;
const Options& options3 = options.withReporter(new_reporter);
const Reporter& reporter3 = options3.getReporter();
CHECK(&reporter3 == &new_reporter);
}
}
TEST_CASE("Options - FileExtension features")
{
Options options;
const Reporter& initialReporter = options.getReporter();
CHECK(options.fileOptions().getFileExtension() == ".txt");
CHECK(options.fileOptions()
.withFileExtension(".xyz")
.fileOptions()
.getFileExtension() == ".xyz");
// Check that setting the file extension does not change the reporter instance:
{
const Reporter& reporter2 =
options.fileOptions().withFileExtension(".abc").getReporter();
CHECK(&initialReporter == &reporter2);
}
}
TEST_CASE("copying")
{
// Options.with... returns new Options, containing new FileOptions
// Options.fileOptions()... returns local FileOptions - but with options poi
// Options.fileOptions().with... returns new Options containing new FileOptions
// FileOptions contains a non-owning pointer to its parent Options
Options o1;
Options o2 = o1;
Options::FileOptions fo = Options().fileOptions();
}
TEST_CASE("Options - FileExtension Example")
{
// begin-snippet: basic_approval_with_file_extension
Approvals::verify("text to be verified",
Options().fileOptions().withFileExtension(".xyz"));
// end-snippet
}