diff --git a/crates/nu-plugin-test-support/src/plugin_test.rs b/crates/nu-plugin-test-support/src/plugin_test.rs index 18872af44d..3f9326a33b 100644 --- a/crates/nu-plugin-test-support/src/plugin_test.rs +++ b/crates/nu-plugin-test-support/src/plugin_test.rs @@ -8,7 +8,8 @@ use nu_plugin::{Plugin, PluginCommand, PluginCustomValue, PluginSource}; use nu_protocol::{ debugger::WithoutDebug, engine::{EngineState, Stack, StateWorkingSet}, - report_error_new, Example, LabeledError, PipelineData, ShellError, Span, Value, + report_error_new, CustomValue, Example, IntoSpanned as _, LabeledError, PipelineData, + ShellError, Span, Value, }; use crate::{diff::diff_by_line, fake_register::fake_register}; @@ -345,4 +346,17 @@ impl PluginTest { _ => Ok(a == b), } } + + /// This implements custom value comparison with `plugin.custom_value_to_base_value()` to behave + /// as similarly as possible to comparison in the engine. + pub fn custom_value_to_base_value( + &self, + val: &dyn CustomValue, + span: Span, + ) -> Result { + let mut serialized = PluginCustomValue::serialize_from_custom_value(val, span)?; + serialized.set_source(Some(self.source.clone())); + let persistent = self.source.persistent(None)?.get_plugin(None)?; + persistent.custom_value_to_base_value(serialized.into_spanned(span)) + } }