Merge pull request #464 from djc/fmt

Fix formatting with cargo fmt
This commit is contained in:
Jonathan Turner 2019-08-27 07:12:18 +12:00 committed by GitHub
commit ca11dc2031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 148 additions and 181 deletions

View File

@ -35,8 +35,8 @@ crate mod pick;
crate mod plugin;
crate mod prev;
crate mod ps;
crate mod reverse;
crate mod reject;
crate mod reverse;
crate mod rm;
crate mod save;
crate mod shells;

View File

@ -2,7 +2,7 @@ use crate::commands::WholeStreamCommand;
use crate::object::base::OF64;
use crate::object::{Primitive, TaggedDictBuilder, Value};
use crate::prelude::*;
use bson::{decode_document, Bson, spec::BinarySubtype};
use bson::{decode_document, spec::BinarySubtype, Bson};
pub struct FromBSON;
@ -47,71 +47,72 @@ fn convert_bson_value_to_nu_value(v: &Bson, tag: impl Into<Tag>) -> Tagged<Value
Bson::Boolean(b) => Value::Primitive(Primitive::Boolean(*b)).tagged(tag),
Bson::Null => Value::Primitive(Primitive::String(String::from(""))).tagged(tag),
Bson::RegExp(r, opts) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$regex".to_string(),
Value::Primitive(Primitive::String(String::from(r))).tagged(tag),
);
collected.insert_tagged(
"$options".to_string(),
Value::Primitive(Primitive::String(String::from(opts))).tagged(tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$regex".to_string(),
Value::Primitive(Primitive::String(String::from(r))).tagged(tag),
);
collected.insert_tagged(
"$options".to_string(),
Value::Primitive(Primitive::String(String::from(opts))).tagged(tag),
);
collected.into_tagged_value()
}
Bson::I32(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag),
Bson::I64(n) => Value::Primitive(Primitive::Int(*n as i64)).tagged(tag),
Bson::JavaScriptCode(js) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.into_tagged_value()
}
Bson::JavaScriptCodeWithScope(js, doc) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.insert_tagged(
"$scope".to_string(),
convert_bson_value_to_nu_value(&Bson::Document(doc.to_owned()), tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$javascript".to_string(),
Value::Primitive(Primitive::String(String::from(js))).tagged(tag),
);
collected.insert_tagged(
"$scope".to_string(),
convert_bson_value_to_nu_value(&Bson::Document(doc.to_owned()), tag),
);
collected.into_tagged_value()
}
Bson::TimeStamp(ts) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$timestamp".to_string(),
Value::Primitive(Primitive::Int(*ts as i64)).tagged(tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$timestamp".to_string(),
Value::Primitive(Primitive::Int(*ts as i64)).tagged(tag),
);
collected.into_tagged_value()
}
Bson::Binary(bst, bytes) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$binary_subtype".to_string(),
match bst {
BinarySubtype::UserDefined(u) => Value::Primitive(Primitive::Int(*u as i64)),
_ => Value::Primitive(Primitive::String(binary_subtype_to_string(*bst))),
}.tagged(tag)
);
collected.insert_tagged(
"$binary".to_string(),
Value::Binary(bytes.to_owned()).tagged(tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$binary_subtype".to_string(),
match bst {
BinarySubtype::UserDefined(u) => Value::Primitive(Primitive::Int(*u as i64)),
_ => Value::Primitive(Primitive::String(binary_subtype_to_string(*bst))),
}
.tagged(tag),
);
collected.insert_tagged(
"$binary".to_string(),
Value::Binary(bytes.to_owned()).tagged(tag),
);
collected.into_tagged_value()
}
Bson::ObjectId(obj_id) => Value::Primitive(Primitive::String(obj_id.to_hex())).tagged(tag),
Bson::UtcDatetime(dt) => Value::Primitive(Primitive::Date(*dt)).tagged(tag),
Bson::Symbol(s) => {
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$symbol".to_string(),
Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
);
collected.into_tagged_value()
let mut collected = TaggedDictBuilder::new(tag);
collected.insert_tagged(
"$symbol".to_string(),
Value::Primitive(Primitive::String(String::from(s))).tagged(tag),
);
collected.into_tagged_value()
}
}
}
@ -125,7 +126,8 @@ fn binary_subtype_to_string(bst: BinarySubtype) -> String {
BinarySubtype::Uuid => "uuid",
BinarySubtype::Md5 => "md5",
_ => unreachable!(),
}.to_string()
}
.to_string()
}
#[derive(Debug)]

View File

