Skip to content

Commit 0219ef7

Browse files
committed
WIP: add one aditional module file for exercise support
1 parent 42b924a commit 0219ef7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/cargo_toml.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ mod tests {
108108
ExerciseInfo {
109109
name: String::from("1"),
110110
dir: None,
111+
module_file: None,
111112
test: true,
112113
strict_clippy: true,
113114
hint: String::new(),
@@ -116,6 +117,7 @@ mod tests {
116117
ExerciseInfo {
117118
name: String::from("2"),
118119
dir: Some(String::from("d")),
120+
module_file: None,
119121
test: false,
120122
strict_clippy: false,
121123
hint: String::new(),

src/info_file.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub struct ExerciseInfo {
1111
pub name: String,
1212
/// Exercise's directory name inside the `exercises/` directory.
1313
pub dir: Option<String>,
14+
/// Extra one Aditional Module file
15+
#[serde(default)]
16+
pub module_file: Option<String>,
1417
/// Run `cargo test` on the exercise.
1518
#[serde(default = "default_true")]
1619
pub test: bool,
@@ -52,6 +55,33 @@ impl ExerciseInfo {
5255

5356
path
5457
}
58+
59+
pub fn module_file_path(&self) -> Option<String> {
60+
if let Some(module_path) = &self.module_file {
61+
let mut path = if let Some(dir) = &self.dir {
62+
// 14 = 10 + 1 + 3
63+
// exercises/ + / + .rs
64+
let mut path = String::with_capacity(14 + dir.len() + module_path.len());
65+
path.push_str("exercises/");
66+
path.push_str(dir);
67+
path.push('/');
68+
path
69+
} else {
70+
// 13 = 10 + 3
71+
// exercises/ + .rs
72+
let mut path = String::with_capacity(13 + module_path.len());
73+
path.push_str("exercises/");
74+
path
75+
};
76+
77+
path.push_str(&module_path);
78+
path.push_str(".rs");
79+
80+
Some(path)
81+
} else {
82+
None
83+
}
84+
}
5585
}
5686

5787
impl RunnableExercise for ExerciseInfo {

0 commit comments

Comments
 (0)