tvl-depot/tvix/eval/builtin-macros/tests/tests.rs
Vincent Ambo f12f938166 refactor(tvix/eval): directly return builtin tuples from macro
All invocations of the builtin macro had to previously filter through
the `builtin_tuple` function, but it's more sensible to directly
return these from the macro.

Change-Id: I45600ba84d56c9528d3e92570461c319eea595ce
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7825
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
2023-01-20 15:39:51 +00:00

44 lines
992 B
Rust

pub use tvix_eval::{Builtin, BuiltinArgument, Value, VM};
use tvix_eval_builtin_macros::builtins;
#[builtins]
mod builtins {
use tvix_eval::{ErrorKind, Value, VM};
/// Test docstring.
///
/// It has multiple lines!
#[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);
let (_, identity) = builtins
.iter()
.find(|(name, _)| *name == "identity")
.unwrap();
match identity {
Value::Builtin(identity) => assert_eq!(
identity.documentation(),
Some(
r#" Test docstring.
It has multiple lines!"#
)
),
_ => panic!("builtin was not a builtin"),
}
}