-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
265 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
#[derive(Debug, PartialEq)] | ||
pub struct InsertNode {} | ||
pub struct InsertNode { | ||
pub alias: Option<String>, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn derived_from_debug() { | ||
format!("{:?}", InsertNode {}); | ||
format!("{:?}", InsertNode { alias: None }); | ||
} | ||
|
||
#[test] | ||
fn derived_from_partial_eq() { | ||
assert_eq!(InsertNode {}, InsertNode {}); | ||
assert_eq!(InsertNode { alias: None }, InsertNode { alias: None }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,62 @@ | ||
use super::query_id::QueryId; | ||
use super::query_ids::QueryIds; | ||
use crate::commands::insert_alias::InsertAlias; | ||
use crate::commands::Commands; | ||
|
||
pub struct InsertAliasesQuery { | ||
pub ids: QueryIds, | ||
pub aliases: Vec<String>, | ||
} | ||
|
||
impl InsertAliasesQuery { | ||
pub(crate) fn commands(&self) -> Vec<Commands> { | ||
match &self.ids { | ||
QueryIds::All | QueryIds::Search(_) => panic!("Invalid query"), | ||
QueryIds::Id(id) => self.id(id), | ||
QueryIds::Ids(ids) => self.ids(ids), | ||
} | ||
} | ||
|
||
fn id(&self, id: &QueryId) -> Vec<Commands> { | ||
vec![Commands::InsertAlias(InsertAlias { | ||
id: id.clone(), | ||
alias: self.aliases[0].clone(), | ||
})] | ||
} | ||
|
||
fn ids(&self, ids: &[QueryId]) -> Vec<Commands> { | ||
let mut commands = Vec::<Commands>::new(); | ||
|
||
for (id, alias) in ids.iter().zip(self.aliases.iter()) { | ||
commands.push(Commands::InsertAlias(InsertAlias { | ||
id: id.clone(), | ||
alias: alias.clone(), | ||
})); | ||
} | ||
|
||
commands | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::test_utilities::catch_unwind_silent::catch_unwind_silent; | ||
|
||
#[test] | ||
fn invalid_query() { | ||
let result = catch_unwind_silent(|| { | ||
let query = InsertAliasesQuery { | ||
ids: QueryIds::All, | ||
aliases: vec![], | ||
}; | ||
|
||
query.commands(); | ||
}); | ||
|
||
assert_eq!( | ||
*result.unwrap_err().downcast_ref::<&str>().unwrap(), | ||
"Invalid query" | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.