2023-05-31 14:26:46 +01:00
|
|
|
#include "test/type_graph_utils.h"
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "oi/ContainerInfo.h"
|
|
|
|
#include "oi/type_graph/PassManager.h"
|
|
|
|
#include "oi/type_graph/Printer.h"
|
|
|
|
#include "oi/type_graph/TypeGraph.h"
|
|
|
|
|
|
|
|
using type_graph::Container;
|
|
|
|
using type_graph::Pass;
|
|
|
|
using type_graph::Type;
|
|
|
|
using type_graph::TypeGraph;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
using ref = std::reference_wrapper<T>;
|
|
|
|
|
|
|
|
void check(const std::vector<ref<Type>>& types,
|
|
|
|
std::string_view expected,
|
|
|
|
std::string_view comment) {
|
|
|
|
std::stringstream out;
|
2023-06-23 12:46:52 +01:00
|
|
|
type_graph::Printer printer(out, types.size());
|
2023-05-31 14:26:46 +01:00
|
|
|
|
|
|
|
for (const auto& type : types) {
|
|
|
|
printer.print(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
expected.remove_prefix(1); // Remove initial '\n'
|
2023-06-20 17:57:43 +01:00
|
|
|
ASSERT_EQ(expected, out.str()) << "Test failure " << comment;
|
2023-05-31 14:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test(type_graph::Pass pass,
|
|
|
|
std::vector<ref<Type>> rootTypes,
|
|
|
|
std::string_view expectedBefore,
|
|
|
|
std::string_view expectedAfter) {
|
2023-06-23 12:43:30 +01:00
|
|
|
if (expectedBefore.data()) {
|
|
|
|
check(rootTypes, expectedBefore, "before running pass");
|
|
|
|
}
|
2023-05-31 14:26:46 +01:00
|
|
|
|
|
|
|
TypeGraph typeGraph;
|
|
|
|
for (const auto& type : rootTypes) {
|
|
|
|
typeGraph.addRoot(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
pass.run(typeGraph);
|
|
|
|
|
2023-06-23 12:43:30 +01:00
|
|
|
// Must use typeGraph's root types here, as the pass may have modified them
|
|
|
|
check(typeGraph.rootTypes(), expectedAfter, "after running pass");
|
2023-05-31 14:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void test(type_graph::Pass pass,
|
|
|
|
std::vector<ref<Type>> rootTypes,
|
|
|
|
std::string_view expectedAfter) {
|
2023-06-23 12:43:30 +01:00
|
|
|
test(pass, rootTypes, {}, expectedAfter);
|
2023-05-31 14:26:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Container getVector() {
|
|
|
|
static ContainerInfo info{"std::vector", SEQ_TYPE, "vector"};
|
|
|
|
info.stubTemplateParams = {1};
|
|
|
|
return Container{info, 24};
|
|
|
|
}
|