tmc_langs_java/
ant_policy.rs1use std::{ffi::OsStr, path::Path};
4use tmc_langs_framework::{StudentFilePolicy, TmcProjectYml};
5
6pub struct AntStudentFilePolicy {
7 project_config: TmcProjectYml,
8}
9
10impl StudentFilePolicy for AntStudentFilePolicy {
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") && path.extension() == Some(OsStr::new("java"))
24 }
25}
26
27#[cfg(test)]
28mod test {
29 use super::*;
30
31 #[test]
32 fn is_student_file() {
33 let policy = AntStudentFilePolicy::new(Path::new(".")).unwrap();
34 assert!(policy.is_student_file(Path::new("src/file.java")));
35 assert!(policy.is_student_file(Path::new("src/dir/file.java")));
36 }
37
38 #[test]
39 fn is_not_student_source_file() {
40 let policy = AntStudentFilePolicy::new(Path::new(".")).unwrap();
41 assert!(!policy.is_student_file(Path::new("src/file")));
42 assert!(!policy.is_student_file(Path::new("file")));
43 assert!(!policy.is_student_file(Path::new("dir/src/file")));
44 assert!(!policy.is_student_file(Path::new("srca/file")));
45 }
46}