Makes new Clippy lints pass

pull/23/head
Tpt 5 years ago
parent 6db8b555fb
commit 329a80bc8c
  1. 4
      lib/src/lib.rs
  2. 1
      lib/src/model/xsd/date_time.rs
  3. 86
      lib/src/model/xsd/decimal.rs
  4. 7
      lib/src/model/xsd/duration.rs
  5. 8
      lib/src/sparql/sparql_grammar.rustpeg
  6. 2
      lib/src/store/rocksdb.rs
  7. 30
      lib/tests/sparql_test_cases.rs

@ -55,6 +55,7 @@
clippy::decimal_literal_representation, clippy::decimal_literal_representation,
//TODO clippy::doc_markdown, //TODO clippy::doc_markdown,
clippy::empty_enum, clippy::empty_enum,
clippy::option_expect_used,
clippy::expl_impl_clone_on_copy, clippy::expl_impl_clone_on_copy,
clippy::explicit_into_iter_loop, clippy::explicit_into_iter_loop,
clippy::explicit_iter_loop, clippy::explicit_iter_loop,
@ -71,6 +72,7 @@
//TODO clippy::match_same_arms, //TODO clippy::match_same_arms,
clippy::maybe_infinite_iter, clippy::maybe_infinite_iter,
clippy::mem_forget, clippy::mem_forget,
//TODO clippy::must_use_candidate,
clippy::multiple_inherent_impl, clippy::multiple_inherent_impl,
clippy::mut_mut, clippy::mut_mut,
clippy::needless_borrow, clippy::needless_borrow,
@ -79,6 +81,7 @@
clippy::non_ascii_literal, clippy::non_ascii_literal,
clippy::option_map_unwrap_or, clippy::option_map_unwrap_or,
clippy::option_map_unwrap_or_else, clippy::option_map_unwrap_or_else,
// clippy::panic, does not work well with tests
clippy::path_buf_push_overwrite, clippy::path_buf_push_overwrite,
clippy::print_stdout, clippy::print_stdout,
clippy::pub_enum_variant_names, clippy::pub_enum_variant_names,
@ -91,6 +94,7 @@
// clippy::single_match_else, // clippy::single_match_else,
clippy::string_add, clippy::string_add,
clippy::string_add_assign, clippy::string_add_assign,
clippy::todo,
clippy::type_repetition_in_bounds, clippy::type_repetition_in_bounds,
clippy::unicode_not_nfc, clippy::unicode_not_nfc,
//TODO clippy::unseparated_literal_suffix, //TODO clippy::unseparated_literal_suffix,

