2022-11-06 16:07:46 +01:00
|
|
|
pub use tvix_eval::internal;
|
|
|
|
pub use tvix_eval::Value;
|
2022-11-06 00:50:31 +01:00
|
|
|
use tvix_eval_builtin_macros::builtins;
|
|
|
|
|
|
|
|
#[builtins]
|
|
|
|
mod builtins {
|
2022-11-06 16:07:46 +01:00
|
|
|
use tvix_eval::internal::VM;
|
|
|
|
use tvix_eval::{ErrorKind, Value};
|
2022-11-06 00:50:31 +01:00
|
|
|
|
2022-12-19 11:23:51 +01:00
|
|
|
/// Test docstring.
|
|
|
|
///
|
|
|
|
/// It has multiple lines!
|
2022-11-06 00:50:31 +01:00
|
|
|
#[builtin("identity")]
|
|
|
|
pub fn builtin_identity(_vm: &mut VM, x: Value) -> Result<Value, ErrorKind> {
|
|
|
|
Ok(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[builtin("tryEval")]
|
|
|
|
pub fn builtin_try_eval(_: &mut VM, #[lazy] _x: Value) -> Result<Value, ErrorKind> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn builtins() {
|
|
|
|
let builtins = builtins::builtins();
|
|
|
|
assert_eq!(builtins.len(), 2);
|
2022-11-06 16:46:56 +01:00
|
|
|
|
|
|
|
let identity = builtins.iter().find(|b| b.name() == "identity").unwrap();
|
2022-12-19 11:23:51 +01:00
|
|
|
assert_eq!(
|
|
|
|
identity.documentation(),
|
|
|
|
Some(
|
|
|
|
r#" Test docstring.
|
|
|
|
|
|
|
|
It has multiple lines!"#
|
|
|
|
)
|
|
|
|
);
|
2022-11-06 00:50:31 +01:00
|
|
|
}
|