tmc_langs_java/
maven_policy.rs1use std::{ffi::OsStr, path::Path};
4use tmc_langs_framework::{StudentFilePolicy, TmcProjectYml};
5
6pub struct MavenStudentFilePolicy {
7 project_config: TmcProjectYml,
8}
9
10impl StudentFilePolicy for MavenStudentFilePolicy {
11 fn new_with_project_config(project_config: TmcProjectYml) -> Self
12 where
13 Self: Sized,
14 {
15 Self { project_config }
16 }
17
18 fn get_project_config(&self) -> &TmcProjectYml {
19 &self.project_config
20 }
21
22 fn is_non_extra_student_file(&self, path: &Path) -> bool {
23 path.starts_with("src/main") && path.extension() == Some(OsStr::new("java"))
25 }
26}
27
28#[cfg(test)]
29mod test {
30 use super::*;
31
32 #[test]
33 fn is_student_file() {
34 let policy = MavenStudentFilePolicy::new(Path::new(".")).unwrap();
35 assert!(policy.is_student_file(Path::new("src/main/file.java")));
36 assert!(policy.is_student_file(Path::new("src/main/dir/file.java")));
37 }
38
39 #[test]
40 fn is_not_student_source_file() {
41 let policy = MavenStudentFilePolicy::new(Path::new(".")).unwrap();
42 assert!(!policy.is_student_file(Path::new("file")));
43 assert!(!policy.is_student_file(Path::new("dir/src/main/file")));
44 assert!(!policy.is_student_file(Path::new("srca/main/file")));
45 assert!(!policy.is_student_file(Path::new("src/mainc/file")));
46 }
47}