@@ -166,54 +166,56 @@ mod tests {
166166 use crate :: document:: TextDocument ;
167167 use crate :: language:: LanguageId ;
168168
169+ // Helper to create platform-appropriate test paths
170+ fn test_file_path ( name : & str ) -> PathBuf {
171+ #[ cfg( windows) ]
172+ return PathBuf :: from ( format ! ( "C:\\ temp\\ {name}" ) ) ;
173+ #[ cfg( not( windows) ) ]
174+ return PathBuf :: from ( format ! ( "/tmp/{name}" ) ) ;
175+ }
176+
169177 #[ test]
170178 fn test_reads_from_buffer_when_present ( ) {
171179 let disk = Arc :: new ( InMemoryFileSystem :: new ( ) ) ;
172180 let buffers = Buffers :: new ( ) ;
173181 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , disk) ;
174182
175183 // Add file to buffer
176- let url = Url :: from_file_path ( "/test.py" ) . unwrap ( ) ;
184+ let path = test_file_path ( "test.py" ) ;
185+ let url = Url :: from_file_path ( & path) . unwrap ( ) ;
177186 let doc = TextDocument :: new ( "buffer content" . to_string ( ) , 1 , LanguageId :: Python ) ;
178187 buffers. open ( url, doc) ;
179188
180- assert_eq ! (
181- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
182- "buffer content"
183- ) ;
189+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "buffer content" ) ;
184190 }
185191
186192 #[ test]
187193 fn test_reads_from_disk_when_no_buffer ( ) {
188194 let mut disk_fs = InMemoryFileSystem :: new ( ) ;
189- disk_fs. add_file ( "/test.py" . into ( ) , "disk content" . to_string ( ) ) ;
195+ let path = test_file_path ( "test.py" ) ;
196+ disk_fs. add_file ( path. clone ( ) , "disk content" . to_string ( ) ) ;
190197
191198 let buffers = Buffers :: new ( ) ;
192199 let fs = WorkspaceFileSystem :: new ( buffers, Arc :: new ( disk_fs) ) ;
193200
194- assert_eq ! (
195- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
196- "disk content"
197- ) ;
201+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "disk content" ) ;
198202 }
199203
200204 #[ test]
201205 fn test_buffer_overrides_disk ( ) {
202206 let mut disk_fs = InMemoryFileSystem :: new ( ) ;
203- disk_fs. add_file ( "/test.py" . into ( ) , "disk content" . to_string ( ) ) ;
207+ let path = test_file_path ( "test.py" ) ;
208+ disk_fs. add_file ( path. clone ( ) , "disk content" . to_string ( ) ) ;
204209
205210 let buffers = Buffers :: new ( ) ;
206211 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , Arc :: new ( disk_fs) ) ;
207212
208213 // Add buffer with different content
209- let url = Url :: from_file_path ( "/test.py" ) . unwrap ( ) ;
214+ let url = Url :: from_file_path ( & path ) . unwrap ( ) ;
210215 let doc = TextDocument :: new ( "buffer content" . to_string ( ) , 1 , LanguageId :: Python ) ;
211216 buffers. open ( url, doc) ;
212217
213- assert_eq ! (
214- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
215- "buffer content"
216- ) ;
218+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "buffer content" ) ;
217219 }
218220
219221 #[ test]
@@ -222,39 +224,42 @@ mod tests {
222224 let buffers = Buffers :: new ( ) ;
223225 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , disk) ;
224226
225- // Add file only to buffer
226- let url = Url :: from_file_path ( "/buffer_only.py" ) . unwrap ( ) ;
227+ // Add file to buffer only
228+ let path = test_file_path ( "buffer_only.py" ) ;
229+ let url = Url :: from_file_path ( & path) . unwrap ( ) ;
227230 let doc = TextDocument :: new ( "content" . to_string ( ) , 1 , LanguageId :: Python ) ;
228231 buffers. open ( url, doc) ;
229232
230- assert ! ( fs. exists( Path :: new ( "/buffer_only.py" ) ) ) ;
233+ assert ! ( fs. exists( & path ) ) ;
231234 }
232235
233236 #[ test]
234237 fn test_exists_for_disk_only_file ( ) {
235238 let mut disk_fs = InMemoryFileSystem :: new ( ) ;
236- disk_fs. add_file ( "/disk_only.py" . into ( ) , "content" . to_string ( ) ) ;
239+ let path = test_file_path ( "disk_only.py" ) ;
240+ disk_fs. add_file ( path. clone ( ) , "content" . to_string ( ) ) ;
237241
238242 let buffers = Buffers :: new ( ) ;
239243 let fs = WorkspaceFileSystem :: new ( buffers, Arc :: new ( disk_fs) ) ;
240244
241- assert ! ( fs. exists( Path :: new ( "/disk_only.py" ) ) ) ;
245+ assert ! ( fs. exists( & path ) ) ;
242246 }
243247
244248 #[ test]
245249 fn test_exists_for_both_buffer_and_disk ( ) {
246250 let mut disk_fs = InMemoryFileSystem :: new ( ) ;
247- disk_fs. add_file ( "/both.py" . into ( ) , "disk" . to_string ( ) ) ;
251+ let path = test_file_path ( "both.py" ) ;
252+ disk_fs. add_file ( path. clone ( ) , "disk" . to_string ( ) ) ;
248253
249254 let buffers = Buffers :: new ( ) ;
250255 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , Arc :: new ( disk_fs) ) ;
251256
252257 // Also add to buffer
253- let url = Url :: from_file_path ( "/both.py" ) . unwrap ( ) ;
258+ let url = Url :: from_file_path ( & path ) . unwrap ( ) ;
254259 let doc = TextDocument :: new ( "buffer" . to_string ( ) , 1 , LanguageId :: Python ) ;
255260 buffers. open ( url, doc) ;
256261
257- assert ! ( fs. exists( Path :: new ( "/both.py" ) ) ) ;
262+ assert ! ( fs. exists( & path ) ) ;
258263 }
259264
260265 #[ test]
@@ -263,7 +268,8 @@ mod tests {
263268 let buffers = Buffers :: new ( ) ;
264269 let fs = WorkspaceFileSystem :: new ( buffers, disk) ;
265270
266- assert ! ( !fs. exists( Path :: new( "/nowhere.py" ) ) ) ;
271+ let path = test_file_path ( "nowhere.py" ) ;
272+ assert ! ( !fs. exists( & path) ) ;
267273 }
268274
269275 #[ test]
@@ -272,7 +278,8 @@ mod tests {
272278 let buffers = Buffers :: new ( ) ;
273279 let fs = WorkspaceFileSystem :: new ( buffers, disk) ;
274280
275- let result = fs. read_to_string ( Path :: new ( "/missing.py" ) ) ;
281+ let path = test_file_path ( "missing.py" ) ;
282+ let result = fs. read_to_string ( & path) ;
276283 assert ! ( result. is_err( ) ) ;
277284 assert_eq ! ( result. unwrap_err( ) . kind( ) , io:: ErrorKind :: NotFound ) ;
278285 }
@@ -283,49 +290,39 @@ mod tests {
283290 let buffers = Buffers :: new ( ) ;
284291 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , disk) ;
285292
286- let url = Url :: from_file_path ( "/test.py" ) . unwrap ( ) ;
293+ let path = test_file_path ( "test.py" ) ;
294+ let url = Url :: from_file_path ( & path) . unwrap ( ) ;
287295
288296 // Initial buffer content
289297 let doc1 = TextDocument :: new ( "version 1" . to_string ( ) , 1 , LanguageId :: Python ) ;
290298 buffers. open ( url. clone ( ) , doc1) ;
291- assert_eq ! (
292- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
293- "version 1"
294- ) ;
299+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "version 1" ) ;
295300
296301 // Update buffer content
297302 let doc2 = TextDocument :: new ( "version 2" . to_string ( ) , 2 , LanguageId :: Python ) ;
298303 buffers. update ( url, doc2) ;
299- assert_eq ! (
300- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
301- "version 2"
302- ) ;
304+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "version 2" ) ;
303305 }
304306
305307 #[ test]
306308 fn test_handles_buffer_removal ( ) {
307309 let mut disk_fs = InMemoryFileSystem :: new ( ) ;
308- disk_fs. add_file ( "/test.py" . into ( ) , "disk content" . to_string ( ) ) ;
310+ let path = test_file_path ( "test.py" ) ;
311+ disk_fs. add_file ( path. clone ( ) , "disk content" . to_string ( ) ) ;
309312
310313 let buffers = Buffers :: new ( ) ;
311314 let fs = WorkspaceFileSystem :: new ( buffers. clone ( ) , Arc :: new ( disk_fs) ) ;
312315
313- let url = Url :: from_file_path ( "/test.py" ) . unwrap ( ) ;
316+ let url = Url :: from_file_path ( & path ) . unwrap ( ) ;
314317
315318 // Add buffer
316319 let doc = TextDocument :: new ( "buffer content" . to_string ( ) , 1 , LanguageId :: Python ) ;
317320 buffers. open ( url. clone ( ) , doc) ;
318- assert_eq ! (
319- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
320- "buffer content"
321- ) ;
321+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "buffer content" ) ;
322322
323323 // Remove buffer
324324 let _ = buffers. close ( & url) ;
325- assert_eq ! (
326- fs. read_to_string( Path :: new( "/test.py" ) ) . unwrap( ) ,
327- "disk content"
328- ) ;
325+ assert_eq ! ( fs. read_to_string( & path) . unwrap( ) , "disk content" ) ;
329326 }
330327 }
331328}
0 commit comments