mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-01 08:19:18 +00:00
WIP: add one aditional module file for exercise support
This commit is contained in:
parent
42b924aeab
commit
0219ef7cc9
@ -108,6 +108,7 @@ mod tests {
|
|||||||
ExerciseInfo {
|
ExerciseInfo {
|
||||||
name: String::from("1"),
|
name: String::from("1"),
|
||||||
dir: None,
|
dir: None,
|
||||||
|
module_file: None,
|
||||||
test: true,
|
test: true,
|
||||||
strict_clippy: true,
|
strict_clippy: true,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
@ -116,6 +117,7 @@ mod tests {
|
|||||||
ExerciseInfo {
|
ExerciseInfo {
|
||||||
name: String::from("2"),
|
name: String::from("2"),
|
||||||
dir: Some(String::from("d")),
|
dir: Some(String::from("d")),
|
||||||
|
module_file: None,
|
||||||
test: false,
|
test: false,
|
||||||
strict_clippy: false,
|
strict_clippy: false,
|
||||||
hint: String::new(),
|
hint: String::new(),
|
||||||
|
|||||||
@ -11,6 +11,9 @@ pub struct ExerciseInfo {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
/// Exercise's directory name inside the `exercises/` directory.
|
/// Exercise's directory name inside the `exercises/` directory.
|
||||||
pub dir: Option<String>,
|
pub dir: Option<String>,
|
||||||
|
/// Extra one Aditional Module file
|
||||||
|
#[serde(default)]
|
||||||
|
pub module_file: Option<String>,
|
||||||
/// Run `cargo test` on the exercise.
|
/// Run `cargo test` on the exercise.
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub test: bool,
|
pub test: bool,
|
||||||
@ -52,6 +55,33 @@ impl ExerciseInfo {
|
|||||||
|
|
||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn module_file_path(&self) -> Option<String> {
|
||||||
|
if let Some(module_path) = &self.module_file {
|
||||||
|
let mut path = if let Some(dir) = &self.dir {
|
||||||
|
// 14 = 10 + 1 + 3
|
||||||
|
// exercises/ + / + .rs
|
||||||
|
let mut path = String::with_capacity(14 + dir.len() + module_path.len());
|
||||||
|
path.push_str("exercises/");
|
||||||
|
path.push_str(dir);
|
||||||
|
path.push('/');
|
||||||
|
path
|
||||||
|
} else {
|
||||||
|
// 13 = 10 + 3
|
||||||
|
// exercises/ + .rs
|
||||||
|
let mut path = String::with_capacity(13 + module_path.len());
|
||||||
|
path.push_str("exercises/");
|
||||||
|
path
|
||||||
|
};
|
||||||
|
|
||||||
|
path.push_str(&module_path);
|
||||||
|
path.push_str(".rs");
|
||||||
|
|
||||||
|
Some(path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunnableExercise for ExerciseInfo {
|
impl RunnableExercise for ExerciseInfo {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user