about summary refs log tree commit diff
path: root/tvix/eval/builtin-macros/tests/tests.rs
blob: 4713743e52958a9d2bc9895ac19dd4c971d46cb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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"),
    }
}