diff options
-rw-r--r-- | tvix/eval/src/builtins/mod.rs | 5 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp | 1 | ||||
-rw-r--r-- | tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix | 10 |
3 files changed, 16 insertions, 0 deletions
diff --git a/tvix/eval/src/builtins/mod.rs b/tvix/eval/src/builtins/mod.rs index 0b19a89aa316..cabdaf0070c7 100644 --- a/tvix/eval/src/builtins/mod.rs +++ b/tvix/eval/src/builtins/mod.rs @@ -100,6 +100,11 @@ fn pure_builtins() -> Vec<Builtin> { Ok(Value::List(NixList::construct(output.len(), output))) }), + Builtin::new("baseNameOf", &[true], |args: Vec<Value>, vm: &mut VM| { + let s = args[0].coerce_to_string(CoercionKind::Weak, vm)?; + let result: String = s.rsplit_once('/').map(|(_, x)| x).unwrap_or(&s).into(); + Ok(result.into()) + }), Builtin::new("bitAnd", &[true, true], |args: Vec<Value>, _: &mut VM| { Ok(Value::Integer(args[0].as_int()? & args[1].as_int()?)) }), diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp new file mode 100644 index 000000000000..60a773f4af69 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.exp @@ -0,0 +1 @@ +[ "bar" "foo" "" "bar" "." "" "" "" ] diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix new file mode 100644 index 000000000000..bc59613f541d --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-basenameof.nix @@ -0,0 +1,10 @@ +[ + (builtins.baseNameOf /foo/bar) + (builtins.baseNameOf "foo") + (builtins.baseNameOf "foo///") + (builtins.baseNameOf "foo/bar") + (builtins.baseNameOf "./.") + (builtins.baseNameOf "") + (builtins.baseNameOf /.) + (builtins.toString (builtins.baseNameOf /.)) +] |