Fix more issues identified by clippy (aka: lint).

This commit is contained in:
Gregory Burd 2020-08-07 09:15:36 -04:00
parent 125306e108
commit 4b1583473e
12 changed files with 153 additions and 157 deletions

View file

@ -13,6 +13,8 @@ before_install:
- brew install sqlcipher - brew install sqlcipher
rust: rust:
- 1.43.0 - 1.43.0
- 1.44.0
- 1.45.0
- stable - stable
- beta - beta
- nightly - nightly
@ -24,10 +26,10 @@ matrix:
jobs: jobs:
include: include:
- stage: "Test iOS" - stage: "Test iOS"
rust: 1.43.0 rust: 1.45.0
script: ./scripts/test-ios.sh script: ./scripts/test-ios.sh
- stage: "Docs" - stage: "Docs"
rust: 1.43.0 rust: 1.45.0
script: ./scripts/cargo-doc.sh script: ./scripts/cargo-doc.sh
script: script:
- cargo build --verbose --all - cargo build --verbose --all

View file

@ -29,6 +29,9 @@ members = ["tools/cli", "ffi"]
[build-dependencies] [build-dependencies]
rustc_version = "~0.2" rustc_version = "~0.2"
[dev-dependencies]
assert_approx_eq = "~1.1"
[dev-dependencies.cargo-husky] [dev-dependencies.cargo-husky]
version = "1" version = "1"
default-features = false # Disable features which are enabled by default default-features = false # Disable features which are enabled by default

View file

