Skip to content

Commit f86fe44

Browse files
committed
add boilerplate for tests + move template to a new file
1 parent 1cce654 commit f86fe44

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

cargo-aoc/src/app.rs

+2-29
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use reqwest::{
77
header::{HeaderMap, COOKIE, USER_AGENT},
88
StatusCode,
99
};
10+
use std::io::Write;
1011
use std::path::Path;
1112
use std::process;
12-
use std::{io::Write};
1313
use std::{error, sync::Arc};
1414
use std::{
1515
error::Error,
@@ -136,34 +136,7 @@ fn codegen(day: u32) -> Result<(), Box<dyn Error>> {
136136
eprintln!("{filename:?} already exists. Skipping...");
137137
return Ok(());
138138
}
139-
let code = r#"use aoc_runner_derive::{aoc, aoc_generator};
140-
#[aoc_generator(REP)]
141-
fn parse(input: &str) -> String {
142-
todo!()
143-
}
144-
145-
#[aoc(REP, part1)]
146-
fn part1(input: &str) -> String {
147-
todo!()
148-
}
149-
150-
#[aoc(REP, part2)]
151-
fn part2(input: &str) -> String {
152-
todo!()
153-
}
154-
155-
156-
#[cfg(test)]
157-
mod tests {
158-
use super::*;
159-
160-
#[test]
161-
fn part1_example() {}
162-
163-
#[test]
164-
fn part2_example() {}
165-
}
166-
"#;
139+
let code = include_str!("../template/codegen.rs");
167140
let code = code.replace("REP", &format!("day{day}"));
168141
std::fs::write(filename, code)?;
169142
Ok(())

cargo-aoc/template/codegen.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use aoc_runner_derive::{aoc, aoc_generator};
2+
#[aoc_generator(REP)]
3+
fn parse(input: &str) -> String {
4+
todo!()
5+
}
6+
7+
#[aoc(REP, part1)]
8+
fn part1(input: &str) -> String {
9+
todo!()
10+
}
11+
12+
#[aoc(REP, part2)]
13+
fn part2(input: &str) -> String {
14+
todo!()
15+
}
16+
17+
#[cfg(test)]
18+
mod tests {
19+
use super::*;
20+
21+
#[test]
22+
fn part1_example() {
23+
let input = "";
24+
let output = "";
25+
26+
let input = parse(input);
27+
let assert_eq!(part1(input), output);
28+
}
29+
30+
#[test]
31+
fn part2_example() {
32+
let input = "";
33+
let output = "";
34+
35+
let input = parse(input);
36+
let assert_eq!(part2(input), output);
37+
}
38+
}

0 commit comments

Comments
 (0)