refactor: extract template to its own file (#49)
This commit is contained in:
parent
b71cbddde9
commit
a79ce7ad6d
2 changed files with 29 additions and 28 deletions
26
src/template.txt
Normal file
26
src/template.txt
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
advent_of_code::solution!(%DAY_NUMBER%);
|
||||||
|
|
||||||
|
pub fn part_one(input: &str) -> Option<u32> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn part_two(input: &str) -> Option<u32> {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,33 +6,8 @@ use std::{
|
||||||
|
|
||||||
use crate::template::Day;
|
use crate::template::Day;
|
||||||
|
|
||||||
const MODULE_TEMPLATE: &str = r#"advent_of_code::solution!(DAY_NUMBER);
|
const MODULE_TEMPLATE: &str =
|
||||||
|
include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/template.txt"));
|
||||||
pub fn part_one(input: &str) -> Option<u32> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn part_two(input: &str) -> Option<u32> {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
fn safe_create_file(path: &str) -> Result<File, std::io::Error> {
|
fn safe_create_file(path: &str) -> Result<File, std::io::Error> {
|
||||||
OpenOptions::new().write(true).create_new(true).open(path)
|
OpenOptions::new().write(true).create_new(true).open(path)
|
||||||
|
@ -57,7 +32,7 @@ pub fn handle(day: Day) {
|
||||||
|
|
||||||
match file.write_all(
|
match file.write_all(
|
||||||
MODULE_TEMPLATE
|
MODULE_TEMPLATE
|
||||||
.replace("DAY_NUMBER", &day.into_inner().to_string())
|
.replace("%DAY_NUMBER%", &day.into_inner().to_string())
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
) {
|
) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue