2024-06-24 20:33:12 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include "tests/libexpr.hh"
|
|
|
|
|
2024-11-12 23:07:17 +00:00
|
|
|
#include "lix/libexpr/nixexpr.hh"
|
|
|
|
#include "lix/libutil/ref.hh"
|
2024-06-24 20:33:12 +00:00
|
|
|
|
|
|
|
namespace nix
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace testing;
|
|
|
|
struct ExprPrintingTests : LibExprTest
|
|
|
|
{
|
|
|
|
void test(Expr const & expr, std::string_view expected)
|
|
|
|
{
|
|
|
|
std::stringstream out;
|
2024-12-03 19:38:41 +00:00
|
|
|
expr.show(evaluator.symbols, out);
|
2024-06-24 20:33:12 +00:00
|
|
|
ASSERT_EQ(out.str(), expected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(ExprPrintingTests, ExprInheritFrom)
|
|
|
|
{
|
|
|
|
// ExprInheritFrom has its own show() impl.
|
|
|
|
// If it uses its parent class's impl it will crash.
|
2024-12-03 19:38:41 +00:00
|
|
|
auto inheritSource = make_ref<ExprVar>(evaluator.symbols.create("stdenv"));
|
2024-06-24 20:33:12 +00:00
|
|
|
ExprInheritFrom const eInheritFrom(noPos, 0, inheritSource);
|
|
|
|
test(eInheritFrom, "(/* expanded inherit (expr) */ stdenv)");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|