tvl-depot/tvix/eval/builtin-macros/tests/tests.rs
Florian Klink d3ecef1a5b refactor(tvix/eval): address clippy lints
Change-Id: Ic2bd4e8291b30ceac9fa0e88a4f56e61ae99b603
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10227
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
2023-12-09 12:58:39 +00:00

45 lines
1 KiB
Rust

pub use tvix_eval::{Builtin, Value};
use tvix_eval_builtin_macros::builtins;
#[builtins]
mod builtins {
use tvix_eval::generators::{Gen, GenCo};
use tvix_eval::{ErrorKind, Value};
/// Test docstring.
///
/// It has multiple lines!
#[builtin("identity")]
pub async fn builtin_identity(co: GenCo, x: Value) -> Result<Value, ErrorKind> {
Ok(x)
}
#[builtin("tryEval")]
pub async fn builtin_try_eval(_co: GenCo, #[lazy] _x: Value) -> Result<Value, ErrorKind> {
unimplemented!("builtin is never called")
}
}
#[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"),
}
}