Browse Source

Engine option equality done...finally

ag-yep
Taylor Bockman 7 years ago
parent
commit
54cab71bd7
  1. 7
      src/lib.rs
  2. 6
      src/options.rs
  3. 20
      tests/lib.rs

7
src/lib.rs

@ -53,12 +53,7 @@ where
{ {
pub fn new(name: &'a str, author: &'a str, pub fn new(name: &'a str, author: &'a str,
reader: R, writer: W, engine_options: Vec<options::EngineOption>) -> Engine<'a, R, W> { reader: R, writer: W, engine_options: Vec<options::EngineOption>) -> Engine<'a, R, W> {
Engine { Engine { name, author, reader, writer, engine_options,
name: name,
author: author,
reader: reader,
writer: writer,
engine_options: engine_options,
} }
} }

6
src/options.rs

@ -46,7 +46,7 @@ pub mod constants {
} }
/// The `EngineOptionType` type used to indicate what type of option the GUI should display /// The `EngineOptionType` type used to indicate what type of option the GUI should display
#[derive(Clone, Debug, PartialEq)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum EngineOptionType { pub enum EngineOptionType {
Check, Check,
Spin, Spin,
@ -64,7 +64,7 @@ pub enum EngineOptionData {
Text(String), Text(String),
} }
#[derive(Debug, Hash, PartialEq)] #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
/// The `EngineOptionDataType` type used to indicate the type of the `EngineOption` setting /// The `EngineOptionDataType` type used to indicate the type of the `EngineOption` setting
pub enum EngineOptionDataType { pub enum EngineOptionDataType {
DefaultVal, // `Default` is reserved so `DefaultVal` is used DefaultVal, // `Default` is reserved so `DefaultVal` is used
@ -86,7 +86,7 @@ impl EngineOption {
/// Constructs a new EngineOption of type T /// Constructs a new EngineOption of type T
pub fn new(name: &'static str, option_type: EngineOptionType, pub fn new(name: &'static str, option_type: EngineOptionType,
option_data: HashMap<EngineOptionDataType, EngineOptionData>) -> EngineOption { option_data: HashMap<EngineOptionDataType, EngineOptionData>) -> EngineOption {
EngineOption { name, option_type, option_data } EngineOption { name, option_type, option_data, }
} }
pub fn option_string(&self) -> String { pub fn option_string(&self) -> String {

20
tests/lib.rs

@ -50,14 +50,28 @@ fn send_readyok() {
fn engine_option_equality() { fn engine_option_equality() {
let name = constants::HASH; let name = constants::HASH;
let option_type = EngineOptionType::Check; let option_type = EngineOptionType::Check;
let option_data = let option_data1 =
[(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)), [(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
(EngineOptionDataType::Min, EngineOptionData::Int(1)), (EngineOptionDataType::Min, EngineOptionData::Int(1)),
(EngineOptionDataType::Max, EngineOptionData::Int(128)) (EngineOptionDataType::Max, EngineOptionData::Int(128))
].iter().cloned().collect(); ].iter().cloned().collect();
let option_data2 =
[(EngineOptionDataType::DefaultVal, EngineOptionData::Int(1)),
(EngineOptionDataType::Min, EngineOptionData::Int(1)),
(EngineOptionDataType::Max, EngineOptionData::Int(128))
].iter().cloned().collect();
let o1 = EngineOption {
name: name,
option_type: option_type,
option_data: option_data1,
};
let o1 = EngineOption { name, option_type, option_data }; let o2 = EngineOption {
let o2 = EngineOption { name, option_type, option_data }; name: name,
option_type: option_type,
option_data: option_data2,
};
assert_eq!(o1, o2); assert_eq!(o1, o2);
} }

Loading…
Cancel
Save