mirror of
https://github.com/nushell/nushell
synced 2025-01-14 22:24:54 +00: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
1 changed files with 15 additions and 1 deletions
|
@ -8,7 +8,8 @@ use nu_plugin::{Plugin, PluginCommand, PluginCustomValue, PluginSource};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
debugger::WithoutDebug,
|
debugger::WithoutDebug,
|
||||||
engine::{EngineState, Stack, StateWorkingSet},
|
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};
|
use crate::{diff::diff_by_line, fake_register::fake_register};
|
||||||
|
@ -345,4 +346,17 @@ impl PluginTest {
|
||||||
_ => Ok(a == b),
|
_ => 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 a new issue