@@ -271,6 +271,18 @@ mod tests {
271271
272272 use super :: * ;
273273
274+ // Helper function to create a test file path and URL that works on all platforms
275+ fn test_file_url ( filename : & str ) -> ( PathBuf , Url ) {
276+ // Use an absolute path that's valid on the platform
277+ #[ cfg( windows) ]
278+ let path = PathBuf :: from ( format ! ( "C:\\ temp\\ {filename}" ) ) ;
279+ #[ cfg( not( windows) ) ]
280+ let path = PathBuf :: from ( format ! ( "/tmp/{filename}" ) ) ;
281+
282+ let url = Url :: from_file_path ( & path) . expect ( "Failed to create file URL" ) ;
283+ ( path, url)
284+ }
285+
274286 #[ test]
275287 fn test_session_database_operations ( ) {
276288 let mut session = Session :: default ( ) ;
@@ -287,7 +299,7 @@ mod tests {
287299 #[ test]
288300 fn test_session_document_lifecycle ( ) {
289301 let mut session = Session :: default ( ) ;
290- let url = Url :: parse ( "file:/// test.py") . unwrap ( ) ;
302+ let ( path , url) = test_file_url ( " test.py") ;
291303
292304 // Open document
293305 let document = TextDocument :: new ( "print('hello')" . to_string ( ) , 1 , LanguageId :: Python ) ;
@@ -297,7 +309,6 @@ mod tests {
297309 assert ! ( session. get_document( & url) . is_some( ) ) ;
298310
299311 // Should be queryable through database
300- let path = paths:: url_to_path ( & url) . unwrap_or_else ( || PathBuf :: from ( "test.py" ) ) ;
301312 let file = session. get_or_create_file ( & path) ;
302313 let content = session. with_db ( |db| source_text ( db, file) . to_string ( ) ) ;
303314 assert_eq ! ( content, "print('hello')" ) ;
@@ -310,7 +321,7 @@ mod tests {
310321 #[ test]
311322 fn test_session_document_update ( ) {
312323 let mut session = Session :: default ( ) ;
313- let url = Url :: parse ( "file:/// test.py") . unwrap ( ) ;
324+ let ( path , url) = test_file_url ( " test.py") ;
314325
315326 // Open with initial content
316327 let document = TextDocument :: new ( "initial" . to_string ( ) , 1 , LanguageId :: Python ) ;
@@ -330,7 +341,6 @@ mod tests {
330341 assert_eq ! ( doc. version( ) , 2 ) ;
331342
332343 // Database should also see updated content
333- let path = paths:: url_to_path ( & url) . unwrap_or_else ( || PathBuf :: from ( "test.py" ) ) ;
334344 let file = session. get_or_create_file ( & path) ;
335345 let content = session. with_db ( |db| source_text ( db, file) . to_string ( ) ) ;
336346 assert_eq ! ( content, "updated" ) ;
0 commit comments