Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 4622054

Browse files
committed
Fix URI test for Windows
1 parent 56bee0e commit 4622054

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/server/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ impl RawMessage {
490490
#[cfg(test)]
491491
mod test {
492492
use super::*;
493+
use url::Url;
493494

494495
fn get_default_params() -> InitializeParams {
495496
InitializeParams {
@@ -506,24 +507,35 @@ mod test {
506507
}
507508
}
508509

510+
fn make_platform_path(path: &'static str) -> PathBuf {
511+
if cfg!(windows) {
512+
PathBuf::from(format!("C:/{}", path))
513+
} else {
514+
PathBuf::from(format!("/{}", path))
515+
}
516+
}
517+
509518
#[test]
510519
fn test_use_root_uri() {
511520
let mut params = get_default_params();
512521

513-
params.root_path = Some(String::from("/path/a"));
514-
params.root_uri = Some(::url::Url::parse("file:///path/b").unwrap());
522+
let root_path = make_platform_path("path/a");
523+
let root_uri = make_platform_path("path/b");
524+
params.root_path = Some(root_path.to_str().unwrap().to_owned());
525+
params.root_uri = Some(Url::from_directory_path(&root_uri).unwrap());
515526

516-
assert_eq!(get_root_path(&params).to_str().unwrap(), "/path/b");
527+
assert_eq!(get_root_path(&params), root_uri);
517528
}
518529

519530
#[test]
520531
fn test_use_root_path() {
521532
let mut params = get_default_params();
522533

523-
params.root_path = Some(String::from("/path/a"));
534+
let root_path = make_platform_path("path/a");
535+
params.root_path = Some(root_path.to_str().unwrap().to_owned());
524536
params.root_uri = None;
525537

526-
assert_eq!(get_root_path(&params).to_str().unwrap(), "/path/a");
538+
assert_eq!(get_root_path(&params), root_path);
527539
}
528540

529541
#[test]

0 commit comments

Comments
 (0)