Skip to content

Commit 3a61524

Browse files
committed
add boilerplate for tests + move template to a new file
1 parent 618531b commit 3a61524

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

cargo-aoc/src/app.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ pub fn execute_credentials(args: &Credentials) {
4141
/// Executes the "input" subcommand of the app
4242
pub fn execute_input(args: &Input) -> Result<(), Box<dyn Error>> {
4343
// Gets the token or exit if it's not referenced.
44-
let token = CredentialsManager::new().get_session_token().expect(
45-
"Error: you need to setup your AOC token using \"cargo aoc credentials {token}\"",
46-
);
44+
let token = CredentialsManager::new()
45+
.get_session_token()
46+
.expect("Error: you need to setup your AOC token using \"cargo aoc credentials {token}\"");
4747

4848
let pm = ProjectManager::new()?;
4949

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+
}

cargo-aoc/template/src/day.rs.tpl

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
use aoc_runner_derive::{aoc, aoc_generator};
2-
#[aoc_generator({DAY})]
2+
#[aoc_generator(REP)]
33
fn parse(input: &str) -> String {
44
todo!()
55
}
66

7-
#[aoc({DAY}, part1)]
7+
#[aoc(REP, part1)]
88
fn part1(input: &str) -> String {
99
todo!()
1010
}
1111

12-
#[aoc({DAY}, part2)]
12+
#[aoc(REP, part2)]
1313
fn part2(input: &str) -> String {
1414
todo!()
1515
}
1616

17-
1817
#[cfg(test)]
1918
mod tests {
2019
use super::*;
2120
2221
#[test]
2322
fn part1_example() {
24-
assert_eq!(part1(&parse("<EXAMPLE>")), "<RESULT>");
23+
let input = "";
24+
let output = "";
25+
26+
let input = parse(input);
27+
assert_eq!(part1(input), output);
2528
}
2629

2730
#[test]
2831
fn part2_example() {
29-
assert_eq!(part2(&parse("<EXAMPLE>")), "<RESULT>");
32+
let input = "";
33+
let output = "";
34+
35+
let input = parse(input);
36+
assert_eq!(part2(input), output);
3037
}
31-
}
38+
}

0 commit comments

Comments
 (0)