From 773438d8aef3b4d45a1ee8f29e2855461ca4d518 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 13 Aug 2023 12:23:19 +0000 Subject: [PATCH] feat: accept plain functions for std.native outputs --- --- a/crates/jrsonnet-stdlib/src/lib.rs +++ b/crates/jrsonnet-stdlib/src/lib.rs @@ -237,7 +237,7 @@ /// Used for `std.extVar` pub ext_vars: HashMap, /// Used for `std.native` - pub ext_natives: HashMap>>, + pub ext_natives: HashMap, /// Used for `std.trace` pub trace_printer: Box, /// Used for `std.thisFile` --- /dev/null +++ b/tests/tests/std_native.rs @@ -0,0 +1,21 @@ +use jrsonnet_evaluator::{function::builtin, trace::PathResolver, State}; +use jrsonnet_stdlib::ContextInitializer; + +#[builtin] +fn example_native(a: u32, b: u32) -> u32 { + a + b +} + +#[test] +fn std_native() { + let state = State::default(); + let std = ContextInitializer::new(state.clone(), PathResolver::Absolute); + std.add_native("example", example_native::INST); + state.set_context_initializer(std); + + assert!(state + .evaluate_snippet("test", "std.native('example')(1, 3) == 4") + .unwrap() + .as_bool() + .expect("boolean output")); +} -- gitstuff