@ -1204,6 +1204,7 @@ mod tests {
} }
#[test] #[test]
#[allow(clippy::neg_cmp_op_on_partial_ord)]
fn cmp() { fn cmp() {
assert!( assert!(
Date::from_str("2004-12-25Z").unwrap() < Date::from_str("2004-12-25-05:00").unwrap() Date::from_str("2004-12-25Z").unwrap() < Date::from_str("2004-12-25-05:00").unwrap()

@ -2,7 +2,6 @@ use std::convert::{TryFrom, TryInto};
use std::error::Error; use std::error::Error;
use std::fmt; use std::fmt;
use std::fmt::Write; use std::fmt::Write;
use std::i128;
use std::ops::Neg; use std::ops::Neg;
use std::str::FromStr; use std::str::FromStr;
@ -11,13 +10,6 @@ const DECIMAL_PART_POW: i128 = 1_000_000_000_000_000_000;
const DECIMAL_PART_POW_MINUS_ONE: i128 = 100_000_000_000_000_000; const DECIMAL_PART_POW_MINUS_ONE: i128 = 100_000_000_000_000_000;
const DECIMAL_PART_HALF_POW: i128 = 1_000_000_000; const DECIMAL_PART_HALF_POW: i128 = 1_000_000_000;
#[cfg(test)]
pub(super) const MIN: Decimal = Decimal { value: i128::MIN };
#[cfg(test)]
pub(super) const MAX: Decimal = Decimal { value: i128::MAX };
#[cfg(test)]
pub(super) const STEP: Decimal = Decimal { value: 1 };
/// [XML Schema `decimal` datatype](https://www.w3.org/TR/xmlschema11-2/#decimal) implementation. /// [XML Schema `decimal` datatype](https://www.w3.org/TR/xmlschema11-2/#decimal) implementation.
/// ///
/// It stores the decimal in a fix point encoding allowing nearly 18 digits before and 18 digits after ".". /// It stores the decimal in a fix point encoding allowing nearly 18 digits before and 18 digits after ".".
@ -189,6 +181,25 @@ impl Decimal {
pub(super) const fn as_i128(&self) -> i128 { pub(super) const fn as_i128(&self) -> i128 {
self.value / DECIMAL_PART_POW self.value / DECIMAL_PART_POW
} }
#[cfg(test)]
pub(super) const fn min_value() -> Decimal {
Self {
value: i128::min_value(),
}
}
#[cfg(test)]
pub(super) const fn max_value() -> Decimal {
Self {
value: i128::max_value(),
}
}
#[cfg(test)]
pub(super) const fn step() -> Decimal {
Self { value: 1 }
}
} }
impl From<i8> for Decimal { impl From<i8> for Decimal {
@ -504,7 +515,6 @@ impl TryFrom<Decimal> for i64 {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::i64;
#[test] #[test]
fn from_str() { fn from_str() {
@ -521,10 +531,19 @@ mod tests {
); );
assert_eq!(Decimal::from_str("0.1220").unwrap().to_string(), "0.122"); assert_eq!(Decimal::from_str("0.1220").unwrap().to_string(), "0.122");
assert_eq!(Decimal::from_str(".12200").unwrap().to_string(), "0.122"); assert_eq!(Decimal::from_str(".12200").unwrap().to_string(), "0.122");
assert_eq!(Decimal::from_str(&MAX.to_string()).unwrap(), MAX);
assert_eq!( assert_eq!(
Decimal::from_str(&MIN.checked_add(STEP).unwrap().to_string()).unwrap(), Decimal::from_str(&Decimal::max_value().to_string()).unwrap(),
MIN.checked_add(STEP).unwrap() Decimal::max_value()
);
assert_eq!(
Decimal::from_str(
&Decimal::min_value()
.checked_add(Decimal::step())
.unwrap()
.to_string()
)
.unwrap(),
Decimal::min_value().checked_add(Decimal::step()).unwrap()
); );
} }
@ -540,15 +559,18 @@ mod tests {
#[test] #[test]
fn add() { fn add() {
assert!(MIN.checked_add(STEP).is_some()); assert!(Decimal::min_value().checked_add(Decimal::step()).is_some());
assert!(MAX.checked_add(STEP).is_none()); assert!(Decimal::max_value().checked_add(Decimal::step()).is_none());
assert_eq!(MAX.checked_add(MIN), Some(-STEP)); assert_eq!(
Decimal::max_value().checked_add(Decimal::min_value()),
Some(-Decimal::step())
);
} }
#[test] #[test]
fn sub() { fn sub() {
assert!(MIN.checked_sub(STEP).is_none()); assert!(Decimal::min_value().checked_sub(Decimal::step()).is_none());
assert!(MAX.checked_sub(STEP).is_some()); assert!(Decimal::max_value().checked_sub(Decimal::step()).is_some());
} }
#[test] #[test]
@ -611,8 +633,14 @@ mod tests {
Decimal::from_str("-2.5").unwrap().round(), Decimal::from_str("-2.5").unwrap().round(),
Decimal::from(-2) Decimal::from(-2)
); );
assert_eq!(Decimal::from(i64::MIN).round(), Decimal::from(i64::MIN)); assert_eq!(
assert_eq!(Decimal::from(i64::MAX).round(), Decimal::from(i64::MAX)); Decimal::from(i64::min_value()).round(),
Decimal::from(i64::min_value())
);
assert_eq!(
Decimal::from(i64::max_value()).round(),
Decimal::from(i64::max_value())
);
} }
#[test] #[test]
@ -624,8 +652,14 @@ mod tests {
Decimal::from_str("-10.5").unwrap().ceil(), Decimal::from_str("-10.5").unwrap().ceil(),
Decimal::from(-10) Decimal::from(-10)
); );
assert_eq!(Decimal::from(i64::MIN).ceil(), Decimal::from(i64::MIN)); assert_eq!(
assert_eq!(Decimal::from(i64::MAX).ceil(), Decimal::from(i64::MAX)); Decimal::from(i64::min_value()).ceil(),
Decimal::from(i64::min_value())
);
assert_eq!(
Decimal::from(i64::max_value()).ceil(),
Decimal::from(i64::max_value())
);
} }
#[test] #[test]
@ -640,7 +674,13 @@ mod tests {
Decimal::from_str("-10.5").unwrap().floor(), Decimal::from_str("-10.5").unwrap().floor(),
Decimal::from(-11) Decimal::from(-11)
); );
assert_eq!(Decimal::from(i64::MIN).floor(), Decimal::from(i64::MIN)); assert_eq!(
assert_eq!(Decimal::from(i64::MAX).floor(), Decimal::from(i64::MAX)); Decimal::from(i64::min_value()).floor(),
Decimal::from(i64::min_value())
);
assert_eq!(
Decimal::from(i64::max_value()).floor(),
Decimal::from(i64::max_value())
);
} }
} }

