11//! Student file policy for the C# plugin.
22
3- use std:: path:: Path ;
3+ use std:: { ffi :: OsStr , path:: Path } ;
44use tmc_langs_framework:: { StudentFilePolicy , TmcProjectYml } ;
55
66pub struct CSharpStudentFilePolicy {
77 project_config : TmcProjectYml ,
88}
99
10- impl CSharpStudentFilePolicy {
11- /// Goes up directories until a bin or obj directory is found, either indicating that the path is in a binary directory.
12- fn is_child_of_binary_dir ( path : & Path ) -> bool {
13- // checks each parent directory for bin or obj
14- for ancestor in path. ancestors ( ) . skip ( 1 ) {
15- if let Some ( file_name) = ancestor. file_name ( ) {
16- if file_name == "bin" || file_name == "obj" {
17- return true ;
18- }
19- }
20- }
21- false
22- }
23- }
24-
2510impl StudentFilePolicy for CSharpStudentFilePolicy {
2611 fn new_with_project_config ( project_config : TmcProjectYml ) -> Self
2712 where
@@ -34,14 +19,9 @@ impl StudentFilePolicy for CSharpStudentFilePolicy {
3419 & self . project_config
3520 }
3621
37- // false for .csproj files and files in bin or obj directories
38- // true for files in src except for .csproj files
22+ // .cs files in src
3923 fn is_non_extra_student_file ( & self , path : & Path ) -> bool {
40- path. starts_with ( "src" )
41- // exclude files in bin
42- && !Self :: is_child_of_binary_dir ( path)
43- // exclude .csproj files
44- && !path. extension ( ) . map ( |ext| ext == "csproj" ) . unwrap_or_default ( )
24+ path. starts_with ( "src" ) && path. extension ( ) == Some ( OsStr :: new ( "cs" ) )
4525 }
4626}
4727
@@ -53,14 +33,14 @@ mod test {
5333 fn file_in_binary_dir_is_not_student_file ( ) {
5434 let policy = CSharpStudentFilePolicy :: new ( Path :: new ( "." ) ) . unwrap ( ) ;
5535 assert ! ( !policy. is_student_file( Path :: new( "src/bin/any/file" ) ) ) ;
56- assert ! ( !policy. is_student_file( Path :: new( "obj/any/src/file" ) ) ) ;
36+ assert ! ( !policy. is_student_file( Path :: new( "obj/any/src/file.cs " ) ) ) ;
5737 }
5838
5939 #[ test]
60- fn file_in_src_is_student_file ( ) {
40+ fn cs_file_in_src_is_student_file ( ) {
6141 let policy = CSharpStudentFilePolicy :: new ( Path :: new ( "." ) ) . unwrap ( ) ;
62- assert ! ( policy. is_student_file( Path :: new( "src/file" ) ) ) ;
63- assert ! ( policy. is_student_file( Path :: new( "src/any/file" ) ) ) ;
42+ assert ! ( policy. is_student_file( Path :: new( "src/file.cs " ) ) ) ;
43+ assert ! ( policy. is_student_file( Path :: new( "src/any/file.cs " ) ) ) ;
6444 }
6545
6646 #[ test]
0 commit comments