mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 16:39:08 +01:00
Added a PluginTest method that will call custom_value_to_base_value (#12502)
# Description Added a method for getting the base value for a PluginCustomValue. cc: @devyn --------- Co-authored-by: Jack Wright <jack.wright@disqo.com>
This commit is contained in:
parent
10a9a17b8c
commit
040f10e19d
@ -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<Value, ShellError> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user