fix clippy lints for latest Rust
This commit is contained in:
parent
108af51abe
commit
b392020798
@ -3,16 +3,18 @@
|
||||
|
||||
mod generated;
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use fluent::{types::FluentNumber, FluentArgs, FluentResource, FluentValue};
|
||||
use fluent_bundle::bundle::FluentBundle as FluentBundleOrig;
|
||||
use generated::{KEYS_BY_MODULE, STRINGS};
|
||||
use num_format::Locale;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use unic_langid::LanguageIdentifier;
|
||||
|
||||
use generated::{KEYS_BY_MODULE, STRINGS};
|
||||
|
||||
type FluentBundle<T> = FluentBundleOrig<T, intl_memoizer::concurrent::IntlLangMemoizer>;
|
||||
|
||||
pub use fluent::fluent_args as tr_args;
|
||||
@ -26,10 +28,7 @@ impl Number for u64 {}
|
||||
impl Number for usize {}
|
||||
|
||||
fn remapped_lang_name(lang: &LanguageIdentifier) -> &str {
|
||||
let region = match &lang.region {
|
||||
Some(region) => Some(region.as_str()),
|
||||
None => None,
|
||||
};
|
||||
let region = lang.region.as_ref().map(|v| v.as_str());
|
||||
match lang.language.as_str() {
|
||||
"en" => {
|
||||
match region {
|
||||
@ -425,13 +424,14 @@ pub struct ResourcesForJavascript {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use unic_langid::langid;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn numbers() {
|
||||
assert_eq!(want_comma_as_decimal_separator(&[langid!("en-US")]), false);
|
||||
assert_eq!(want_comma_as_decimal_separator(&[langid!("pl-PL")]), true);
|
||||
assert!(!want_comma_as_decimal_separator(&[langid!("en-US")]));
|
||||
assert!(want_comma_as_decimal_separator(&[langid!("pl-PL")]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -36,8 +36,8 @@ impl CardRenderingService for Backend {
|
||||
field_text,
|
||||
lang,
|
||||
voices,
|
||||
other_args,
|
||||
speed,
|
||||
other_args,
|
||||
})),
|
||||
},
|
||||
})
|
||||
|
@ -50,7 +50,7 @@ impl ToSql for SqlValue {
|
||||
SqlValue::String(v) => ValueRef::Text(v.as_bytes()),
|
||||
SqlValue::Int(v) => ValueRef::Integer(*v),
|
||||
SqlValue::Double(v) => ValueRef::Real(*v),
|
||||
SqlValue::Blob(v) => ValueRef::Blob(&v),
|
||||
SqlValue::Blob(v) => ValueRef::Blob(v),
|
||||
};
|
||||
Ok(ToSqlOutput::Borrowed(val))
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ pub(super) fn progress_to_proto(progress: Option<Progress>, tr: &I18n) -> pb::Pr
|
||||
.to_string();
|
||||
pb::progress::Value::DatabaseCheck(pb::progress::DatabaseCheck {
|
||||
stage,
|
||||
stage_current,
|
||||
stage_total,
|
||||
stage_current,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -150,8 +150,8 @@ impl Card {
|
||||
pub fn new(note_id: NoteId, template_idx: u16, deck_id: DeckId, due: i32) -> Self {
|
||||
Card {
|
||||
note_id,
|
||||
template_idx,
|
||||
deck_id,
|
||||
template_idx,
|
||||
due,
|
||||
..Default::default()
|
||||
}
|
||||
|
@ -82,35 +82,35 @@ mod test {
|
||||
let key = BoolKey::NormalizeNoteText;
|
||||
|
||||
// not set by default, but defaults to true
|
||||
assert_eq!(col.get_config_bool(key), true);
|
||||
assert!(col.get_config_bool(key));
|
||||
|
||||
// first set adds the key
|
||||
col.transact(op.clone(), |col| col.set_config_bool_inner(key, false))?;
|
||||
assert_eq!(col.get_config_bool(key), false);
|
||||
assert!(!col.get_config_bool(key));
|
||||
|
||||
// mutate it twice
|
||||
col.transact(op.clone(), |col| col.set_config_bool_inner(key, true))?;
|
||||
assert_eq!(col.get_config_bool(key), true);
|
||||
assert!(col.get_config_bool(key));
|
||||
col.transact(op.clone(), |col| col.set_config_bool_inner(key, false))?;
|
||||
assert_eq!(col.get_config_bool(key), false);
|
||||
assert!(!col.get_config_bool(key));
|
||||
|
||||
// when we remove it, it goes back to its default
|
||||
col.transact(op, |col| col.remove_config_inner(key))?;
|
||||
assert_eq!(col.get_config_bool(key), true);
|
||||
assert!(col.get_config_bool(key));
|
||||
|
||||
// undo the removal
|
||||
col.undo()?;
|
||||
assert_eq!(col.get_config_bool(key), false);
|
||||
assert!(!col.get_config_bool(key));
|
||||
|
||||
// undo the mutations
|
||||
col.undo()?;
|
||||
assert_eq!(col.get_config_bool(key), true);
|
||||
assert!(col.get_config_bool(key));
|
||||
col.undo()?;
|
||||
assert_eq!(col.get_config_bool(key), false);
|
||||
assert!(!col.get_config_bool(key));
|
||||
|
||||
// and undo the initial add
|
||||
col.undo()?;
|
||||
assert_eq!(col.get_config_bool(key), true);
|
||||
assert!(col.get_config_bool(key));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ impl Collection {
|
||||
CardGenContext::new(&nt, self.get_last_deck_added_to_for_notetype(nt.id), usn)
|
||||
});
|
||||
self.update_note_inner_generating_cards(
|
||||
&ctx, &mut note, &original, false, norm, true,
|
||||
ctx, &mut note, &original, false, norm, true,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@ -480,11 +480,9 @@ mod test {
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
col.storage
|
||||
.db_scalar::<bool>("select ivl = lastIvl = 1 from revlog")?,
|
||||
true
|
||||
);
|
||||
assert!(col
|
||||
.storage
|
||||
.db_scalar::<bool>("select ivl = lastIvl = 1 from revlog")?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -625,8 +623,8 @@ mod test {
|
||||
|
||||
col.check_database(progress_fn)?;
|
||||
|
||||
assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true);
|
||||
assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false);
|
||||
assert!(col.storage.get_tag("one")?.unwrap().expanded);
|
||||
assert!(!col.storage.get_tag("two")?.unwrap().expanded);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -229,17 +229,14 @@ mod test {
|
||||
removed_config_ids: vec![],
|
||||
apply_to_children: false,
|
||||
};
|
||||
assert_eq!(
|
||||
col.update_deck_configs(input.clone())?.changes.had_change(),
|
||||
false
|
||||
);
|
||||
assert!(!col.update_deck_configs(input.clone())?.changes.had_change());
|
||||
|
||||
// modifying a value should update the config, but not the deck
|
||||
input.configs[0].inner.new_per_day += 1;
|
||||
let changes = col.update_deck_configs(input.clone())?.changes.changes;
|
||||
assert_eq!(changes.deck, false);
|
||||
assert_eq!(changes.deck_config, true);
|
||||
assert_eq!(changes.card, false);
|
||||
assert!(!changes.deck);
|
||||
assert!(changes.deck_config);
|
||||
assert!(!changes.card);
|
||||
|
||||
// adding a new config will update the deck as well
|
||||
let new_config = DeckConfig {
|
||||
@ -248,9 +245,9 @@ mod test {
|
||||
};
|
||||
input.configs.push(new_config);
|
||||
let changes = col.update_deck_configs(input.clone())?.changes.changes;
|
||||
assert_eq!(changes.deck, true);
|
||||
assert_eq!(changes.deck_config, true);
|
||||
assert_eq!(changes.card, false);
|
||||
assert!(changes.deck);
|
||||
assert!(changes.deck_config);
|
||||
assert!(!changes.card);
|
||||
let allocated_id = col.get_deck(DeckId(1))?.unwrap().normal()?.config_id;
|
||||
assert_ne!(allocated_id, 0);
|
||||
assert_ne!(allocated_id, 1);
|
||||
@ -260,10 +257,7 @@ mod test {
|
||||
reset_card1_pos(&mut col);
|
||||
assert_eq!(card1_pos(&mut col), 0);
|
||||
input.configs[1].inner.new_card_insert_order = NewCardInsertOrder::Random as i32;
|
||||
assert_eq!(
|
||||
col.update_deck_configs(input.clone())?.changes.changes.card,
|
||||
true
|
||||
);
|
||||
assert!(col.update_deck_configs(input.clone())?.changes.changes.card);
|
||||
assert_ne!(card1_pos(&mut col), 0);
|
||||
|
||||
// removing the config will assign the selected config (default in this case),
|
||||
|
@ -271,13 +271,8 @@ impl Collection {
|
||||
}
|
||||
|
||||
if let Some(now) = now {
|
||||
let limit = top_deck_id.and_then(|did| {
|
||||
if let Some(deck) = decks_map.get(&did) {
|
||||
Some(deck.name.as_native_str())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
let limit = top_deck_id
|
||||
.and_then(|did| decks_map.get(&did).map(|deck| deck.name.as_native_str()));
|
||||
let days_elapsed = self.timing_for_timestamp(now)?.days_elapsed;
|
||||
let learn_cutoff = (now.0 as u32) + self.learn_ahead_secs();
|
||||
let sched_ver = self.scheduler_version();
|
||||
|
@ -80,7 +80,7 @@ impl AnkiError {
|
||||
format!("{}<br>{}", header, details)
|
||||
}
|
||||
AnkiError::DbError(err) => err.localized_description(tr),
|
||||
AnkiError::SearchError(kind) => kind.localized_description(&tr),
|
||||
AnkiError::SearchError(kind) => kind.localized_description(tr),
|
||||
AnkiError::InvalidInput(info) => {
|
||||
if info.is_empty() {
|
||||
tr.errors_invalid_input_empty().into()
|
||||
|
@ -114,7 +114,7 @@ where
|
||||
};
|
||||
|
||||
// make sure the filename is normalized
|
||||
let fname = match filename_if_normalized(&disk_fname) {
|
||||
let fname = match filename_if_normalized(disk_fname) {
|
||||
Some(fname) => fname,
|
||||
None => {
|
||||
// not normalized; skip it
|
||||
|
@ -227,7 +227,7 @@ where
|
||||
} else {
|
||||
match data_for_file(&self.mgr.media_folder, disk_fname)? {
|
||||
Some(data) => {
|
||||
let norm_name = self.normalize_file(ctx, &disk_fname, data)?;
|
||||
let norm_name = self.normalize_file(ctx, disk_fname, data)?;
|
||||
out.renamed
|
||||
.insert(disk_fname.to_string(), norm_name.to_string());
|
||||
out.files.push(norm_name.into_owned());
|
||||
|
@ -106,7 +106,7 @@ impl MediaManager {
|
||||
{
|
||||
let pre_remove_folder_mtime = mtime_as_i64(&self.media_folder)?;
|
||||
|
||||
remove_files(&self.media_folder, &filenames)?;
|
||||
remove_files(&self.media_folder, filenames)?;
|
||||
|
||||
let post_remove_folder_mtime = mtime_as_i64(&self.media_folder)?;
|
||||
|
||||
|
@ -260,7 +260,7 @@ where
|
||||
let resp = self
|
||||
.client
|
||||
.get(&url)
|
||||
.query(&[("k", hkey), ("v", &sync_client_version())])
|
||||
.query(&[("k", hkey), ("v", sync_client_version())])
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?;
|
||||
|
@ -135,7 +135,7 @@ impl Note {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::clippy::too_many_arguments)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new_from_storage(
|
||||
id: NoteId,
|
||||
guid: String,
|
||||
@ -323,7 +323,7 @@ fn invalid_char_for_field(c: char) -> bool {
|
||||
impl Collection {
|
||||
fn canonify_note_tags(&mut self, note: &mut Note, usn: Usn) -> Result<()> {
|
||||
if !note.tags.is_empty() {
|
||||
let tags = std::mem::replace(&mut note.tags, vec![]);
|
||||
let tags = std::mem::take(&mut note.tags);
|
||||
note.tags = self.canonify_tags(tags, usn)?.0;
|
||||
}
|
||||
Ok(())
|
||||
@ -337,7 +337,7 @@ impl Collection {
|
||||
normalize_text: bool,
|
||||
) -> Result<()> {
|
||||
self.canonify_note_tags(note, ctx.usn)?;
|
||||
note.prepare_for_update(&ctx.notetype, normalize_text)?;
|
||||
note.prepare_for_update(ctx.notetype, normalize_text)?;
|
||||
note.set_modified(ctx.usn);
|
||||
self.add_note_only_undoable(note)?;
|
||||
self.generate_cards_for_new_note(ctx, note, did)?;
|
||||
@ -415,7 +415,7 @@ impl Collection {
|
||||
}
|
||||
|
||||
// TODO: refactor into struct
|
||||
#[allow(clippy::clippy::too_many_arguments)]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn update_note_inner_without_cards(
|
||||
&mut self,
|
||||
note: &mut Note,
|
||||
@ -504,7 +504,7 @@ impl Collection {
|
||||
)
|
||||
});
|
||||
self.update_note_inner_generating_cards(
|
||||
&ctx,
|
||||
ctx,
|
||||
&mut note,
|
||||
&original,
|
||||
out.mark_modified,
|
||||
@ -559,7 +559,7 @@ impl Collection {
|
||||
}
|
||||
|
||||
fn is_duplicate(&self, first_field: &str, note: &Note) -> Result<bool> {
|
||||
let csum = field_checksum(&first_field);
|
||||
let csum = field_checksum(first_field);
|
||||
Ok(self
|
||||
.storage
|
||||
.note_fields_by_checksum(note.notetype_id, csum)?
|
||||
@ -735,7 +735,7 @@ mod test {
|
||||
col.storage.db_scalar::<u32>("select count() from graves")?,
|
||||
0
|
||||
);
|
||||
assert_eq!(col.get_next_card()?.is_some(), false);
|
||||
assert!(!col.get_next_card()?.is_some());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@ -746,7 +746,7 @@ mod test {
|
||||
col.storage.db_scalar::<u32>("select count() from graves")?,
|
||||
0
|
||||
);
|
||||
assert_eq!(col.get_next_card()?.is_some(), true);
|
||||
assert!(col.get_next_card()?.is_some());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
@ -774,7 +774,7 @@ mod test {
|
||||
col.storage.db_scalar::<u32>("select count() from graves")?,
|
||||
3
|
||||
);
|
||||
assert_eq!(col.get_next_card()?.is_some(), false);
|
||||
assert!(!col.get_next_card()?.is_some());
|
||||
Ok(())
|
||||
};
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl CardGenContext<'_> {
|
||||
CardGenContext {
|
||||
usn,
|
||||
last_deck,
|
||||
notetype: &nt,
|
||||
notetype: nt,
|
||||
cards: nt
|
||||
.templates
|
||||
.iter()
|
||||
@ -82,7 +82,7 @@ impl CardGenContext<'_> {
|
||||
}
|
||||
};
|
||||
|
||||
template.renders_with_fields(&nonempty_fields)
|
||||
template.renders_with_fields(nonempty_fields)
|
||||
}
|
||||
|
||||
/// Returns the cards that need to be generated for the provided note.
|
||||
@ -239,7 +239,7 @@ impl Collection {
|
||||
target_deck_id: Option<DeckId>,
|
||||
cache: &mut CardGenCache,
|
||||
) -> Result<()> {
|
||||
let cards = ctx.new_cards_required(note, &existing, true);
|
||||
let cards = ctx.new_cards_required(note, existing, true);
|
||||
if cards.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
@ -337,13 +337,9 @@ impl Collection {
|
||||
|
||||
/// If deck exists and and is a normal deck, return its ID and config
|
||||
fn deck_conf_if_normal(&mut self, did: DeckId) -> Result<Option<(DeckId, DeckConfigId)>> {
|
||||
Ok(self.get_deck(did)?.and_then(|d| {
|
||||
if let Some(conf_id) = d.config_id() {
|
||||
Some((did, conf_id))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}))
|
||||
Ok(self
|
||||
.get_deck(did)?
|
||||
.and_then(|d| d.config_id().map(|conf_id| (did, conf_id))))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ impl Default for Notetype {
|
||||
|
||||
impl Notetype {
|
||||
pub fn new_note(&self) -> Note {
|
||||
Note::new(&self)
|
||||
Note::new(self)
|
||||
}
|
||||
|
||||
/// Return the template for the given card ordinal. Cloze notetypes
|
||||
@ -200,7 +200,7 @@ impl Collection {
|
||||
return Err(AnkiError::NotFound);
|
||||
}
|
||||
|
||||
let nids_node: Node = SearchNode::NoteIds(comma_separated_ids(¬e_ids)).into();
|
||||
let nids_node: Node = SearchNode::NoteIds(comma_separated_ids(note_ids)).into();
|
||||
let note1 = self
|
||||
.storage
|
||||
.get_note(*note_ids.first().unwrap())?
|
||||
@ -663,7 +663,7 @@ impl Collection {
|
||||
// adding with existing id for old undo code, bypass undo
|
||||
self.state.notetype_cache.remove(¬etype.id);
|
||||
self.storage
|
||||
.add_or_update_notetype_with_existing_id(¬etype)?;
|
||||
.add_or_update_notetype_with_existing_id(notetype)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -56,7 +56,7 @@ impl TemplateMap {
|
||||
.collect();
|
||||
|
||||
let removed: Vec<_> = (0..old_template_count)
|
||||
.filter(|idx| !seen.contains(&idx))
|
||||
.filter(|idx| !seen.contains(idx))
|
||||
.collect();
|
||||
|
||||
TemplateMap { removed, remapped }
|
||||
|
@ -96,7 +96,7 @@ impl Collection {
|
||||
let mut field_map = note.fields_map(&nt.fields);
|
||||
|
||||
let card_num;
|
||||
self.add_special_fields(&mut field_map, note, card, &nt, template)?;
|
||||
self.add_special_fields(&mut field_map, note, card, nt, template)?;
|
||||
// due to lifetime restrictions we need to add card number here
|
||||
card_num = format!("c{}", card.template_idx + 1);
|
||||
field_map.entry(&card_num).or_insert_with(|| "1".into());
|
||||
|
@ -48,7 +48,7 @@ impl TemplateOrdChanges {
|
||||
}
|
||||
}
|
||||
|
||||
changes.removed = removed.into_iter().filter_map(|v| v).collect();
|
||||
changes.removed = removed.into_iter().flatten().collect();
|
||||
|
||||
changes
|
||||
}
|
||||
@ -83,11 +83,10 @@ impl Collection {
|
||||
false,
|
||||
)?;
|
||||
}
|
||||
return Ok(());
|
||||
} else {
|
||||
// nothing to do
|
||||
return Ok(());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// fields have changed
|
||||
@ -192,11 +191,11 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn ord_changes() {
|
||||
assert_eq!(ords_changed(&[Some(0), Some(1)], 2), false);
|
||||
assert_eq!(ords_changed(&[Some(0), Some(1)], 1), true);
|
||||
assert_eq!(ords_changed(&[Some(1), Some(0)], 2), true);
|
||||
assert_eq!(ords_changed(&[None, Some(1)], 2), true);
|
||||
assert_eq!(ords_changed(&[Some(0), Some(1), None], 2), true);
|
||||
assert!(!ords_changed(&[Some(0), Some(1)], 2));
|
||||
assert!(ords_changed(&[Some(0), Some(1)], 1));
|
||||
assert!(ords_changed(&[Some(1), Some(0)], 2));
|
||||
assert!(ords_changed(&[None, Some(1)], 2));
|
||||
assert!(ords_changed(&[Some(0), Some(1), None], 2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -259,9 +259,9 @@ impl Collection {
|
||||
)));
|
||||
}
|
||||
if let Some(revlog_partial) = updater.apply_study_state(current_state, answer.new_state)? {
|
||||
self.add_partial_revlog(revlog_partial, usn, &answer)?;
|
||||
self.add_partial_revlog(revlog_partial, usn, answer)?;
|
||||
}
|
||||
self.update_deck_stats_from_answer(usn, &answer, &updater, original.queue)?;
|
||||
self.update_deck_stats_from_answer(usn, answer, &updater, original.queue)?;
|
||||
self.maybe_bury_siblings(&original, &updater.config)?;
|
||||
let timing = updater.timing;
|
||||
let mut card = updater.into_card();
|
||||
|
@ -147,12 +147,12 @@ mod test {
|
||||
|
||||
let note = col.storage.get_note(nid)?.unwrap();
|
||||
assert_eq!(note.tags, vec!["leech".to_string()]);
|
||||
assert_eq!(col.storage.all_tags()?.is_empty(), false);
|
||||
assert!(!col.storage.all_tags()?.is_empty());
|
||||
|
||||
let deck = col.get_deck(DeckId(1))?.unwrap();
|
||||
assert_eq!(deck.common.review_studied, 1);
|
||||
|
||||
assert_eq!(col.get_next_card()?.is_some(), false);
|
||||
assert!(!col.get_next_card()?.is_some());
|
||||
|
||||
Ok(())
|
||||
};
|
||||
@ -172,12 +172,12 @@ mod test {
|
||||
|
||||
// the note should no longer be tagged as a leech
|
||||
let note = col.storage.get_note(nid)?.unwrap();
|
||||
assert_eq!(note.tags.is_empty(), true);
|
||||
assert_eq!(col.storage.all_tags()?.is_empty(), true);
|
||||
assert!(note.tags.is_empty());
|
||||
assert!(col.storage.all_tags()?.is_empty());
|
||||
|
||||
let deck = col.get_deck(DeckId(1))?.unwrap();
|
||||
assert_eq!(deck.common.review_studied, 0);
|
||||
assert_eq!(col.get_next_card()?.is_some(), true);
|
||||
assert!(col.get_next_card()?.is_some());
|
||||
assert_eq!(col.counts(), [0, 0, 1]);
|
||||
|
||||
Ok(())
|
||||
|
@ -49,8 +49,8 @@ impl CardState {
|
||||
|
||||
pub(crate) fn next_states(self, ctx: &StateContext) -> NextCardStates {
|
||||
match self {
|
||||
CardState::Normal(state) => state.next_states(&ctx),
|
||||
CardState::Filtered(state) => state.next_states(&ctx),
|
||||
CardState::Normal(state) => state.next_states(ctx),
|
||||
CardState::Filtered(state) => state.next_states(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ impl ReschedulingFilterState {
|
||||
}
|
||||
|
||||
pub(crate) fn next_states(self, ctx: &StateContext) -> NextCardStates {
|
||||
let normal = self.original_state.next_states(&ctx);
|
||||
let normal = self.original_state.next_states(ctx);
|
||||
if ctx.in_filtered_deck {
|
||||
NextCardStates {
|
||||
current: self.into(),
|
||||
|
@ -237,30 +237,30 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn leech_threshold() {
|
||||
assert_eq!(leech_threshold_met(0, 3), false);
|
||||
assert_eq!(leech_threshold_met(1, 3), false);
|
||||
assert_eq!(leech_threshold_met(2, 3), false);
|
||||
assert_eq!(leech_threshold_met(3, 3), true);
|
||||
assert_eq!(leech_threshold_met(4, 3), false);
|
||||
assert_eq!(leech_threshold_met(5, 3), true);
|
||||
assert_eq!(leech_threshold_met(6, 3), false);
|
||||
assert_eq!(leech_threshold_met(7, 3), true);
|
||||
assert!(!leech_threshold_met(0, 3));
|
||||
assert!(!leech_threshold_met(1, 3));
|
||||
assert!(!leech_threshold_met(2, 3));
|
||||
assert!(leech_threshold_met(3, 3));
|
||||
assert!(!leech_threshold_met(4, 3));
|
||||
assert!(leech_threshold_met(5, 3));
|
||||
assert!(!leech_threshold_met(6, 3));
|
||||
assert!(leech_threshold_met(7, 3));
|
||||
|
||||
assert_eq!(leech_threshold_met(7, 8), false);
|
||||
assert_eq!(leech_threshold_met(8, 8), true);
|
||||
assert_eq!(leech_threshold_met(9, 8), false);
|
||||
assert_eq!(leech_threshold_met(10, 8), false);
|
||||
assert_eq!(leech_threshold_met(11, 8), false);
|
||||
assert_eq!(leech_threshold_met(12, 8), true);
|
||||
assert_eq!(leech_threshold_met(13, 8), false);
|
||||
assert!(!leech_threshold_met(7, 8));
|
||||
assert!(leech_threshold_met(8, 8));
|
||||
assert!(!leech_threshold_met(9, 8));
|
||||
assert!(!leech_threshold_met(10, 8));
|
||||
assert!(!leech_threshold_met(11, 8));
|
||||
assert!(leech_threshold_met(12, 8));
|
||||
assert!(!leech_threshold_met(13, 8));
|
||||
|
||||
// 0 means off
|
||||
assert_eq!(leech_threshold_met(0, 0), false);
|
||||
assert!(!leech_threshold_met(0, 0));
|
||||
|
||||
// no div by zero; half of 1 is 1
|
||||
assert_eq!(leech_threshold_met(0, 1), false);
|
||||
assert_eq!(leech_threshold_met(1, 1), true);
|
||||
assert_eq!(leech_threshold_met(2, 1), true);
|
||||
assert_eq!(leech_threshold_met(3, 1), true);
|
||||
assert!(!leech_threshold_met(0, 1));
|
||||
assert!(leech_threshold_met(1, 1));
|
||||
assert!(leech_threshold_met(2, 1));
|
||||
assert!(leech_threshold_met(3, 1));
|
||||
}
|
||||
}
|
||||
|
@ -705,7 +705,7 @@ fn unescape(txt: &str) -> ParseResult<String> {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r#"\\[\\":()-]"#).unwrap();
|
||||
}
|
||||
RE.replace_all(&txt, |caps: &Captures| match &caps[0] {
|
||||
RE.replace_all(txt, |caps: &Captures| match &caps[0] {
|
||||
r"\\" => r"\\",
|
||||
"\\\"" => "\"",
|
||||
r"\:" => ":",
|
||||
|
@ -53,7 +53,7 @@ impl SqlWriter<'_> {
|
||||
) -> Result<(String, Vec<String>)> {
|
||||
self.table = self.table.combine(table.combine(node.required_table()));
|
||||
self.write_table_sql();
|
||||
self.write_node_to_sql(&node)?;
|
||||
self.write_node_to_sql(node)?;
|
||||
Ok((self.sql, self.args))
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl super::SqliteStorage {
|
||||
note.mtime,
|
||||
note.usn,
|
||||
join_tags(¬e.tags),
|
||||
join_fields(¬e.fields()),
|
||||
join_fields(note.fields()),
|
||||
note.sort_field.as_ref().unwrap(),
|
||||
note.checksum.unwrap(),
|
||||
note.id
|
||||
@ -69,7 +69,7 @@ impl super::SqliteStorage {
|
||||
note.mtime,
|
||||
note.usn,
|
||||
join_tags(¬e.tags),
|
||||
join_fields(¬e.fields()),
|
||||
join_fields(note.fields()),
|
||||
note.sort_field.as_ref().unwrap(),
|
||||
note.checksum.unwrap(),
|
||||
])?;
|
||||
@ -87,7 +87,7 @@ impl super::SqliteStorage {
|
||||
note.mtime,
|
||||
note.usn,
|
||||
join_tags(¬e.tags),
|
||||
join_fields(¬e.fields()),
|
||||
join_fields(note.fields()),
|
||||
note.sort_field.as_ref().unwrap(),
|
||||
note.checksum.unwrap(),
|
||||
])?;
|
||||
|
@ -428,7 +428,7 @@ mod test {
|
||||
syncer.set_full_sync_progress_fn(Some(Box::new(|progress, _throttle| {
|
||||
println!("progress {:?}", progress);
|
||||
})));
|
||||
syncer.full_upload(&out_path.path(), false).await?;
|
||||
syncer.full_upload(out_path.path(), false).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -84,6 +84,6 @@ mod test {
|
||||
|
||||
assert_eq!(&add_to(""), " abc DEF xyz ");
|
||||
assert_eq!(&add_to("XYZ deF aaa"), " aaa abc deF XYZ ");
|
||||
assert_eq!(add_missing_tags("def xyz abc", &desired).is_none(), true);
|
||||
assert!(add_missing_tags("def xyz abc", &desired).is_none());
|
||||
}
|
||||
}
|
||||
|
@ -131,17 +131,17 @@ mod test {
|
||||
#[test]
|
||||
fn regex() -> Result<()> {
|
||||
let re = TagMatcher::new("one two")?;
|
||||
assert_eq!(re.is_match(" foo "), false);
|
||||
assert_eq!(re.is_match(" foo one "), true);
|
||||
assert_eq!(re.is_match(" two foo "), true);
|
||||
assert!(!re.is_match(" foo "));
|
||||
assert!(re.is_match(" foo one "));
|
||||
assert!(re.is_match(" two foo "));
|
||||
|
||||
let mut re = TagMatcher::new("foo")?;
|
||||
assert_eq!(re.is_match("foo"), true);
|
||||
assert_eq!(re.is_match(" foo "), true);
|
||||
assert_eq!(re.is_match(" bar foo baz "), true);
|
||||
assert_eq!(re.is_match(" bar FOO baz "), true);
|
||||
assert_eq!(re.is_match(" bar foof baz "), false);
|
||||
assert_eq!(re.is_match(" barfoo "), false);
|
||||
assert!(re.is_match("foo"));
|
||||
assert!(re.is_match(" foo "));
|
||||
assert!(re.is_match(" bar foo baz "));
|
||||
assert!(re.is_match(" bar FOO baz "));
|
||||
assert!(!re.is_match(" bar foof baz "));
|
||||
assert!(!re.is_match(" barfoo "));
|
||||
|
||||
let mut as_xxx = |text| re.replace(text, "xxx");
|
||||
|
||||
|
@ -65,7 +65,7 @@ impl Collection {
|
||||
pub(crate) fn register_tag(&mut self, tag: &mut Tag) -> Result<bool> {
|
||||
let is_new = self.prepare_tag_for_registering(tag)?;
|
||||
if is_new {
|
||||
self.register_tag_undoable(&tag)?;
|
||||
self.register_tag_undoable(tag)?;
|
||||
}
|
||||
Ok(is_new)
|
||||
}
|
||||
@ -100,7 +100,7 @@ impl Collection {
|
||||
impl Collection {
|
||||
/// If parent tag(s) exist and differ in case, return a rewritten tag.
|
||||
fn adjusted_case_for_parents(&self, tag: &str) -> Result<Option<String>> {
|
||||
if let Some(parent_tag) = self.first_existing_parent_tag(&tag)? {
|
||||
if let Some(parent_tag) = self.first_existing_parent_tag(tag)? {
|
||||
let child_split: Vec<_> = tag.split("::").collect();
|
||||
let parent_count = parent_tag.matches("::").count() + 1;
|
||||
Ok(Some(format!(
|
||||
|
@ -109,8 +109,8 @@ mod test {
|
||||
|
||||
col.set_tag_collapsed("one", false)?;
|
||||
col.clear_unused_tags()?;
|
||||
assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true);
|
||||
assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false);
|
||||
assert!(col.storage.get_tag("one")?.unwrap().expanded);
|
||||
assert!(!col.storage.get_tag("two")?.unwrap().expanded);
|
||||
|
||||
// tag children are also cleared when clearing their parent
|
||||
col.storage.clear_all_tags()?;
|
||||
|
@ -82,12 +82,8 @@ fn old_to_new_names(
|
||||
.iter()
|
||||
// generate resulting names and filter out invalid ones
|
||||
.flat_map(|source_tag| {
|
||||
if let Some(output_name) = reparented_name(source_tag, new_parent.as_deref()) {
|
||||
Some((source_tag.as_str(), output_name))
|
||||
} else {
|
||||
// invalid rename, ignore this tag
|
||||
None
|
||||
}
|
||||
reparented_name(source_tag, new_parent.as_deref())
|
||||
.map(|output_name| (source_tag.as_str(), output_name))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ impl Collection {
|
||||
|
||||
fn update_tag_inner(&mut self, tag: &mut Tag, original: Tag, usn: Usn) -> Result<()> {
|
||||
tag.set_modified(usn);
|
||||
self.update_tag_undoable(&tag, original)
|
||||
self.update_tag_undoable(tag, original)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ impl Collection {
|
||||
/// Caller is responsible for setting usn.
|
||||
pub(super) fn register_tag_undoable(&mut self, tag: &Tag) -> Result<()> {
|
||||
self.save_undo(UndoableTagChange::Added(Box::new(tag.clone())));
|
||||
self.storage.register_tag(&tag)
|
||||
self.storage.register_tag(tag)
|
||||
}
|
||||
|
||||
/// Remove a single tag from the tag list, saving an undo entry. Does not alter notes.
|
||||
|
@ -656,7 +656,7 @@ impl ParsedTemplate {
|
||||
/// Given a map of old to new field names, update references to the new names.
|
||||
/// Returns true if any changes made.
|
||||
pub(crate) fn rename_and_remove_fields(&mut self, fields: &HashMap<String, Option<String>>) {
|
||||
let old_nodes = std::mem::replace(&mut self.0, vec![]);
|
||||
let old_nodes = std::mem::take(&mut self.0);
|
||||
self.0 = rename_and_remove_fields(old_nodes, fields);
|
||||
}
|
||||
}
|
||||
@ -746,12 +746,12 @@ fn nodes_to_string(buf: &mut String, nodes: &[ParsedNode]) {
|
||||
}
|
||||
ParsedNode::Conditional { key, children } => {
|
||||
write!(buf, "{{{{#{}}}}}", key).unwrap();
|
||||
nodes_to_string(buf, &children);
|
||||
nodes_to_string(buf, children);
|
||||
write!(buf, "{{{{/{}}}}}", key).unwrap();
|
||||
}
|
||||
ParsedNode::NegatedConditional { key, children } => {
|
||||
write!(buf, "{{{{^{}}}}}", key).unwrap();
|
||||
nodes_to_string(buf, &children);
|
||||
nodes_to_string(buf, children);
|
||||
write!(buf, "{{{{/{}}}}}", key).unwrap();
|
||||
}
|
||||
}
|
||||
@ -794,10 +794,10 @@ fn find_fields_with_filter<'a>(
|
||||
}
|
||||
}
|
||||
ParsedNode::Conditional { children, .. } => {
|
||||
find_fields_with_filter(&children, fields, filter);
|
||||
find_fields_with_filter(children, fields, filter);
|
||||
}
|
||||
ParsedNode::NegatedConditional { children, .. } => {
|
||||
find_fields_with_filter(&children, fields, filter);
|
||||
find_fields_with_filter(children, fields, filter);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -819,13 +819,13 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn field_empty() {
|
||||
assert_eq!(field_is_empty(""), true);
|
||||
assert_eq!(field_is_empty(" "), true);
|
||||
assert_eq!(field_is_empty("x"), false);
|
||||
assert_eq!(field_is_empty("<BR>"), true);
|
||||
assert_eq!(field_is_empty("<div />"), true);
|
||||
assert_eq!(field_is_empty(" <div> <br> </div>\n"), true);
|
||||
assert_eq!(field_is_empty(" <div>x</div>\n"), false);
|
||||
assert!(field_is_empty(""));
|
||||
assert!(field_is_empty(" "));
|
||||
assert!(!field_is_empty("x"));
|
||||
assert!(field_is_empty("<BR>"));
|
||||
assert!(field_is_empty("<div />"));
|
||||
assert!(field_is_empty(" <div> <br> </div>\n"));
|
||||
assert!(!field_is_empty(" <div>x</div>\n"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -891,17 +891,17 @@ mod test {
|
||||
fn nonempty() {
|
||||
let fields = vec!["1", "3"].into_iter().collect();
|
||||
let mut tmpl = PT::from_text("{{2}}{{1}}").unwrap();
|
||||
assert_eq!(tmpl.renders_with_fields(&fields), true);
|
||||
assert!(tmpl.renders_with_fields(&fields));
|
||||
tmpl = PT::from_text("{{2}}").unwrap();
|
||||
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
||||
assert!(!tmpl.renders_with_fields(&fields));
|
||||
tmpl = PT::from_text("{{2}}{{4}}").unwrap();
|
||||
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
||||
assert!(!tmpl.renders_with_fields(&fields));
|
||||
tmpl = PT::from_text("{{#3}}{{^2}}{{1}}{{/2}}{{/3}}").unwrap();
|
||||
assert_eq!(tmpl.renders_with_fields(&fields), true);
|
||||
assert!(tmpl.renders_with_fields(&fields));
|
||||
|
||||
tmpl = PT::from_text("{{^1}}{{3}}{{/1}}").unwrap();
|
||||
assert_eq!(tmpl.renders_with_fields(&fields), false);
|
||||
assert_eq!(tmpl.renders_with_fields_for_reqs(&fields), true);
|
||||
assert!(!tmpl.renders_with_fields(&fields));
|
||||
assert!(tmpl.renders_with_fields_for_reqs(&fields));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -359,7 +359,7 @@ pub(crate) fn to_custom_re<'a>(txt: &'a str, wildcard: &str) -> Cow<'a, str> {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"\\?.").unwrap();
|
||||
}
|
||||
RE.replace_all(&txt, |caps: &Captures| {
|
||||
RE.replace_all(txt, |caps: &Captures| {
|
||||
let s = &caps[0];
|
||||
match s {
|
||||
r"\\" | r"\*" => s.to_string(),
|
||||
@ -377,7 +377,7 @@ pub(crate) fn to_sql(txt: &str) -> Cow<str> {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"\\[\\*]|[*%]").unwrap();
|
||||
}
|
||||
RE.replace_all(&txt, |caps: &Captures| {
|
||||
RE.replace_all(txt, |caps: &Captures| {
|
||||
let s = &caps[0];
|
||||
match s {
|
||||
r"\\" => r"\\",
|
||||
@ -394,7 +394,7 @@ pub(crate) fn to_text(txt: &str) -> Cow<str> {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"\\(.)").unwrap();
|
||||
}
|
||||
RE.replace_all(&txt, "$1")
|
||||
RE.replace_all(txt, "$1")
|
||||
}
|
||||
|
||||
/// Escape Anki wildcards and the backslash for escaping them: \*_
|
||||
@ -402,7 +402,7 @@ pub(crate) fn escape_anki_wildcards(txt: &str) -> String {
|
||||
lazy_static! {
|
||||
static ref RE: Regex = Regex::new(r"[\\*_]").unwrap();
|
||||
}
|
||||
RE.replace_all(&txt, r"\$0").into()
|
||||
RE.replace_all(txt, r"\$0").into()
|
||||
}
|
||||
|
||||
/// Escape Anki wildcards unless it's _*
|
||||
|
@ -498,8 +498,8 @@ mod test {
|
||||
|
||||
// merge subsequent changes into our restore point
|
||||
let op = col.merge_undoable_ops(restore_point)?;
|
||||
assert_eq!(op.changes.card, true);
|
||||
assert_eq!(op.changes.config, true);
|
||||
assert!(op.changes.card);
|
||||
assert!(op.changes.config);
|
||||
|
||||
// the last undo action should be at the end of the step list,
|
||||
// before the modtime bump
|
||||
@ -535,7 +535,7 @@ mod test {
|
||||
col.storage.get_collection_timestamps()?.collection_change.0,
|
||||
0
|
||||
);
|
||||
assert_eq!(out.changes.had_change(), false);
|
||||
assert!(!out.changes.had_change());
|
||||
|
||||
// if there is an undoable step, mtime should change
|
||||
let out = col.set_config_bool(BoolKey::AddingDefaultsToCurrentDeck, false, true)?;
|
||||
@ -543,7 +543,7 @@ mod test {
|
||||
col.storage.get_collection_timestamps()?.collection_change.0,
|
||||
0
|
||||
);
|
||||
assert_eq!(out.changes.had_change(), true);
|
||||
assert!(out.changes.had_change());
|
||||
|
||||
// when skipping undo, mtime should still only be bumped on a change
|
||||
col.storage.db.execute_batch("update col set mod = 0")?;
|
||||
@ -552,7 +552,7 @@ mod test {
|
||||
col.storage.get_collection_timestamps()?.collection_change.0,
|
||||
0
|
||||
);
|
||||
assert_eq!(out.changes.had_change(), false);
|
||||
assert!(!out.changes.had_change());
|
||||
|
||||
// op output won't reflect changes were made
|
||||
let out = col.set_config_bool(BoolKey::AddingDefaultsToCurrentDeck, true, false)?;
|
||||
@ -560,7 +560,7 @@ mod test {
|
||||
col.storage.get_collection_timestamps()?.collection_change.0,
|
||||
0
|
||||
);
|
||||
assert_eq!(out.changes.had_change(), false);
|
||||
assert!(!out.changes.had_change());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user