@ -44,7 +44,7 @@ fn last(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, S
"Value is too low",
"expected a positive integer",
args.expect_nth(0)?.span(),
))
));
}
let stream = async_stream_block! {

View File

@ -426,14 +426,16 @@ pub fn parse_string_as_value(
name_span: Span,
) -> Result<Tagged<Value>, ShellError> {
match extension {
Some(x) if x == "csv" => crate::commands::from_csv::from_csv_string_to_value(
contents,
false,
contents_tag,
)
.map_err(move |_| {
ShellError::labeled_error("Could not open as CSV", "could not open as CSV", name_span)
}),
Some(x) if x == "csv" => {
crate::commands::from_csv::from_csv_string_to_value(contents, false, contents_tag)
.map_err(move |_| {
ShellError::labeled_error(
"Could not open as CSV",
"could not open as CSV",
name_span,
)
})
}
Some(x) if x == "toml" => {
crate::commands::from_toml::from_toml_string_to_value(contents, contents_tag).map_err(
move |_| {
@ -507,9 +509,9 @@ pub fn parse_binary_as_value(
crate::commands::from_bson::from_bson_bytes_to_value(contents, contents_tag).map_err(
move |_| {
ShellError::labeled_error(
"Could not open as BSON",
"could not open as BSON",
name_span,
"Could not open as BSON",
"could not open as BSON",
name_span,
)
},
)

View File

@ -46,9 +46,7 @@ fn sort_by(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream
.collect::<Vec<Option<Tagged<Value>>>>()
};
if reverse {
vec.sort_by_cached_key(|item| {
std::cmp::Reverse(calc_key(item))
});
vec.sort_by_cached_key(|item| std::cmp::Reverse(calc_key(item)));
} else {
vec.sort_by_cached_key(calc_key);
}

View File

@ -7,15 +7,13 @@ pub fn current_branch() -> Option<String> {
Ok(repo) => {
let r = repo.head();
match r {
Ok(r) => {
match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
}
Ok(r) => match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
},
_ => None
_ => None,
}
},
_ => None
}
_ => None,
}
}

View File

@ -122,10 +122,8 @@ impl Primitive {
pub fn style(&self) -> &'static str {
match self {
Primitive::Bytes(0) => "c", // centre 'missing' indicator
Primitive::Int(_) |
Primitive::Bytes(_) |
Primitive::Float(_) => "r",
_ => ""
Primitive::Int(_) | Primitive::Bytes(_) | Primitive::Float(_) => "r",
_ => "",
}
}
}
@ -472,7 +470,7 @@ impl Value {
crate fn style_leaf(&self) -> &'static str {
match self {
Value::Primitive(p) => p.style(),
_ => ""
_ => "",
}
}

View File

@ -105,7 +105,10 @@ impl FileStructure {
self.root = path.to_path_buf();
}
pub fn paths_applying_with<F>(&mut self, to: F) -> Result<Vec<(PathBuf, PathBuf)>, Box<dyn std::error::Error>>
pub fn paths_applying_with<F>(
&mut self,
to: F,
) -> Result<Vec<(PathBuf, PathBuf)>, Box<dyn std::error::Error>>
where
F: Fn((PathBuf, usize)) -> Result<(PathBuf, PathBuf), Box<dyn std::error::Error>>,
{
@ -175,7 +178,8 @@ mod tests {
fn prepares_and_decorates_source_files_for_copying() {
let mut res = FileStructure::new();
res.walk_decorate(fixtures().as_path()).expect("Can not decorate files traversal.");
res.walk_decorate(fixtures().as_path())
.expect("Can not decorate files traversal.");
assert_eq!(
res.resources,

View File

@ -25,7 +25,7 @@ fn accepts_and_creates_directories() {
let full_path = format!("{}/{}", Playground::root(), sandbox);
nu!(_output, cwd(&full_path), "mkdir dir_1 dir_2 dir_3");
assert!(h::files_exist_at(
vec![Path::new("dir_1"), Path::new("dir_2"), Path::new("dir_3")],
PathBuf::from(&full_path)

View File

@ -8,15 +8,13 @@ use std::path::{Path, PathBuf};
#[test]
fn moves_a_file() {
let sandbox = Playground::setup_for("mv_test_1")
.with_files(vec![
EmptyFile("andres.txt"),
])
.with_files(vec![EmptyFile("andres.txt")])
.mkdir("expected")
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original = format!("{}/{}", full_path, "andres.txt");
let expected = format!("{}/{}", full_path, "expected/yehuda.txt");
let expected = format!("{}/{}", full_path, "expected/yehuda.txt");
nu!(
_output,
@ -31,21 +29,14 @@ fn moves_a_file() {
#[test]
fn overwrites_if_moving_to_existing_file() {
let sandbox = Playground::setup_for("mv_test_2")
.with_files(vec![
EmptyFile("andres.txt"),
EmptyFile("jonathan.txt"),
])
.with_files(vec![EmptyFile("andres.txt"), EmptyFile("jonathan.txt")])
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original = format!("{}/{}", full_path, "andres.txt");
let expected = format!("{}/{}", full_path, "jonathan.txt");
let expected = format!("{}/{}", full_path, "jonathan.txt");
nu!(
_output,
cwd(&full_path),
"mv andres.txt jonathan.txt"
);
nu!(_output, cwd(&full_path), "mv andres.txt jonathan.txt");
assert!(!h::file_exists_at(PathBuf::from(original)));
assert!(h::file_exists_at(PathBuf::from(expected)));
@ -58,14 +49,10 @@ fn moves_a_directory() {
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original_dir = format!("{}/{}", full_path, "empty_dir");
let expected = format!("{}/{}", full_path, "renamed_dir");
let original_dir = format!("{}/{}", full_path, "empty_dir");
let expected = format!("{}/{}", full_path, "renamed_dir");
nu!(
_output,
cwd(&full_path),
"mv empty_dir renamed_dir"
);
nu!(_output, cwd(&full_path), "mv empty_dir renamed_dir");
assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
assert!(h::dir_exists_at(PathBuf::from(expected)));
@ -74,22 +61,15 @@ fn moves_a_directory() {
#[test]
fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
let sandbox = Playground::setup_for("mv_test_4")
.with_files(vec![
EmptyFile("jonathan.txt"),
])
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original_dir = format!("{}/{}", full_path, "jonathan.txt");
let expected = format!("{}/{}", full_path, "expected/jonathan.txt");
nu!(
_output,
cwd(&full_path),
"mv jonathan.txt expected"
);
let original_dir = format!("{}/{}", full_path, "jonathan.txt");
let expected = format!("{}/{}", full_path, "expected/jonathan.txt");
nu!(_output, cwd(&full_path), "mv jonathan.txt expected");
assert!(!h::file_exists_at(PathBuf::from(original_dir)));
assert!(h::file_exists_at(PathBuf::from(expected)));
@ -99,22 +79,15 @@ fn moves_the_file_inside_directory_if_path_to_move_is_existing_directory() {
fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory() {
let sandbox = Playground::setup_for("mv_test_5")
.within("contributors")
.with_files(vec![
EmptyFile("jonathan.txt"),
])
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original_dir = format!("{}/{}", full_path, "contributors");
let expected = format!("{}/{}", full_path, "expected/contributors");
nu!(
_output,
cwd(&full_path),
"mv contributors expected"
);
let original_dir = format!("{}/{}", full_path, "contributors");
let expected = format!("{}/{}", full_path, "expected/contributors");
nu!(_output, cwd(&full_path), "mv contributors expected");
assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
assert!(h::file_exists_at(PathBuf::from(expected)));
@ -124,14 +97,12 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_existing_directory()
fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory() {
let sandbox = Playground::setup_for("mv_test_6")
.within("contributors")
.with_files(vec![
EmptyFile("jonathan.txt"),
])
.with_files(vec![EmptyFile("jonathan.txt")])
.mkdir("expected")
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
let original_dir = format!("{}/{}", full_path, "contributors");
let original_dir = format!("{}/{}", full_path, "contributors");
nu!(
_output,
@ -139,7 +110,10 @@ fn moves_the_directory_inside_directory_if_path_to_move_is_nonexistent_directory
"mv contributors expected/this_dir_exists_now/los_tres_amigos"
);
let expected = format!("{}/{}", full_path, "expected/this_dir_exists_now/los_tres_amigos");
let expected = format!(
"{}/{}",
full_path, "expected/this_dir_exists_now/los_tres_amigos"
);
assert!(!h::dir_exists_at(PathBuf::from(original_dir)));
assert!(h::file_exists_at(PathBuf::from(expected)));
@ -168,11 +142,7 @@ fn moves_using_path_with_wildcard() {
let work_dir = format!("{}/{}", full_path, "work_dir");
let expected_copies_path = format!("{}/{}", full_path, "expected");
nu!(
_output,
cwd(&work_dir),
"mv ../originals/*.ini ../expected"
);
nu!(_output, cwd(&work_dir), "mv ../originals/*.ini ../expected");
assert!(h::files_exist_at(
vec![
@ -185,7 +155,6 @@ fn moves_using_path_with_wildcard() {
));
}
#[test]
fn moves_using_a_glob() {
let sandbox = Playground::setup_for("mv_test_8")
@ -204,11 +173,7 @@ fn moves_using_a_glob() {
let work_dir = format!("{}/{}", full_path, "work_dir");
let expected_copies_path = format!("{}/{}", full_path, "expected");
nu!(
_output,
cwd(&work_dir),
"mv ../meals/* ../expected"
);
nu!(_output, cwd(&work_dir), "mv ../meals/* ../expected");
assert!(h::dir_exists_at(PathBuf::from(meal_dir)));
assert!(h::files_exist_at(
@ -219,4 +184,4 @@ fn moves_using_a_glob() {
],
PathBuf::from(&expected_copies_path)
));
}
}

View File

@ -111,4 +111,4 @@ fn errors_if_file_not_found() {
);
assert!(output.contains("File could not be opened"));
}
}

View File

@ -90,7 +90,7 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
.test_dir_name();
let full_path = format!("{}/{}", Playground::root(), sandbox);
nu!(
_output,
cwd("tests/fixtures/nuplayground/rm_wildcard_test_2"),
@ -98,10 +98,7 @@ fn rm_removes_deeply_nested_directories_with_wildcard_and_recursive_flag() {
);
assert!(!h::files_exist_at(
vec![
Path::new("src/parser/parse"),
Path::new("src/parser/hir"),
],
vec![Path::new("src/parser/parse"), Path::new("src/parser/hir"),],
PathBuf::from(&full_path)
));
}
@ -150,7 +147,11 @@ fn rm_errors_if_attempting_to_delete_a_directory_with_content_without_recursive_
let full_path = format!("{}/{}", Playground::root(), sandbox);
nu_error!(output, cwd(&Playground::root()), "rm rm_prevent_directory_removal_without_flag_test");
nu_error!(
output,
cwd(&Playground::root()),
"rm rm_prevent_directory_removal_without_flag_test"
);
assert!(h::file_exists_at(PathBuf::from(full_path)));
assert!(output.contains("is a directory"));
@ -168,4 +169,4 @@ fn rm_errors_if_attempting_to_delete_two_dot_as_argument() {
nu_error!(output, cwd(&Playground::root()), "rm ..");
assert!(output.contains("may not be removed"));
}
}

View File

@ -16,14 +16,15 @@ fn can_only_apply_one() {
#[test]
fn by_one_with_field_passed() {
Playground::setup_for("plugin_inc_by_one_with_field_passed_test")
.with_files(vec![FileWithContent(
Playground::setup_for("plugin_inc_by_one_with_field_passed_test").with_files(vec![
FileWithContent(
"sample.toml",
r#"
[package]
edition = "2018"
"#,
)]);
),
]);
nu!(
output,
@ -36,35 +37,34 @@ fn by_one_with_field_passed() {
#[test]
fn by_one_with_no_field_passed() {
Playground::setup_for("plugin_inc_by_one_with_no_field_passed_test")
.with_files(vec![FileWithContent(
Playground::setup_for("plugin_inc_by_one_with_no_field_passed_test").with_files(vec![
FileWithContent(
"sample.toml",
r#"
[package]
contributors = "2"
"#,
)]);
),
]);
nu!(
output,
cwd("tests/fixtures/nuplayground/plugin_inc_by_one_with_no_field_passed_test"),
"open sample.toml | get package.contributors | inc | echo $it"
);
assert_eq!(output, "3");
}
#[test]
fn semversion_major_inc() {
Playground::setup_for("plugin_inc_major_semversion_test")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
Playground::setup_for("plugin_inc_major_semversion_test").with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
)]);
nu!(
output,
@ -77,14 +77,13 @@ fn semversion_major_inc() {
#[test]
fn semversion_minor_inc() {
Playground::setup_for("plugin_inc_minor_semversion_test")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
Playground::setup_for("plugin_inc_minor_semversion_test").with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
)]);
nu!(
output,
@ -97,14 +96,13 @@ fn semversion_minor_inc() {
#[test]
fn semversion_patch_inc() {
Playground::setup_for("plugin_inc_patch_semversion_test")
.with_files(vec![FileWithContent(
"sample.toml",
r#"
Playground::setup_for("plugin_inc_patch_semversion_test").with_files(vec![FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
)]);
nu!(
output,
@ -117,14 +115,15 @@ fn semversion_patch_inc() {
#[test]
fn semversion_without_passing_field() {
Playground::setup_for("plugin_inc_semversion_without_passing_field_test")
.with_files(vec![FileWithContent(
Playground::setup_for("plugin_inc_semversion_without_passing_field_test").with_files(vec![
FileWithContent(
"sample.toml",
r#"
[package]
version = "0.1.3"
"#,
)]);
),
]);
nu!(
output,
@ -133,4 +132,4 @@ fn semversion_without_passing_field() {
);
assert_eq!(output, "0.1.4");
}
}