File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff 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 ( ) ,
Original file line number Diff line number Diff 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
5787impl RunnableExercise for ExerciseInfo {
You can’t perform that action at this time.
0 commit comments