@ -70,6 +70,7 @@
//! (for `Result<(), T>`). Callers are responsible for freeing the `message` field of `ExternError`. //! (for `Result<(), T>`). Callers are responsible for freeing the `message` field of `ExternError`.
#![allow(unused_doc_comments)] #![allow(unused_doc_comments)]
#![allow(clippy::missing_safety_doc)]
extern crate core; extern crate core;
extern crate libc; extern crate libc;
@ -176,8 +177,12 @@ pub unsafe extern "C" fn store_open(uri: *const c_char, error: *mut ExternError)
} }
/// Variant of store_open that opens an encrypted database. /// Variant of store_open that opens an encrypted database.
///
/// # Safety /// # Safety
/// Be afraid... TODO ///
/// Callers are responsible for managing the memory for the return value.
/// A destructor `store_destroy` is provided for releasing the memory for this
/// pointer type.
#[cfg(feature = "sqlcipher")] #[cfg(feature = "sqlcipher")]
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn store_open_encrypted( pub unsafe extern "C" fn store_open_encrypted(
@ -249,6 +254,10 @@ pub unsafe extern "C" fn in_progress_transact<'m>(
/// in progress transaction. /// in progress transaction.
/// ///
/// # Safety /// # Safety
/// Callers are responsible for managing the memory for the return value.
/// A destructor `tx_report_destroy` is provided for releasing the memory for this
/// pointer type.
///
/// TODO: Document the errors that can result from transact /// TODO: Document the errors that can result from transact
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn in_progress_commit<'m>( pub unsafe extern "C" fn in_progress_commit<'m>(
@ -264,6 +273,11 @@ pub unsafe extern "C" fn in_progress_commit<'m>(
/// in progress transaction. /// in progress transaction.
/// ///
/// # Safety /// # Safety
///
/// Callers are responsible for managing the memory for the return value.
/// A destructor `tx_report_destroy` is provided for releasing the memory for this
/// pointer type.
///
/// TODO: Document the errors that can result from rollback /// TODO: Document the errors that can result from rollback
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn in_progress_rollback<'m>( pub unsafe extern "C" fn in_progress_rollback<'m>(
@ -1360,7 +1374,7 @@ pub unsafe extern "C" fn tx_report_entity_for_temp_id(
let tx_report = &*tx_report; let tx_report = &*tx_report;
let key = c_char_to_string(tempid); let key = c_char_to_string(tempid);
if let Some(entid) = tx_report.tempids.get(key) { if let Some(entid) = tx_report.tempids.get(key) {
Box::into_raw(Box::new(entid.clone() as c_longlong)) Box::into_raw(Box::new(*entid as c_longlong))
} else { } else {
std::ptr::null_mut() std::ptr::null_mut()
} }
@ -2145,7 +2159,7 @@ pub unsafe extern "C" fn store_register_observer(
.map(|(tx_id, changes)| { .map(|(tx_id, changes)| {
( (
*tx_id, *tx_id,
changes.into_iter().map(|eid| *eid as c_longlong).collect(), changes.iter().map(|eid| *eid as c_longlong).collect(),
) )
}) })
.collect(); .collect();

View file

@ -533,7 +533,7 @@ mod test {
assert_eq!( assert_eq!(
results results
.get(1) .get(1)
.map_or(None, |t| t.to_owned().into_long()) .and_then(|t| t.to_owned().into_long())
.expect("long"), .expect("long"),
25 25
); );

View file

@ -117,7 +117,7 @@ impl Store {
} }
#[cfg(test)] #[cfg(test)]
pub fn is_registered_as_observer(&self, key: &String) -> bool { pub fn is_registered_as_observer(&self, key: &str) -> bool {
self.conn self.conn
.tx_observer_service .tx_observer_service
.lock() .lock()
@ -309,13 +309,11 @@ mod tests {
[?neighborhood :neighborhood/district ?d] [?neighborhood :neighborhood/district ?d]
[?d :district/name ?district]]"#; [?d :district/name ?district]]"#;
let hood = "Beacon Hill"; let hood = "Beacon Hill";
let inputs = QueryInputs::with_value_sequence(vec![( let inputs =
var!(?hood), QueryInputs::with_value_sequence(vec![(var!(?hood), TypedValue::typed_string(hood))]);
TypedValue::typed_string(hood).into(),
)]);
let mut prepared = in_progress.q_prepare(query, inputs).expect("prepared"); let mut prepared = in_progress.q_prepare(query, inputs).expect("prepared");
match &prepared { match prepared {
&PreparedQuery::Constant { PreparedQuery::Constant {
select: ref _select, select: ref _select,
} => {} } => {}
_ => panic!(), _ => panic!(),
@ -703,8 +701,8 @@ mod tests {
.expect("entid to exist for completion_date") .expect("entid to exist for completion_date")
.into(); .into();
let mut registered_attrs = BTreeSet::new(); let mut registered_attrs = BTreeSet::new();
registered_attrs.insert(name_entid.clone()); registered_attrs.insert(name_entid);
registered_attrs.insert(date_entid.clone()); registered_attrs.insert(date_entid);
let key = "Test Observing".to_string(); let key = "Test Observing".to_string();
@ -749,27 +747,27 @@ mod tests {
let mut in_progress = conn.begin_transaction().expect("expected transaction"); let mut in_progress = conn.begin_transaction().expect("expected transaction");
for i in 0..3 { for i in 0..3 {
let mut changeset = BTreeSet::new(); let mut changeset = BTreeSet::new();
changeset.insert(db_tx_instant_entid.clone()); changeset.insert(db_tx_instant_entid);
let name = format!("todo{}", i); let name = format!("todo{}", i);
let uuid = Uuid::new_v4(); let uuid = Uuid::new_v4();
let mut builder = in_progress.builder().describe_tempid(&name); let mut builder = in_progress.builder().describe_tempid(&name);
builder builder
.add(kw!(:todo/uuid), TypedValue::Uuid(uuid)) .add(kw!(:todo/uuid), TypedValue::Uuid(uuid))
.expect("Expected added uuid"); .expect("Expected added uuid");
changeset.insert(uuid_entid.clone()); changeset.insert(uuid_entid);
builder builder
.add(kw!(:todo/name), TypedValue::typed_string(name)) .add(kw!(:todo/name), TypedValue::typed_string(name))
.expect("Expected added name"); .expect("Expected added name");
changeset.insert(name_entid.clone()); changeset.insert(name_entid);
if i % 2 == 0 { if i % 2 == 0 {
builder builder
.add(kw!(:todo/completion_date), TypedValue::current_instant()) .add(kw!(:todo/completion_date), TypedValue::current_instant())
.expect("Expected added date"); .expect("Expected added date");
changeset.insert(date_entid.clone()); changeset.insert(date_entid);
} }
let (ip, r) = builder.transact(); let (ip, r) = builder.transact();
let report = r.expect("expected a report"); let report = r.expect("expected a report");
tx_ids.push(report.tx_id.clone()); tx_ids.push(report.tx_id);
changesets.push(changeset); changesets.push(changeset);
in_progress = ip; in_progress = ip;
} }
@ -788,7 +786,7 @@ mod tests {
let out = Arc::try_unwrap(output).expect("unwrapped"); let out = Arc::try_unwrap(output).expect("unwrapped");
let o = out.into_inner().expect("Expected an Output"); let o = out.into_inner().expect("Expected an Output");
assert_eq!(o.called_key, Some(key.clone())); assert_eq!(o.called_key, Some(key));
assert_eq!(o.txids, tx_ids); assert_eq!(o.txids, tx_ids);
assert_eq!(o.changes, changesets); assert_eq!(o.changes, changesets);
} }
@ -811,8 +809,8 @@ mod tests {
.expect("entid to exist for completion_date") .expect("entid to exist for completion_date")
.into(); .into();
let mut registered_attrs = BTreeSet::new(); let mut registered_attrs = BTreeSet::new();
registered_attrs.insert(name_entid.clone()); registered_attrs.insert(name_entid);
registered_attrs.insert(date_entid.clone()); registered_attrs.insert(date_entid);
let key = "Test Observing".to_string(); let key = "Test Observing".to_string();

View file

@ -35,6 +35,8 @@ use mentat::conn::Conn;
use public_traits::errors::MentatError; use public_traits::errors::MentatError;
use assert_approx_eq::assert_approx_eq;
#[test] #[test]
fn test_rel() { fn test_rel() {
let mut c = new_connection("").expect("Couldn't open conn."); let mut c = new_connection("").expect("Couldn't open conn.");
@ -468,7 +470,7 @@ fn test_fulltext() {
) => { ) => {
assert_eq!(x, v); assert_eq!(x, v);
assert_eq!(text.as_str(), "hello darkness my old friend"); assert_eq!(text.as_str(), "hello darkness my old friend");
assert_eq!(score, 0.0f64); assert_approx_eq!(score, 0.0f64.into());
} }
_ => panic!("Unexpected results."), _ => panic!("Unexpected results."),
} }
@ -854,7 +856,7 @@ fn test_type_reqs() {
let eid_query = r#"[:find ?eid :where [?eid :test/string "foo"]]"#; let eid_query = r#"[:find ?eid :where [?eid :test/string "foo"]]"#;
let res = conn let res = conn
.q_once(&mut c, eid_query, None) .q_once(&c, eid_query, None)
.into_rel_result() .into_rel_result()
.expect("results"); .expect("results");

View file

@ -77,7 +77,7 @@ mod tolstoy_tests {
where where
T: Iterator<Item = TxPart>, T: Iterator<Item = TxPart>,
{ {
let datoms = self.txes.entry(tx_id).or_insert_with(|| vec![]); let datoms = self.txes.entry(tx_id).or_default();
datoms.extend(d); datoms.extend(d);
Ok(()) Ok(())
} }

View file

@ -799,9 +799,7 @@ fn test_upgrade_with_functions() {
return Ok(()); return Ok(());
} }
ip.transact_builder(builder) ip.transact_builder(builder).and(Ok(())).map_err(|e| e)
.and(Ok(()))
.map_err(|e| e.into())
} }
/// This is the function we write to dedupe. This logic is very suitable for sharing: /// This is the function we write to dedupe. This logic is very suitable for sharing:
@ -821,11 +819,11 @@ fn test_upgrade_with_functions() {
.into_iter() .into_iter()
{ {
let mut row = row.into_iter(); let mut row = row.into_iter();
match (row.next(), row.next()) { if let (
(
Some(Binding::Scalar(TypedValue::Ref(left))), Some(Binding::Scalar(TypedValue::Ref(left))),
Some(Binding::Scalar(TypedValue::Ref(right))), Some(Binding::Scalar(TypedValue::Ref(right))),
) => { ) = (row.next(), row.next())
{
let keep = KnownEntid(left); let keep = KnownEntid(left);
let replace = KnownEntid(right); let replace = KnownEntid(right);
@ -861,20 +859,15 @@ fn test_upgrade_with_functions() {
builder.retract(e, a, replace)?; builder.retract(e, a, replace)?;
builder.add(e, a, keep)?; builder.add(e, a, keep)?;
} }
// TODO: `retractEntity` on `replace` (when we support that). // TODO: `retractEntity` on `replace` (when we support that).
} }
_ => {}
}
} }
if builder.is_empty() { if builder.is_empty() {
return Ok(()); return Ok(());
} }
ip.transact_builder(builder) ip.transact_builder(builder).and(Ok(())).map_err(|e| e)
.and(Ok(()))
.map_err(|e| e.into())
} }
// This migration is bad: it can't impose the uniqueness constraint because we end up with // This migration is bad: it can't impose the uniqueness constraint because we end up with
@ -1150,9 +1143,7 @@ fn test_upgrade_with_functions() {
db_doc, db_doc,
TypedValue::typed_string("Deprecated. Use :movie/likes or :food/likes instead."), TypedValue::typed_string("Deprecated. Use :movie/likes or :food/likes instead."),
)?; )?;
ip.transact_builder(builder) ip.transact_builder(builder).and(Ok(())).map_err(|e| e)
.and(Ok(()))
.map_err(|e| e.into())
} }
}; };

View file

@ -105,26 +105,26 @@ impl Command {
pub fn output(&self) -> String { pub fn output(&self) -> String {
match self { match self {
&Command::Cache(ref attr, ref direction) => { Command::Cache(ref attr, ref direction) => {
format!(".{} {} {:?}", COMMAND_CACHE, attr, direction) format!(".{} {} {:?}", COMMAND_CACHE, attr, direction)
} }
&Command::Close => format!(".{}", COMMAND_CLOSE), Command::Close => format!(".{}", COMMAND_CLOSE),
&Command::Exit => format!(".{}", COMMAND_EXIT_LONG), Command::Exit => format!(".{}", COMMAND_EXIT_LONG),
&Command::Help(ref args) => format!(".{} {:?}", COMMAND_HELP, args), Command::Help(ref args) => format!(".{} {:?}", COMMAND_HELP, args),
&Command::Import(ref args) => format!(".{} {}", COMMAND_IMPORT_LONG, args), Command::Import(ref args) => format!(".{} {}", COMMAND_IMPORT_LONG, args),
&Command::Open(ref args) => format!(".{} {}", COMMAND_OPEN, args), Command::Open(ref args) => format!(".{} {}", COMMAND_OPEN, args),
&Command::OpenEncrypted(ref db, ref key) => { Command::OpenEncrypted(ref db, ref key) => {
format!(".{} {} {}", COMMAND_OPEN_ENCRYPTED, db, key) format!(".{} {} {}", COMMAND_OPEN_ENCRYPTED, db, key)
} }
&Command::Query(ref args) => format!(".{} {}", COMMAND_QUERY_LONG, args), Command::Query(ref args) => format!(".{} {}", COMMAND_QUERY_LONG, args),
&Command::QueryExplain(ref args) => format!(".{} {}", COMMAND_QUERY_EXPLAIN_LONG, args), Command::QueryExplain(ref args) => format!(".{} {}", COMMAND_QUERY_EXPLAIN_LONG, args),
&Command::QueryPrepared(ref args) => { Command::QueryPrepared(ref args) => {
format!(".{} {}", COMMAND_QUERY_PREPARED_LONG, args) format!(".{} {}", COMMAND_QUERY_PREPARED_LONG, args)
} }
&Command::Schema => format!(".{}", COMMAND_SCHEMA), Command::Schema => format!(".{}", COMMAND_SCHEMA),
&Command::Sync(ref args) => format!(".{} {:?}", COMMAND_SYNC, args), Command::Sync(ref args) => format!(".{} {:?}", COMMAND_SYNC, args),
&Command::Timer(on) => format!(".{} {}", COMMAND_TIMER_LONG, on), Command::Timer(on) => format!(".{} {}", COMMAND_TIMER_LONG, on),
&Command::Transact(ref args) => format!(".{} {}", COMMAND_TRANSACT_LONG, args), Command::Transact(ref args) => format!(".{} {}", COMMAND_TRANSACT_LONG, args),
} }
} }
} }
@ -219,7 +219,7 @@ pub fn command(s: &str) -> Result<Command, Error> {
let help_parser = string(COMMAND_HELP) let help_parser = string(COMMAND_HELP)
.with(spaces()) .with(spaces())
.with(arguments()) .with(arguments())
.map(|args| Ok(Command::Help(args.clone()))); .map(|args| Ok(Command::Help(args)));
let import_parser = attempt(string(COMMAND_IMPORT_LONG)) let import_parser = attempt(string(COMMAND_IMPORT_LONG))
.or(attempt(string(COMMAND_IMPORT_SHORT))) .or(attempt(string(COMMAND_IMPORT_SHORT)))
@ -257,7 +257,7 @@ pub fn command(s: &str) -> Result<Command, Error> {
.with(spaces()) .with(spaces())
.with(arguments()) .with(arguments())
.map(|args| { .map(|args| {
if args.len() < 1 { if args.is_empty() {
bail!(CliError::CommandParse( bail!(CliError::CommandParse(
"Missing required argument".to_string() "Missing required argument".to_string()
)); ));
@ -268,7 +268,7 @@ pub fn command(s: &str) -> Result<Command, Error> {
args[2] args[2]
))); )));
} }
Ok(Command::Sync(args.clone())) Ok(Command::Sync(args))
}); });
let timer_parser = string(COMMAND_TIMER_LONG) let timer_parser = string(COMMAND_TIMER_LONG)
@ -320,7 +320,7 @@ mod tests {
Command::Help(args) => { Command::Help(args) => {
assert_eq!(args, vec!["command1", "command2"]); assert_eq!(args, vec!["command1", "command2"]);
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -332,7 +332,7 @@ mod tests {
Command::Help(args) => { Command::Help(args) => {
assert_eq!(args, vec![".command1"]); assert_eq!(args, vec![".command1"]);
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -345,7 +345,7 @@ mod tests {
let empty: Vec<String> = vec![]; let empty: Vec<String> = vec![];
assert_eq!(args, empty); assert_eq!(args, empty);
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -358,7 +358,7 @@ mod tests {
let empty: Vec<String> = vec![]; let empty: Vec<String> = vec![];
assert_eq!(args, empty); assert_eq!(args, empty);
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -377,7 +377,7 @@ mod tests {
Command::Open(arg) => { Command::Open(arg) => {
assert_eq!(arg, "database1".to_string()); assert_eq!(arg, "database1".to_string());
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -389,7 +389,7 @@ mod tests {
Command::Open(arg) => { Command::Open(arg) => {
assert_eq!(arg, "/path/to/my.db".to_string()); assert_eq!(arg, "/path/to/my.db".to_string());
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -402,7 +402,7 @@ mod tests {
assert_eq!(path, "/path/to/my.db".to_string()); assert_eq!(path, "/path/to/my.db".to_string());
assert_eq!(key, "hunter2".to_string()); assert_eq!(key, "hunter2".to_string());
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -422,7 +422,7 @@ mod tests {
assert_eq!(args[0], "https://example.com/api/".to_string()); assert_eq!(args[0], "https://example.com/api/".to_string());
assert_eq!(args[1], "316ea470-ce35-4adf-9c61-e0de6e289c59".to_string()); assert_eq!(args[1], "316ea470-ce35-4adf-9c61-e0de6e289c59".to_string());
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -434,7 +434,7 @@ mod tests {
Command::Open(arg) => { Command::Open(arg) => {
assert_eq!(arg, "my.db".to_string()); assert_eq!(arg, "my.db".to_string());
} }
_ => assert!(false), _ => panic!(),
} }
} }
@ -463,9 +463,8 @@ mod tests {
fn test_close_parser_no_args() { fn test_close_parser_no_args() {
let input = ".close"; let input = ".close";
let cmd = command(&input).expect("Expected close command"); let cmd = command(&input).expect("Expected close command");
match cmd { if cmd != Command::Close {
Command::Close => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -473,9 +472,8 @@ mod tests {
fn test_close_parser_no_args_trailing_whitespace() { fn test_close_parser_no_args_trailing_whitespace() {
let input = ".close "; let input = ".close ";
let cmd = command(&input).expect("Expected close command"); let cmd = command(&input).expect("Expected close command");
match cmd { if cmd != Command::Close {
Command::Close => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -490,9 +488,8 @@ mod tests {
fn test_exit_parser_no_args() { fn test_exit_parser_no_args() {
let input = ".exit"; let input = ".exit";
let cmd = command(&input).expect("Expected exit command"); let cmd = command(&input).expect("Expected exit command");
match cmd { if cmd != Command::Exit {
Command::Exit => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -500,9 +497,8 @@ mod tests {
fn test_exit_parser_no_args_trailing_whitespace() { fn test_exit_parser_no_args_trailing_whitespace() {
let input = ".exit "; let input = ".exit ";
let cmd = command(&input).expect("Expected exit command"); let cmd = command(&input).expect("Expected exit command");
match cmd { if cmd != Command::Exit {
Command::Exit => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -510,9 +506,8 @@ mod tests {
fn test_exit_parser_short_command() { fn test_exit_parser_short_command() {
let input = ".e"; let input = ".e";
let cmd = command(&input).expect("Expected exit command"); let cmd = command(&input).expect("Expected exit command");
match cmd { if cmd != Command::Exit {
Command::Exit => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -527,9 +522,8 @@ mod tests {
fn test_schema_parser_no_args() { fn test_schema_parser_no_args() {
let input = ".schema"; let input = ".schema";
let cmd = command(&input).expect("Expected schema command"); let cmd = command(&input).expect("Expected schema command");
match cmd { if cmd != Command::Schema {
Command::Schema => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -537,9 +531,8 @@ mod tests {
fn test_schema_parser_no_args_trailing_whitespace() { fn test_schema_parser_no_args_trailing_whitespace() {
let input = ".schema "; let input = ".schema ";
let cmd = command(&input).expect("Expected schema command"); let cmd = command(&input).expect("Expected schema command");
match cmd { if cmd != Command::Schema {
Command::Schema => assert!(true), panic!()
_ => assert!(false),
} }
} }
@ -549,7 +542,7 @@ mod tests {
let cmd = command(&input).expect("Expected query command"); let cmd = command(&input).expect("Expected query command");
match cmd { match cmd {
Command::Query(edn) => assert_eq!(edn, "[:find ?x :where [?x foo/bar ?y]]"), Command::Query(edn) => assert_eq!(edn, "[:find ?x :where [?x foo/bar ?y]]"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -559,7 +552,7 @@ mod tests {
let cmd = command(&input).expect("Expected query command"); let cmd = command(&input).expect("Expected query command");
match cmd { match cmd {
Command::Query(edn) => assert_eq!(edn, "[:find ?x :where [?x foo/bar ?y]]"), Command::Query(edn) => assert_eq!(edn, "[:find ?x :where [?x foo/bar ?y]]"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -569,7 +562,7 @@ mod tests {
let cmd = command(&input).expect("Expected query command"); let cmd = command(&input).expect("Expected query command");
match cmd { match cmd {
Command::Query(edn) => assert_eq!(edn, "[:find ?x\r\n"), Command::Query(edn) => assert_eq!(edn, "[:find ?x\r\n"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -579,7 +572,7 @@ mod tests {
let cmd = command(&input).expect("Expected query command"); let cmd = command(&input).expect("Expected query command");
match cmd { match cmd {
Command::Query(edn) => assert_eq!(edn, "{}"), Command::Query(edn) => assert_eq!(edn, "{}"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -616,7 +609,7 @@ mod tests {
edn, edn,
"[[:db/add \"s\" :db/ident :foo/uuid] [:db/add \"r\" :db/ident :bar/uuid]]" "[[:db/add \"s\" :db/ident :foo/uuid] [:db/add \"r\" :db/ident :bar/uuid]]"
), ),
_ => assert!(false), _ => panic!(),
} }
} }
@ -630,7 +623,7 @@ mod tests {
edn, edn,
"[[:db/add \"s\" :db/ident :foo/uuid] [:db/add \"r\" :db/ident :bar/uuid]]" "[[:db/add \"s\" :db/ident :foo/uuid] [:db/add \"r\" :db/ident :bar/uuid]]"
), ),
_ => assert!(false), _ => panic!(),
} }
} }
@ -640,7 +633,7 @@ mod tests {
let cmd = command(&input).expect("Expected transact command"); let cmd = command(&input).expect("Expected transact command");
match cmd { match cmd {
Command::Transact(edn) => assert_eq!(edn, "{\r\n"), Command::Transact(edn) => assert_eq!(edn, "{\r\n"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -650,7 +643,7 @@ mod tests {
let cmd = command(&input).expect("Expected transact command"); let cmd = command(&input).expect("Expected transact command");
match cmd { match cmd {
Command::Transact(edn) => assert_eq!(edn, "{}"), Command::Transact(edn) => assert_eq!(edn, "{}"),
_ => assert!(false), _ => panic!(),
} }
} }
@ -672,9 +665,8 @@ mod tests {
fn test_parser_preceeding_trailing_whitespace() { fn test_parser_preceeding_trailing_whitespace() {
let input = " .close "; let input = " .close ";
let cmd = command(&input).expect("Expected close command"); let cmd = command(&input).expect("Expected close command");
match cmd { if cmd != Command::Close {
Command::Close => assert!(true), panic!()
_ => assert!(false),
} }
} }

View file

@ -130,13 +130,11 @@ impl InputReader {
// Therefore, we add the newly read in line to the existing command args. // Therefore, we add the newly read in line to the existing command args.
// If there is no in process command, we parse the read in line as a new command. // If there is no in process command, we parse the read in line as a new command.
let cmd = match &self.in_process_cmd { let cmd = match &self.in_process_cmd {
&Some(Command::QueryPrepared(ref args)) => { Some(Command::QueryPrepared(ref args)) => {
Ok(Command::QueryPrepared(args.clone() + "\n" + &line)) Ok(Command::QueryPrepared(args.clone() + "\n" + &line))
} }
&Some(Command::Query(ref args)) => Ok(Command::Query(args.clone() + "\n" + &line)), Some(Command::Query(ref args)) => Ok(Command::Query(args.clone() + "\n" + &line)),
&Some(Command::Transact(ref args)) => { Some(Command::Transact(ref args)) => Ok(Command::Transact(args.clone() + "\n" + &line)),
Ok(Command::Transact(args.clone() + "\n" + &line))
}
_ => command(&self.buffer), _ => command(&self.buffer),
}; };
@ -202,7 +200,7 @@ impl InputReader {
match stdin().read_line(&mut s) { match stdin().read_line(&mut s) {
Ok(0) | Err(_) => UserAction::Quit, Ok(0) | Err(_) => UserAction::Quit,
Ok(_) => { Ok(_) => {
if s.ends_with("\n") { if s.ends_with('\n') {
let len = s.len() - 1; let len = s.len() - 1;
s.truncate(len); s.truncate(len);
} }

View file

@ -136,7 +136,7 @@ pub fn run() -> i32 {
.filter_map(|arg| match last_arg { .filter_map(|arg| match last_arg {
Some("-d") => { Some("-d") => {
last_arg = None; last_arg = None;
if let &Some(ref k) = &key { if let Some(ref k) = key {
Some(command_parser::Command::OpenEncrypted( Some(command_parser::Command::OpenEncrypted(
arg.clone(), arg.clone(),
k.clone(), k.clone(),

View file

@ -430,14 +430,10 @@ impl Repl {
} }
} else { } else {
for mut arg in args { for mut arg in args {
if arg.chars().nth(0).unwrap() == '.' { if arg.starts_with('.') {
arg.remove(0); arg.remove(0);
} }
if let Some(&(cmd, msg)) = HELP_COMMANDS if let Some(&(cmd, msg)) = HELP_COMMANDS.iter().find(|&&(c, _)| c == arg.as_str()) {
.iter()
.filter(|&&(c, _)| c == arg.as_str())
.next()
{
write!(output, ".{}\t", cmd).unwrap(); write!(output, ".{}\t", cmd).unwrap();
writeln!(output, "{}", msg).unwrap(); writeln!(output, "{}", msg).unwrap();
} else { } else {
@ -569,13 +565,13 @@ impl Repl {
fn binding_as_string(&self, value: &Binding) -> String { fn binding_as_string(&self, value: &Binding) -> String {
use self::Binding::*; use self::Binding::*;
match value { match value {
&Scalar(ref v) => self.value_as_string(v), Scalar(ref v) => self.value_as_string(v),
&Map(ref v) => self.map_as_string(v), Map(ref v) => self.map_as_string(v),
&Vec(ref v) => self.vec_as_string(v), Vec(ref v) => self.vec_as_string(v),
} }
} }
fn vec_as_string(&self, value: &Vec<Binding>) -> String { fn vec_as_string(&self, value: &[Binding]) -> String {
let mut out: String = "[".to_string(); let mut out: String = "[".to_string();
let vals: Vec<String> = value.iter().map(|v| self.binding_as_string(v)).collect(); let vals: Vec<String> = value.iter().map(|v| self.binding_as_string(v)).collect();
@ -603,20 +599,20 @@ impl Repl {
fn value_as_string(&self, value: &TypedValue) -> String { fn value_as_string(&self, value: &TypedValue) -> String {
use self::TypedValue::*; use self::TypedValue::*;
match value { match value {
&Boolean(b) => { Boolean(b) => {
if b { if *b {
"true".to_string() "true".to_string()
} else { } else {
"false".to_string() "false".to_string()
} }
} }
&Double(d) => format!("{}", d), Double(d) => format!("{}", d),
&Instant(ref i) => format!("{}", i), Instant(ref i) => format!("{}", i),
&Keyword(ref k) => format!("{}", k), Keyword(ref k) => format!("{}", k),
&Long(l) => format!("{}", l), Long(l) => format!("{}", l),
&Ref(r) => format!("{}", r), Ref(r) => format!("{}", r),
&String(ref s) => format!("{:?}", s.to_string()), String(ref s) => format!("{:?}", s.to_string()),
&Uuid(ref u) => format!("{}", u), Uuid(ref u) => format!("{}", u),
} }
} }
} }