#include "closure.hh" #include namespace nix { using namespace std; map> testGraph = { { "A", { "B", "C", "G" } }, { "B", { "A" } }, // Loops back to A { "C", { "F" } }, // Indirect reference { "D", { "A" } }, // Not reachable, but has backreferences { "E", {} }, // Just not reachable { "F", {} }, { "G", { "G" } }, // Self reference }; TEST(closure, correctClosure) { set expectedClosure = {"A", "B", "C", "F", "G"}; set aClosure = computeClosure( {"A"}, [&](const string currentNode) { return testGraph[currentNode]; } ); ASSERT_EQ(aClosure, expectedClosure); } TEST(closure, properlyHandlesDirectExceptions) { struct TestExn {}; EXPECT_THROW( computeClosure( {"A"}, [&](const string currentNode) -> set { throw TestExn(); } ), TestExn ); } }