@@ -62,13 +62,102 @@ def test_collect_files_recursive_directory(self):
6262 assert file2 in files
6363
6464 def test_is_supported (self ):
65- unsupported_extensions = [". exe" , ". bin" , ". jpg" , ". png" ]
65+ unsupported_extensions = ["exe" , "bin" , "jpg" , "png" ]
6666
6767 for ext in FileReader .extensions :
68- assert FileReader .is_supported (Path (f"test{ ext } " ))
68+ assert FileReader .is_supported (Path (f"test. { ext } " ))
6969
7070 for ext in unsupported_extensions :
71- assert not FileReader .is_supported (Path (f"test{ ext } " ))
71+ assert not FileReader .is_supported (Path (f"test.{ ext } " ))
72+
73+ def test_is_supported_with_only_extensions (self ):
74+ """Test is_supported with only_extensions parameter"""
75+ # Test with only_extensions - should only allow specified extensions
76+ assert FileReader .is_supported (Path ("test.py" ), only_extensions = ["py" , "js" ])
77+ assert FileReader .is_supported (Path ("test.js" ), only_extensions = ["py" , "js" ])
78+ assert not FileReader .is_supported (
79+ Path ("test.txt" ), only_extensions = ["py" , "js" ]
80+ )
81+ assert not FileReader .is_supported (
82+ Path ("test.md" ), only_extensions = ["py" , "js" ]
83+ )
84+
85+ # Test with dots in extensions (should be normalized)
86+ assert FileReader .is_supported (Path ("test.py" ), only_extensions = [".py" , ".js" ])
87+ assert FileReader .is_supported (Path ("test.js" ), only_extensions = [".py" , ".js" ])
88+
89+ # Test case insensitive
90+ assert FileReader .is_supported (Path ("test.py" ), only_extensions = ["PY" , "JS" ])
91+ assert FileReader .is_supported (Path ("test.JS" ), only_extensions = ["py" , "js" ])
92+
93+ def test_is_supported_with_exclude_extensions (self ):
94+ """Test is_supported with exclude_extensions parameter"""
95+ # Test basic exclusion - py files should be excluded
96+ assert not FileReader .is_supported (Path ("test.py" ), exclude_extensions = ["py" ])
97+ assert FileReader .is_supported (Path ("test.js" ), exclude_extensions = ["py" ])
98+ assert FileReader .is_supported (Path ("test.txt" ), exclude_extensions = ["py" ])
99+
100+ # Test with dots in extensions (should be normalized)
101+ assert not FileReader .is_supported (Path ("test.py" ), exclude_extensions = [".py" ])
102+ assert FileReader .is_supported (Path ("test.js" ), exclude_extensions = [".py" ])
103+
104+ # Test case insensitive
105+ assert not FileReader .is_supported (Path ("test.py" ), exclude_extensions = ["PY" ])
106+ assert not FileReader .is_supported (Path ("test.PY" ), exclude_extensions = ["py" ])
107+
108+ # Test multiple exclusions
109+ assert not FileReader .is_supported (
110+ Path ("test.py" ), exclude_extensions = ["py" , "js" ]
111+ )
112+ assert not FileReader .is_supported (
113+ Path ("test.js" ), exclude_extensions = ["py" , "js" ]
114+ )
115+ assert FileReader .is_supported (
116+ Path ("test.txt" ), exclude_extensions = ["py" , "js" ]
117+ )
118+
119+ def test_is_supported_with_only_and_exclude_extensions (self ):
120+ """Test is_supported with both only_extensions and exclude_extensions"""
121+ # Include py and js, but exclude py - should only allow js
122+ assert not FileReader .is_supported (
123+ Path ("test.py" ), only_extensions = ["py" , "js" ], exclude_extensions = ["py" ]
124+ )
125+ assert FileReader .is_supported (
126+ Path ("test.js" ), only_extensions = ["py" , "js" ], exclude_extensions = ["py" ]
127+ )
128+ assert not FileReader .is_supported (
129+ Path ("test.txt" ), only_extensions = ["py" , "js" ], exclude_extensions = ["py" ]
130+ )
131+
132+ # Include py, txt, md, but exclude md - should only allow py and txt
133+ assert FileReader .is_supported (
134+ Path ("test.py" ),
135+ only_extensions = ["py" , "txt" , "md" ],
136+ exclude_extensions = ["md" ],
137+ )
138+ assert FileReader .is_supported (
139+ Path ("test.txt" ),
140+ only_extensions = ["py" , "txt" , "md" ],
141+ exclude_extensions = ["md" ],
142+ )
143+ assert not FileReader .is_supported (
144+ Path ("test.md" ),
145+ only_extensions = ["py" , "txt" , "md" ],
146+ exclude_extensions = ["md" ],
147+ )
148+ assert not FileReader .is_supported (
149+ Path ("test.js" ),
150+ only_extensions = ["py" , "txt" , "md" ],
151+ exclude_extensions = ["md" ],
152+ )
153+
154+ def test_is_supported_with_unsupported_extensions_in_only (self ):
155+ """Test that only_extensions can't add unsupported extensions"""
156+ # .exe is not in FileReader.extensions, so should not be supported even if in only_extensions
157+ assert not FileReader .is_supported (
158+ Path ("test.exe" ), only_extensions = ["exe" , "py" ]
159+ )
160+ assert FileReader .is_supported (Path ("test.py" ), only_extensions = ["exe" , "py" ])
72161
73162 def test_parse_html_into_markdown (self ):
74163 with tempfile .NamedTemporaryFile (suffix = ".html" , delete = False ) as f :
0 commit comments