mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
Improve the unsafeGetAttrPos test
We can use corepkgsFS->addFile() now to create a "real" position.
This commit is contained in:
parent
1f93fa2ed2
commit
19ec1c9fd4
1 changed files with 20 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "memory-input-accessor.hh"
|
||||||
|
|
||||||
#include "tests/libexpr.hh"
|
#include "tests/libexpr.hh"
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
@ -148,10 +150,25 @@ namespace nix {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PrimOpTest, unsafeGetAttrPos) {
|
TEST_F(PrimOpTest, unsafeGetAttrPos) {
|
||||||
// The `y` attribute is at position
|
state.corepkgsFS->addFile(CanonPath("foo.nix"), "{ y = \"x\"; }");
|
||||||
const char* expr = "builtins.unsafeGetAttrPos \"y\" { y = \"x\"; }";
|
|
||||||
|
auto expr = "builtins.unsafeGetAttrPos \"y\" (import <nix/foo.nix>)";
|
||||||
auto v = eval(expr);
|
auto v = eval(expr);
|
||||||
ASSERT_THAT(v, IsNull());
|
ASSERT_THAT(v, IsAttrsOfSize(3));
|
||||||
|
|
||||||
|
auto file = v.attrs->find(createSymbol("file"));
|
||||||
|
ASSERT_NE(file, nullptr);
|
||||||
|
ASSERT_THAT(*file->value, IsString());
|
||||||
|
auto s = baseNameOf(file->value->string_view());
|
||||||
|
ASSERT_EQ(s, "foo.nix");
|
||||||
|
|
||||||
|
auto line = v.attrs->find(createSymbol("line"));
|
||||||
|
ASSERT_NE(line, nullptr);
|
||||||
|
ASSERT_THAT(*line->value, IsIntEq(1));
|
||||||
|
|
||||||
|
auto column = v.attrs->find(createSymbol("column"));
|
||||||
|
ASSERT_NE(column, nullptr);
|
||||||
|
ASSERT_THAT(*column->value, IsIntEq(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PrimOpTest, hasAttr) {
|
TEST_F(PrimOpTest, hasAttr) {
|
||||||
|
|
Loading…
Reference in a new issue