#include "lix/libexpr/attr-path.hh" #include "lix/libexpr/attr-set.hh" #include "tests/libexpr.hh" #include #include #include #include #include namespace nix { class AttrPathEval : public LibExprTest { public: std::pair testFindAlongAttrPath(std::string expr, std::string path); }; RC_GTEST_PROP(AttrPath, prop_round_trip, ()) { auto strings = *rc::gen::container>( rc::gen::container(rc::gen::distinctFrom('"')) ); auto const unparsed = unparseAttrPath(strings); auto const unparsedReparsed = parseAttrPath(unparsed); RC_ASSERT(strings == unparsedReparsed); } std::pair AttrPathEval::testFindAlongAttrPath(std::string expr, std::string path) { auto v = eval(expr); auto bindings = evalState().ctx.buildBindings(0).finish(); return findAlongAttrPath(state, path, *bindings, v); } // n.b. I do not know why we throw for empty attrs but they are apparently // disallowed. TEST_F(AttrPathEval, emptyAttrsThrows) { std::string expr = "{a.\"\".b = 2;}"; ASSERT_NO_THROW(testFindAlongAttrPath(expr, "a")); ASSERT_THROW(testFindAlongAttrPath(expr, "a.\"\".b"), Error); ASSERT_THROW(testFindAlongAttrPath(expr, "a.\"\""), Error); } }