mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 00:07:46 +02:00
Inc refactoring, Value helper test method extractions, and more integration helpers. (#1135)
* Manifests check. Ignore doctests for now. * We continue with refactorings towards the separation of concerns between crates. `nu_plugin_inc` and `nu_plugin_str` common test helpers usage has been refactored into `nu-plugin` value test helpers. Inc also uses the new API for integration tests.
This commit is contained in:
committed by
GitHub
parent
21e508009f
commit
0615adac94
@ -7,11 +7,8 @@ pub use strutils::Str;
|
||||
mod tests {
|
||||
use super::Str;
|
||||
use crate::strutils::Action;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{Primitive, ReturnSuccess, TaggedDictBuilder, UntaggedValue, Value};
|
||||
use nu_source::Tag;
|
||||
use nu_protocol::Value;
|
||||
use nu_value_ext::ValueExt;
|
||||
use num_bigint::BigInt;
|
||||
|
||||
impl Str {
|
||||
pub fn expect_action(&self, action: Action) {
|
||||
@ -38,51 +35,4 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_data(for_value: Value, key: &str) -> Value {
|
||||
for_value.get_data(&key.to_string()).borrow().clone()
|
||||
}
|
||||
|
||||
pub fn expect_return_value_at(
|
||||
for_results: Result<Vec<Result<ReturnSuccess, ShellError>>, ShellError>,
|
||||
at: usize,
|
||||
) -> Value {
|
||||
let return_values = for_results
|
||||
.expect("Failed! This seems to be an error getting back the results from the plugin.");
|
||||
|
||||
for (idx, item) in return_values.iter().enumerate() {
|
||||
let item = match item {
|
||||
Ok(return_value) => return_value,
|
||||
Err(reason) => panic!(format!("{}", reason)),
|
||||
};
|
||||
|
||||
if idx == at {
|
||||
return item.raw_value().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
panic!(format!(
|
||||
"Couldn't get return value from stream at {}. (There are {} items)",
|
||||
at,
|
||||
return_values.len() - 1
|
||||
))
|
||||
}
|
||||
|
||||
pub fn int(i: impl Into<BigInt>) -> Value {
|
||||
UntaggedValue::Primitive(Primitive::Int(i.into())).into_untagged_value()
|
||||
}
|
||||
|
||||
pub fn string(input: impl Into<String>) -> Value {
|
||||
UntaggedValue::string(input.into()).into_untagged_value()
|
||||
}
|
||||
|
||||
pub fn structured_sample_record(key: &str, value: &str) -> Value {
|
||||
let mut record = TaggedDictBuilder::new(Tag::unknown());
|
||||
record.insert_untagged(key.clone(), UntaggedValue::string(value));
|
||||
record.into_value()
|
||||
}
|
||||
|
||||
pub fn unstructured_sample_record(value: &str) -> Value {
|
||||
UntaggedValue::string(value).into_value(Tag::unknown())
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
mod integration {
|
||||
use crate::strutils::{Action, ReplaceAction};
|
||||
use crate::tests::{
|
||||
expect_return_value_at, get_data, int, string, structured_sample_record,
|
||||
use crate::Str;
|
||||
use nu_plugin::test_helpers::value::{
|
||||
column_path, get_data, int, string, structured_sample_record, table,
|
||||
unstructured_sample_record,
|
||||
};
|
||||
use crate::Str;
|
||||
use nu_plugin::test_helpers::{column_path, plugin, table, CallStub};
|
||||
use nu_plugin::test_helpers::{expect_return_value_at, plugin, CallStub};
|
||||
use nu_protocol::UntaggedValue;
|
||||
|
||||
#[test]
|
||||
@ -24,6 +24,7 @@ mod integration {
|
||||
assert_eq!(plugin.error, Some("can only apply one".to_string()));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picks_up_downcase_flag() {
|
||||
plugin(&mut Str::new())
|
||||
|
@ -2,7 +2,6 @@ use nu_errors::ShellError;
|
||||
use nu_protocol::{did_you_mean, ColumnPath, Primitive, ShellTypeName, UntaggedValue, Value};
|
||||
use nu_source::{span_for_spanned_list, Tagged};
|
||||
use nu_value_ext::ValueExt;
|
||||
|
||||
use regex::Regex;
|
||||
use std::cmp;
|
||||
|
||||
@ -206,42 +205,35 @@ impl Str {
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use super::{ReplaceAction, Str};
|
||||
use crate::tests::{int, string};
|
||||
use super::ReplaceAction;
|
||||
use super::Str;
|
||||
use nu_plugin::test_helpers::value::{int, string};
|
||||
|
||||
#[test]
|
||||
fn downcases() {
|
||||
let mut strutils = Str::new();
|
||||
|
||||
strutils.for_downcase();
|
||||
|
||||
assert_eq!(strutils.apply("ANDRES").unwrap(), string("andres").value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn upcases() {
|
||||
let mut strutils = Str::new();
|
||||
|
||||
strutils.for_upcase();
|
||||
|
||||
assert_eq!(strutils.apply("andres").unwrap(), string("ANDRES").value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn converts_to_int() {
|
||||
let mut strutils = Str::new();
|
||||
|
||||
strutils.for_to_int();
|
||||
|
||||
assert_eq!(strutils.apply("9999").unwrap(), int(9999 as i64).value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces() {
|
||||
let mut strutils = Str::new();
|
||||
|
||||
strutils.for_replace(ReplaceAction::Direct("robalino".to_string()));
|
||||
|
||||
assert_eq!(strutils.apply("andres").unwrap(), string("robalino").value);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user