From c73172e9864dbb0b38e480c9e284245bbbd616e7 Mon Sep 17 00:00:00 2001 From: HaeNoe Date: Tue, 16 Apr 2024 13:37:39 +0200 Subject: [PATCH] add unit tests for `getNullable` --- tests/unit/libutil/json-utils.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/unit/libutil/json-utils.cc b/tests/unit/libutil/json-utils.cc index ec653fff5..c9370a74b 100644 --- a/tests/unit/libutil/json-utils.cc +++ b/tests/unit/libutil/json-utils.cc @@ -169,7 +169,19 @@ TEST(optionalValueAt, existing) { TEST(optionalValueAt, empty) { auto json = R"({})"_json; - ASSERT_EQ(optionalValueAt(json, "string2"), std::nullopt); + ASSERT_EQ(optionalValueAt(json, "string"), std::nullopt); +} + +TEST(getNullable, null) { + auto json = R"(null)"_json; + + ASSERT_EQ(getNullable(json), std::nullopt); +} + +TEST(getNullable, empty) { + auto json = R"({})"_json; + + ASSERT_EQ(getNullable(json), std::optional { R"({})"_json }); } } /* namespace nix */