Skip to content

Add tests for YAML 1.2 specification examples - #1493

Open
alex-thiessen-for-siemens wants to merge 43 commits into
jbeder:masterfrom
alex-thiessen-for-siemens:yaml12-spec-examples
Open

alex-thiessen-for-siemens wants to merge 43 commits into
jbeder:masterfrom
alex-thiessen-for-siemens:yaml12-spec-examples

Conversation

@alex-thiessen-for-siemens

Copy link
Copy Markdown
Contributor

Summary

  • Add node and event-handler coverage for the remaining YAML 1.2 specification examples.
  • Extend the shared specification fixtures used by the integration tests.
  • Keep the coverage organized by specification example so each case is traceable to the YAML 1.2 text.

Testing

  • CMake/CTest suite passes with 1,110 tests.

Closes #38

@alex-thiessen-for-siemens
alex-thiessen-for-siemens marked this pull request as ready for review September 8, 2026 10:05
Comment thread test/integration/handler_spec_test.cpp
Correct the expected trailing line breaks for Examples 8.5 and 8.21 in
both specification test layers. These parser results already match the
YAML 1.2.2 examples, so the tests no longer need to be disabled.

Reference verification: not applicable. This contribution records YAML
1.2 specification examples. No external semantic oracle is required.
Cover Example 2.19 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 2.20 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 2.21 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 2.22 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.1 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.1 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.2 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.2 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.9 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.9 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.10 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 5.10 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.1 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.1 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.2 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.2 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.3 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.3 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.4 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.4 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.5 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.5 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.6 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 9.6 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.1 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.1 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.2 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.2 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.3 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.3 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.4 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.4 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.5 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.5 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.6 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.6 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.7 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.7 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.8 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.8 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.9 in the event-handler specification test suite and
introduce its canonical YAML fixture.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.
Cover Example 10.9 in the node specification test suite.

Reference verification: not applicable - this contribution records YAML
1.2 specification examples; no external semantic oracle is required.

@SGSSGene SGSSGene left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank your for this PR, this is highly appriciated.

To get a better grip on all the changes I added ':+1:` everypart that I agree with.

I did found a few things, to make them find them easier, a list them here explicitly:

  • Waiting for resolution of Ex8_21_BlockScalarNodes (or we put a SPEC GAP marker here or similar)
  • ex9_1 is not correct
  • Unclear if DISABLED_Ex10_8_JsonTagResolution test is correct
  • TEST_F(NodeSpecTest, Ex10_1_MapExamples) not testing everything
  • TEST(NodeSpecTest, Ex10_2_SequenceExamples) not testing everything

}

// TODO: 5.1 - 5.2 BOM
TEST_F(HandlerSpecTest, Ex5_1_ByteOrderMark) { Parse(ex5_1); }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 (I will mark every test that I have checked, to keep an overview)

TEST_F(HandlerSpecTest, Ex5_1_ByteOrderMark) { Parse(ex5_1); }

TEST_F(HandlerSpecTest, Ex5_2_InvalidByteOrderMark) {
EXPECT_THROW(IgnoreParse(ex5_2), ParserException);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread test/specexamples.h
Comment on lines +329 to +335
const char *ex5_9 =
"%YAML 1.2\n"
"--- text";

const char *ex5_10 =
"commercial-at: @text\n"
"grave-accent: `text";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread test/specexamples.h
Comment on lines +289 to +296
const char *ex5_1 =
"\xEF\xBB\xBF"
"# Comment only.";

const char *ex5_2 =
"- Invalid use of BOM\n"
"\xEF\xBB\xBF"
"- Inside a document.";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +724 to +729
TEST_F(HandlerSpecTest, Ex5_9_DirectiveIndicator) {
EXPECT_CALL(handler, OnDocumentStart(_));
EXPECT_CALL(handler, OnScalar(_, "?", 0, "text"));
EXPECT_CALL(handler, OnDocumentEnd());
Parse(ex5_9);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +1258 to +1263
TEST(NodeSpecTest, Ex10_5_BooleanExamples) {
Node doc = Load(ex10_5);
EXPECT_TRUE(doc["YAML is a superset of JSON"].as<bool>());
EXPECT_FALSE(doc["Pluto is a planet"].as<bool>());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +1264 to +1269
TEST(NodeSpecTest, Ex10_6_IntegerExamples) {
Node doc = Load(ex10_6);
EXPECT_EQ(-12, doc["negative"].as<int>());
EXPECT_EQ(0, doc["zero"].as<int>());
EXPECT_EQ(34, doc["positive"].as<int>());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +1271 to +1279
TEST(NodeSpecTest, Ex10_7_FloatingPointExamples) {
Node doc = Load(ex10_7);
EXPECT_DOUBLE_EQ(-1.0, doc["negative"].as<double>());
EXPECT_DOUBLE_EQ(0.0, doc["zero"].as<double>());
EXPECT_DOUBLE_EQ(23000.0, doc["positive"].as<double>());
EXPECT_TRUE(std::isinf(doc["infinity"].as<double>()));
EXPECT_GT(doc["infinity"].as<double>(), 0.0);
EXPECT_TRUE(std::isnan(doc["not a number"].as<double>()));
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


TEST(NodeSpecTest, DISABLED_Ex10_8_JsonTagResolution) {
// SPEC_GAP: yaml-cpp uses the YAML 1.1-compatible resolver for several
// values that YAML 1.2 JSON resolution leaves as strings.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only real issue here is IsNull isn't it?

because as<bool> could just be as<std::string> as well.

Comment thread test/specexamples.h
const char *ex5_1 =
"\xEF\xBB\xBF"
"# Comment only.";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full test suite for the YAML 1.2 spec

2 participants