feat(tvix/eval): implement builtins.dirOf
This commit causes the test eval-okay-builtins.nix to pass. It also adds tests/tvix_tests/eval-okay-dirof.nix which has better coverage than the nix tests for this builtin. Signed-off-by: Adam Joseph <adam@westernsemico.com> Change-Id: I71d96b48680696fd6e4fea3a9861742b35cfaa66 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6987 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
d6088005ef
commit
caf9cbf711
4 changed files with 27 additions and 0 deletions
|
@ -194,6 +194,21 @@ fn pure_builtins() -> Vec<Builtin> {
|
|||
&[false, false],
|
||||
|args: Vec<Value>, vm: &mut VM| arithmetic_op!(&*args[0].force(vm)?, &*args[1].force(vm)?, /),
|
||||
),
|
||||
Builtin::new("dirOf", &[true], |args: Vec<Value>, vm: &mut VM| {
|
||||
let s = args[0].coerce_to_string(CoercionKind::Weak, vm)?;
|
||||
let result = s
|
||||
.rsplit_once('/')
|
||||
.map(|(x, _)| match x {
|
||||
"" => "/",
|
||||
_ => x,
|
||||
})
|
||||
.unwrap_or(".");
|
||||
if args[0].is_path() {
|
||||
Ok(Value::Path(result.into()))
|
||||
} else {
|
||||
Ok(result.into())
|
||||
}
|
||||
}),
|
||||
Builtin::new("elem", &[true, true], |args: Vec<Value>, vm: &mut VM| {
|
||||
for val in args[1].to_list()? {
|
||||
if val.nix_eq(&args[0], vm)? {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue