4#include <gtest/gtest.h>
5#include <gmock/gmock.h>
19 class LibExprTest :
public LibStoreTest {
21 static void SetUpTestSuite() {
22 LibStoreTest::SetUpTestSuite();
29 , state({}, store, fetchSettings, evalSettings,
nullptr)
31 evalSettings.nixPath = {};
35 Expr * e = state.parseExprFromString(input, state.rootPath(CanonPath::root));
39 state.forceValue(v, noPos);
44 Expr * e = state.parseExprFromString(input, state.rootPath(CanonPath::root));
46 return e->maybeThunk(state, state.baseEnv);
50 return state.symbols.create(
value);
53 bool readOnlyMode =
true;
59 MATCHER(IsListType,
"") {
64 return arg.type() == nList;
67 MATCHER(IsString,
"") {
68 return arg.type() == nString;
72 return arg.type() == nNull;
75 MATCHER(IsThunk,
"") {
76 return arg.type() == nThunk;
79 MATCHER(IsAttrs,
"") {
80 return arg.type() == nAttrs;
83 MATCHER_P(IsStringEq,
s,
fmt(
"The string is equal to \"%1%\"",
s)) {
84 if (arg.type() != nString) {
87 return std::string_view(arg.c_str()) ==
s;
90 MATCHER_P(IsIntEq, v,
fmt(
"The string is equal to \"%1%\"", v)) {
91 if (arg.type() != nInt) {
94 return arg.integer().value == v;
97 MATCHER_P(IsFloatEq, v,
fmt(
"The float is equal to \"%1%\"", v)) {
98 if (arg.type() != nFloat) {
101 return arg.fpoint() == v;
104 MATCHER(IsTrue,
"") {
105 if (arg.type() != nBool) {
108 return arg.boolean() ==
true;
111 MATCHER(IsFalse,
"") {
112 if (arg.type() != nBool) {
115 return arg.boolean() ==
false;
118 MATCHER_P(IsPathEq,
p,
fmt(
"Is a path equal to \"%1%\"",
p)) {
119 if (arg.type() != nPath) {
120 *result_listener <<
"Expected a path got " << arg.type();
123 auto path = arg.path();
125 *result_listener <<
"Expected a path that equals \"" <<
p <<
"\" but got: " << path.path;
133 MATCHER_P(IsListOfSize, n,
fmt(
"Is a list of size [%1%]", n)) {
134 if (arg.type() != nList) {
135 *result_listener <<
"Expected list got " << arg.type();
137 }
else if (arg.listSize() != (
size_t)n) {
138 *result_listener <<
"Expected as list of size " << n <<
" got " << arg.listSize();
144 MATCHER_P(IsAttrsOfSize, n,
fmt(
"Is a set of size [%1%]", n)) {
145 if (arg.type() != nAttrs) {
146 *result_listener <<
"Expected set got " << arg.type();
148 }
else if (arg.attrs()->size() != (
size_t) n) {
149 *result_listener <<
"Expected a set with " << n <<
" attributes but got " << arg.attrs()->size();
Definition canon-path.hh:41
Definition symbol-table.hh:58
std::string fmt(const std::string &s)
Definition fmt.hh:67
return s
Definition lexer.l:459
std::shared_ptr< T > p
Definition lexer.l:1269
const T & value
Definition lexer.l:492
void forceValue(Value &v, const PosIdx pos)
Definition eval-settings.hh:13
Definition fetch-settings.hh:15