Skip to content

Commit

Permalink
Implement default for slot type
Browse files Browse the repository at this point in the history
  • Loading branch information
andriygm committed Aug 9, 2024
1 parent 79c7c1f commit a7efefb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ mod tests {
use super::*;

#[test]
fn get_name_explicit() {
fn project_get_name_explicit() {
let project = Project {
config: Config {
name: Some("some_name".to_string()),
Expand All @@ -164,7 +164,7 @@ mod tests {
}

#[test]
fn get_name_inferred() {
fn project_get_name_inferred() {
let project = Project {
config: Config::default(),
dir: PathBuf::from("tests/data/templated"),
Expand All @@ -174,7 +174,7 @@ mod tests {
}

#[test]
fn get_name_cwd() {
fn project_get_name_cwd() {
let cwd = env::current_dir().unwrap();

env::set_current_dir(PathBuf::from("tests/data/templated")).unwrap();
Expand Down
44 changes: 20 additions & 24 deletions src/slot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ pub enum SlotType {
Boolean,
}

impl Default for Slot {
fn default() -> Self {
Self {
key: "".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
}
}
}

impl Display for Slot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
Expand Down Expand Up @@ -132,16 +144,12 @@ mod tests {
Slot {
key: "key".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
..Default::default()
},
Slot {
key: "key2".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
..Default::default()
},
];

Expand All @@ -159,16 +167,12 @@ mod tests {
Slot {
key: "key".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
..Default::default()
},
Slot {
key: "key2".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
..Default::default()
},
];

Expand All @@ -185,9 +189,7 @@ mod tests {
let slots = vec![Slot {
key: "key".to_string(),
r#type: SlotType::String,
needs: None,
name: None,
description: None,
..Default::default()
}];

let data = HashMap::from([("key", "value"), ("key2", "value2")])
Expand All @@ -204,16 +206,12 @@ mod tests {
Slot {
key: "key".to_string(),
r#type: SlotType::Number,
needs: None,
name: None,
description: None,
..Default::default()
},
Slot {
key: "key2".to_string(),
r#type: SlotType::Boolean,
needs: None,
name: None,
description: None,
..Default::default()
},
];

Expand All @@ -230,9 +228,7 @@ mod tests {
let slots = vec![Slot {
key: "key".to_string(),
r#type: SlotType::Number,
needs: None,
name: None,
description: None,
..Default::default()
}];

let data = HashMap::from([("key", "value")])
Expand Down

0 comments on commit a7efefb

Please sign in to comment.