From ff4c286e8006e3d13da67076e973badf78edf22b Mon Sep 17 00:00:00 2001 From: HaeNoe Date: Sun, 14 Apr 2024 22:36:03 +0200 Subject: [PATCH] add tests for `optionalValueAt` --- tests/unit/libutil/json-utils.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/libutil/json-utils.cc b/tests/unit/libutil/json-utils.cc index ffa667806..ec653fff5 100644 --- a/tests/unit/libutil/json-utils.cc +++ b/tests/unit/libutil/json-utils.cc @@ -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 */