Skip to content

Commit b0242cf

Browse files
committed
Add explicit Value(const char*) constructor
1 parent b8d3e59 commit b0242cf

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ if(BUILD_TESTS OR UPDATE_SAMPLES)
138138
add_test(NAME PegtlCase
139139
COMMAND tests --gtest_filter=PegtlCase.*
140140
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
141+
add_test(NAME ResponseCase
142+
COMMAND tests --gtest_filter=ResponseCase.*
143+
WORKING_DIRECTORY $<TARGET_FILE_DIR:tests>)
141144
endif()
142145

143146
if(UPDATE_SAMPLES)

GraphQLResponse.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ Value::~Value()
4444
// omitted, declare it explicitly and define it in graphqlservice.
4545
}
4646

47+
Value::Value(const char* value)
48+
: _type(Type::String)
49+
, _string(new StringType(value))
50+
{
51+
}
52+
4753
Value::Value(StringType&& value)
4854
: _type(Type::String)
4955
, _string(new StringType(std::move(value)))

include/graphqlservice/GraphQLResponse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct Value
4444
Value(Type type = Type::Null);
4545
~Value();
4646

47+
explicit Value(const char* value);
4748
explicit Value(StringType&& value);
4849
explicit Value(BooleanType value);
4950
explicit Value(IntType value);

tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,3 +1624,12 @@ TEST(PegtlCase, AnalyzeGrammar)
16241624
{
16251625
ASSERT_EQ(0, analyze<document>(true)) << "there shuldn't be any infinite loops in the PEG version of the grammar";
16261626
}
1627+
1628+
TEST(ResponseCase, ValueConstructorFromStringLiteral)
1629+
{
1630+
auto expected = "Test String";
1631+
auto actual = response::Value(expected);
1632+
1633+
ASSERT_TRUE(response::Type::String == actual.type());
1634+
ASSERT_EQ(expected, actual.release<response::StringType>());
1635+
}

0 commit comments

Comments
 (0)