Skip to content

Commit

Permalink
chore(test/integration): refactor some test cases to their own test.
Browse files Browse the repository at this point in the history
Plus, check that the content is what we actually expect.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP authored and jbeder committed Sep 13, 2024
1 parent 1f2b841 commit da82fd9
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions test/integration/load_node_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,30 +366,31 @@ TEST(NodeTest, LoadCommaSeparatedStrings) {
EXPECT_THROW(Load(R"("foo",)"), ParserException);
EXPECT_THROW(Load(R"(,"foo")"), ParserException);
EXPECT_THROW(Load(R"(,foo)"), ParserException);
}

const char *doc_ok = R"(
top
, aa
)";
EXPECT_NO_THROW(Load(doc_ok));

const char *doc_ok_2 = R"(
top
, "aa"
)";
EXPECT_NO_THROW(Load(doc_ok_2));

const char *doc_fail = R"(
"top"
, "aa"
)";
EXPECT_THROW(Load(doc_fail), ParserException);

const char *doc_fail_2 = R"(
"top"
, aa
)";
EXPECT_THROW(Load(doc_fail_2), ParserException);
struct NewLineStringsTestCase {
std::string input;
std::string expected_content;
bool should_throw;
};
TEST(NodeTest, LoadNewLineStrings) {
std::vector<NewLineStringsTestCase> tests = {
{"foo\n, bar", "foo , bar", false},
{"foo\n, \"bar\"", "foo , \"bar\"", false},
{"\"foo\"\n, \"bar\"", "", true},
{"\"foo\"\n, bar", "", true},
};
for (const NewLineStringsTestCase& test : tests) {
if (test.should_throw) {
EXPECT_THROW(Load(test.input), ParserException);
} else {
Node node = Load(test.input);
Emitter emitter;
emitter << node;
EXPECT_EQ(NodeType::Scalar, node.Type());
EXPECT_EQ(test.expected_content, std::string(emitter.c_str()));
}
}
}

TEST(NodeTest, LoadSameLineStrings) {
Expand Down

0 comments on commit da82fd9

Please sign in to comment.