@ -5,7 +5,6 @@ use crate::model::xsd::decimal::DecimalOverflowError;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::fmt; use std::fmt;
use std::i64;
use std::ops::Neg; use std::ops::Neg;
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration as StdDuration; use std::time::Duration as StdDuration;
@ -238,10 +237,10 @@ mod tests {
#[test] #[test]
fn from_str() { fn from_str() {
let min = Duration::new( let min = Duration::new(
i64::MIN + 1, i64::min_value() + 1,
decimal::MIN.checked_add(decimal::STEP).unwrap(), Decimal::min_value().checked_add(Decimal::step()).unwrap(),
); );
let max = Duration::new(i64::MAX, decimal::MAX); let max = Duration::new(i64::max_value(), Decimal::max_value());
assert_eq!(Duration::from_str("P1Y").unwrap().to_string(), "P1Y"); assert_eq!(Duration::from_str("P1Y").unwrap().to_string(), "P1Y");
assert_eq!(Duration::from_str("P1M").unwrap().to_string(), "P1M"); assert_eq!(Duration::from_str("P1M").unwrap().to_string(), "P1M");

@ -724,7 +724,7 @@ RelationalExpression -> Expression =
">=" => Expression::GreaterOrEq(Box::new(a), Box::new(b)), ">=" => Expression::GreaterOrEq(Box::new(a), Box::new(b)),
"<" => Expression::Lower(Box::new(a), Box::new(b)), "<" => Expression::Lower(Box::new(a), Box::new(b)),
"<=" => Expression::LowerOrEq(Box::new(a), Box::new(b)), "<=" => Expression::LowerOrEq(Box::new(a), Box::new(b)),
_ => panic!() // Could never happen _ => unreachable!()
} }
} / } /
a:NumericExpression _ "IN"i _ b:ExpressionList { Expression::In(Box::new(a), b) } / a:NumericExpression _ "IN"i _ b:ExpressionList { Expression::In(Box::new(a), b) } /
@ -739,7 +739,7 @@ AdditiveExpression -> Expression =
a:MultiplicativeExpression _ s: $('+' / '-') _ b:AdditiveExpression { match s { a:MultiplicativeExpression _ s: $('+' / '-') _ b:AdditiveExpression { match s {
"+" => Expression::Add(Box::new(a), Box::new(b)), "+" => Expression::Add(Box::new(a), Box::new(b)),
"-" => Expression::Sub(Box::new(a), Box::new(b)), "-" => Expression::Sub(Box::new(a), Box::new(b)),
_ => panic!() // Could never happen _ => unreachable!()
} } / MultiplicativeExpression } } / MultiplicativeExpression
//[117] //[117]
@ -747,7 +747,7 @@ MultiplicativeExpression -> Expression =
a:UnaryExpression _ s: $('*' / '/') _ b:MultiplicativeExpression { match s { a:UnaryExpression _ s: $('*' / '/') _ b:MultiplicativeExpression { match s {
"*" => Expression::Mul(Box::new(a), Box::new(b)), "*" => Expression::Mul(Box::new(a), Box::new(b)),
"/" => Expression::Div(Box::new(a), Box::new(b)), "/" => Expression::Div(Box::new(a), Box::new(b)),
_ => panic!() // Could never happen _ => unreachable!()
} } / UnaryExpression } } / UnaryExpression
//[118] //[118]
@ -756,7 +756,7 @@ UnaryExpression -> Expression = s: $('!' / '+' / '-')? _ e:PrimaryExpression { m
"+" => Expression::UnaryPlus(Box::new(e)), "+" => Expression::UnaryPlus(Box::new(e)),
"-" => Expression::UnaryMinus(Box::new(e)), "-" => Expression::UnaryMinus(Box::new(e)),
"" => e, "" => e,
_ => panic!() // Could never happen _ => unreachable!()
} } } }
//[119] //[119]

