diff --git a/src/template.txt b/src/template.txt new file mode 100644 index 0000000..11344df --- /dev/null +++ b/src/template.txt @@ -0,0 +1,26 @@ +advent_of_code::solution!(%DAY_NUMBER%); + +pub fn part_one(input: &str) -> Option { + None +} + +pub fn part_two(input: &str) -> Option { + None +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part_one() { + let result = part_one(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, None); + } + + #[test] + fn test_part_two() { + let result = part_two(&advent_of_code::template::read_file("examples", DAY)); + assert_eq!(result, None); + } +} diff --git a/src/template/commands/scaffold.rs b/src/template/commands/scaffold.rs index 138e124..8afdaed 100644 --- a/src/template/commands/scaffold.rs +++ b/src/template/commands/scaffold.rs @@ -6,33 +6,8 @@ use std::{ use crate::template::Day; -const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER); - -pub fn part_one(input: &str) -> Option { - None -} - -pub fn part_two(input: &str) -> Option { - None -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_part_one() { - let result = part_one(&advent_of_code::template::read_file("examples", DAY)); - assert_eq!(result, None); - } - - #[test] - fn test_part_two() { - let result = part_two(&advent_of_code::template::read_file("examples", DAY)); - assert_eq!(result, None); - } -} -"#; +const MODULE_TEMPLATE: &str = + include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/template.txt")); fn safe_create_file(path: &str) -> Result { OpenOptions::new().write(true).create_new(true).open(path) @@ -57,7 +32,7 @@ pub fn handle(day: Day) { match file.write_all( MODULE_TEMPLATE - .replace("DAY_NUMBER", &day.into_inner().to_string()) + .replace("%DAY_NUMBER%", &day.into_inner().to_string()) .as_bytes(), ) { Ok(()) => {