forked from nix-community/nixd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValue.cpp
64 lines (46 loc) · 1.43 KB
/
Value.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "StateTest.h"
#include "nixt/Value.h"
using namespace nixt;
namespace {
struct ValueTest : StateTest {
nix::SourcePath cwd() { return State->rootPath("."); }
};
TEST_F(ValueTest, IsOption_neg) {
nix::Expr *AST = State->parseExprFromString("1", cwd());
nix::Value V;
State->eval(AST, V);
ASSERT_FALSE(isOption(*State, V));
}
TEST_F(ValueTest, IsOption_pos) {
nix::Expr *AST =
State->parseExprFromString(R"({ _type = "option"; })", cwd());
nix::Value V;
State->eval(AST, V);
ASSERT_TRUE(isOption(*State, V));
}
TEST_F(ValueTest, IsDerivation_neg) {
nix::Expr *AST =
State->parseExprFromString(R"({ _type = "option"; })", cwd());
nix::Value V;
State->eval(AST, V);
ASSERT_FALSE(isDerivation(*State, V));
}
TEST_F(ValueTest, IsDerivation_pos) {
nix::Expr *AST =
State->parseExprFromString(R"({ type = "derivation"; })", cwd());
nix::Value V;
State->eval(AST, V);
ASSERT_TRUE(isDerivation(*State, V));
}
TEST_F(ValueTest, selectAttrPath) {
nix::Expr *AST = State->parseExprFromString(R"({ a.b.c.d = 1; })", cwd());
nix::Value V;
State->eval(AST, V);
nix::Value &Nested = selectStringViews(*State, V, {"a", "b"});
// Make sure no extra "force" performed.
ASSERT_EQ(Nested.type(), nix::ValueType::nThunk);
nix::Value &Kern = selectStringViews(*State, Nested, {"c", "d"});
ASSERT_EQ(Kern.type(), nix::ValueType::nInt);
ASSERT_EQ(Kern.integer(), nix::NixInt{1});
}
} // namespace