@ -680,7 +680,7 @@ fn repository() -> Result<()> {
let mut connection = repository.connection()?; let mut connection = repository.connection()?;
connection.insert(&main_quad)?; connection.insert(&main_quad)?;
for t in &all_o { for t in &all_o {
connection.insert(&t)?; connection.insert(t)?;
} }
let target = vec![main_quad]; let target = vec![main_quad];

@ -336,12 +336,12 @@ fn to_graph(result: QueryResult<'_>, with_order: bool) -> Result<SimpleGraph> {
let mut graph = SimpleGraph::default(); let mut graph = SimpleGraph::default();
let result_set = BlankNode::default(); let result_set = BlankNode::default();
graph.insert(Triple::new( graph.insert(Triple::new(
result_set.clone(), result_set,
rdf::TYPE.clone(), rdf::TYPE.clone(),
rs::RESULT_SET.clone(), rs::RESULT_SET.clone(),
)); ));
graph.insert(Triple::new( graph.insert(Triple::new(
result_set.clone(), result_set,
rs::BOOLEAN.clone(), rs::BOOLEAN.clone(),
Literal::from(value), Literal::from(value),
)); ));
@ -351,14 +351,14 @@ fn to_graph(result: QueryResult<'_>, with_order: bool) -> Result<SimpleGraph> {
let mut graph = SimpleGraph::default(); let mut graph = SimpleGraph::default();
let result_set = BlankNode::default(); let result_set = BlankNode::default();
graph.insert(Triple::new( graph.insert(Triple::new(
result_set.clone(), result_set,
rdf::TYPE.clone(), rdf::TYPE.clone(),
rs::RESULT_SET.clone(), rs::RESULT_SET.clone(),
)); ));
let (variables, iter) = bindings.destruct(); let (variables, iter) = bindings.destruct();
for variable in &variables { for variable in &variables {
graph.insert(Triple::new( graph.insert(Triple::new(
result_set.clone(), result_set,
rs::RESULT_VARIABLE.clone(), rs::RESULT_VARIABLE.clone(),
Literal::new_simple_literal(variable.name()?), Literal::new_simple_literal(variable.name()?),
)); ));
@ -366,26 +366,14 @@ fn to_graph(result: QueryResult<'_>, with_order: bool) -> Result<SimpleGraph> {
for (i, binding_values) in iter.enumerate() { for (i, binding_values) in iter.enumerate() {
let binding_values = binding_values?; let binding_values = binding_values?;
let solution = BlankNode::default(); let solution = BlankNode::default();
graph.insert(Triple::new( graph.insert(Triple::new(result_set, rs::SOLUTION.clone(), solution));
result_set.clone(),
rs::SOLUTION.clone(),
solution.clone(),
));
for i in 0..variables.len() { for i in 0..variables.len() {
if let Some(ref value) = binding_values[i] { if let Some(ref value) = binding_values[i] {
let binding = BlankNode::default(); let binding = BlankNode::default();
graph.insert(Triple::new(solution, rs::BINDING.clone(), binding));
graph.insert(Triple::new(binding, rs::VALUE.clone(), value.clone()));
graph.insert(Triple::new( graph.insert(Triple::new(
solution.clone(), binding,
rs::BINDING.clone(),
binding.clone(),
));
graph.insert(Triple::new(
binding.clone(),
rs::VALUE.clone(),
value.clone(),
));
graph.insert(Triple::new(
binding.clone(),
rs::VARIABLE.clone(), rs::VARIABLE.clone(),
Literal::new_simple_literal(variables[i].name()?), Literal::new_simple_literal(variables[i].name()?),
)); ));
@ -393,7 +381,7 @@ fn to_graph(result: QueryResult<'_>, with_order: bool) -> Result<SimpleGraph> {
} }
if with_order { if with_order {
graph.insert(Triple::new( graph.insert(Triple::new(
solution.clone(), solution,
rs::INDEX.clone(), rs::INDEX.clone(),
Literal::from((i + 1) as i128), Literal::from((i + 1) as i128),
)); ));

Loading…
Cancel
Save