forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCtorConfigTest.cpp
More file actions
89 lines (76 loc) · 2.77 KB
/
CtorConfigTest.cpp
File metadata and controls
89 lines (76 loc) · 2.77 KB
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "hermes/Public/CtorConfig.h"
#include "gtest/gtest.h"
namespace {
#define TEST_FIELDS(F) \
F(constexpr, int, AAA, 0) \
\
F(constexpr, bool, BBB, false) \
\
F(, const char *, CCC, "abc") \
/* TEST_FIELDS END */
_HERMES_CTORCONFIG_STRUCT(TestConfig, TEST_FIELDS, {})
TEST(CtorConfigTest, testDefaults) {
static_assert(TestConfig::getDefaultAAA() == 0, "unexpected default");
static_assert(TestConfig::getDefaultBBB() == false, "unexpected default");
// Not constexpr.
EXPECT_STREQ("abc", TestConfig::getDefaultCCC());
}
TEST(CtorConfigTest, testBasic) {
TestConfig testConfig =
TestConfig::Builder().withAAA(1).withBBB(true).build();
EXPECT_EQ(1, testConfig.getAAA());
EXPECT_TRUE(testConfig.getBBB());
EXPECT_STREQ("abc", testConfig.getCCC());
}
TEST(CtorConfigTest, testOverride) {
TestConfig testConfig =
TestConfig::Builder().withAAA(1).withBBB(true).build();
testConfig = testConfig.rebuild()
.update(TestConfig::Builder().withAAA(2).withCCC("xyz"))
.build();
EXPECT_EQ(2, testConfig.getAAA());
EXPECT_TRUE(testConfig.getBBB());
EXPECT_STREQ("xyz", testConfig.getCCC());
}
#define TEST_FIELDS2(F) \
F(constexpr, int, MMM, 100) \
\
F(, TestConfig, NestedConfig) \
/* TEST_FIELDS2 END */
_HERMES_CTORCONFIG_STRUCT(TestConfigWithNesting, TEST_FIELDS2, {})
TEST(CtorConfigTest, testBasicNested) {
TestConfigWithNesting testConfig =
TestConfigWithNesting::Builder()
.withMMM(200)
.withNestedConfig(TestConfig::Builder().withCCC("pqr").build())
.build();
EXPECT_EQ(200, testConfig.getMMM());
EXPECT_FALSE(testConfig.getNestedConfig().getBBB());
EXPECT_STREQ("pqr", testConfig.getNestedConfig().getCCC());
}
TEST(CtorConfigTest, testOverrideNested) {
TestConfigWithNesting testConfig =
TestConfigWithNesting::Builder()
.withMMM(200)
.withNestedConfig(TestConfig::Builder().withCCC("pqr").build())
.build();
testConfig =
testConfig.rebuild()
.update(
TestConfigWithNesting::Builder().withMMM(300).withNestedConfig(
testConfig.getNestedConfig()
.rebuild()
.update(TestConfig::Builder().withCCC("def"))
.build()))
.build();
EXPECT_EQ(300, testConfig.getMMM());
EXPECT_FALSE(testConfig.getNestedConfig().getBBB());
EXPECT_STREQ("def", testConfig.getNestedConfig().getCCC());
}
} // end anonymous namespace