Page MenuHomec4science

yaml.cpp
No OneTemporary

File Metadata

Created
Wed, Aug 28, 05:51

yaml.cpp

#include <catch.hpp>
#include "utils/io/yaml.hpp"
using namespace specmicp::io;
const char* yaml_input =
R"(
---
section1:
{key1: value1, key2: 2, key3: true}
section2:
key4: value4
)";
TEST_CASE("YAML RO", "[yaml],[io]") {
SECTION("Parsing") {
auto file = RORichYAMLNode::parse_yaml_string(yaml_input);
CHECK(file.check("section1"));
CHECK(file.check("section2"));
CHECK(not file.check("section4"));
file.check_mandatory("section1");
RORichYAMLNode section1 = file["section1"];
CHECK_THROWS(file["section4"]);
const YAML::Node& node = section1.get_raw_node();
CHECK(node.IsSequence() == false);
CHECK(node.IsMap() == true);
std::string test = section1.get_mandatory<std::string>("key1");
CHECK(test == "value1");
CHECK(section1.get_mandatory<int>("key2") == 2);
CHECK(section1.get_mandatory<bool>("key3") == true);
CHECK(section1.get_optional<std::string>("keyopt", "opt") == "opt");
RORichYAMLNode section2 = file["section2"];
CHECK(section2.get_optional<std::string>("key4", "foo") == "value4");
}
}

Event Timeline