e34833c025
This: - Converts a bunch of C style casts into C++ casts. - Removes some very silly pointer subtraction code (which is no more or less busted on i686 than it began) - Fixes some "technically UB" that never had to be UB in the first place. - Makes finally follow the noexcept status of the inner function. Maybe in the future we should ban the function from not being noexcept, but that is not today. - Makes various locally-used exceptions inherit from std::exception. Change-Id: I22e66972602604989b5e494fd940b93e0e6e9297
43 lines
1,014 B
C++
43 lines
1,014 B
C++
#include "closure.hh"
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace nix {
|
|
|
|
using namespace std;
|
|
|
|
map<string, set<string>> 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<string> expectedClosure = {"A", "B", "C", "F", "G"};
|
|
set<string> aClosure = computeClosure<string>(
|
|
{"A"},
|
|
[&](const string currentNode) {
|
|
return testGraph[currentNode];
|
|
}
|
|
);
|
|
|
|
ASSERT_EQ(aClosure, expectedClosure);
|
|
}
|
|
|
|
TEST(closure, properlyHandlesDirectExceptions) {
|
|
struct TestExn : std::exception {};
|
|
EXPECT_THROW(
|
|
computeClosure<string>(
|
|
{"A"},
|
|
[&](const string currentNode) -> set<string> {
|
|
throw TestExn();
|
|
}
|
|
),
|
|
TestExn
|
|
);
|
|
}
|
|
|
|
}
|