add tests for optionalValueAt

This commit is contained in:
HaeNoe 2024-04-14 22:36:03 +02:00
parent bb939d3772
commit ff4c286e80
No known key found for this signature in database

View file

@ -160,4 +160,16 @@ TEST(getBoolean, wrongAssertions) {
ASSERT_THROW(getBoolean(valueAt(json, "int")), Error);
}
TEST(optionalValueAt, existing) {
auto json = R"({ "string": "ssh-rsa" })"_json;
ASSERT_EQ(optionalValueAt(json, "string"), std::optional { "ssh-rsa" });
}
TEST(optionalValueAt, empty) {
auto json = R"({})"_json;
ASSERT_EQ(optionalValueAt(json, "string2"), std::nullopt);
}
} /* namespace nix */