66
77import pygit2
88from pygit2 import Blob , Filter , FilterSource , Repository
9- from pygit2 .enums import BlobFilter
9+ from pygit2 .enums import BlobFilter , FilterMode
1010from pygit2 .errors import Passthrough
1111
1212
@@ -155,6 +155,20 @@ def test_filterlist_crlf(testrepo: Repository) -> None:
155155 1234 in fl
156156
157157
158+ def test_filterlist_crlf_clean (testrepo : Repository ) -> None :
159+ testrepo .config ['core.autocrlf' ] = True
160+ fl = testrepo .load_filter_list ('whatever.txt' , mode = FilterMode .CLEAN )
161+ filtered = fl .apply_to_buffer (b'hello\r \n world\r \n ' )
162+ assert filtered == b'hello\n world\n '
163+
164+
165+ def test_filterlist_crlf_smudge (testrepo : Repository ) -> None :
166+ testrepo .config ['core.autocrlf' ] = True
167+ fl = testrepo .load_filter_list ('whatever.txt' , mode = FilterMode .SMUDGE )
168+ filtered = fl .apply_to_buffer (b'hello\n world\n ' )
169+ assert filtered == b'hello\r \n world\r \n '
170+
171+
158172def test_filterlist_rot13 (testrepo : Repository , rot13_filter : Filter ) -> None :
159173 fl = testrepo .load_filter_list ('hello.txt' )
160174 assert fl is not None
@@ -177,3 +191,29 @@ def test_filterlist_rot13_dangerous_unregister(testrepo: Repository) -> None:
177191 # to unregister the filter.
178192 del fl
179193 pygit2 .filter_unregister ('rot13' )
194+
195+
196+ def test_filterlist_rot13_apply_to_buffer (
197+ testrepo : Repository , rot13_filter : Filter
198+ ) -> None :
199+ fl = testrepo .load_filter_list ('whatever.txt' )
200+ filtered = fl .apply_to_buffer (b'bye world\n ' )
201+ assert filtered == b'olr jbeyq\n '
202+
203+
204+ def test_filterlist_rot13_apply_to_file (
205+ testrepo : Repository , rot13_filter : Filter
206+ ) -> None :
207+ fl = testrepo .load_filter_list ('bye.txt' )
208+ filtered = fl .apply_to_file (testrepo , 'bye.txt' )
209+ assert filtered == b'olr jbeyq\n '
210+
211+
212+ def test_filterlist_rot13_apply_to_blob (
213+ testrepo : Repository , rot13_filter : Filter
214+ ) -> None :
215+ fl = testrepo .load_filter_list ('whatever.txt' )
216+ blob_oid = testrepo .create_blob (b'bye world\n ' )
217+ blob = testrepo [blob_oid ]
218+ filtered = fl .apply_to_blob (blob )
219+ assert filtered == b'olr jbeyq\n '
0 commit comments