From d8d2c37ec0d22e061f9637ae2b4b26357dd0c861 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Mon, 10 Jun 2024 00:55:10 -0600 Subject: [PATCH] Fix test on windows --- src/hyperlink.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/hyperlink.rs b/src/hyperlink.rs index 4e6ee8f..c8c5bad 100644 --- a/src/hyperlink.rs +++ b/src/hyperlink.rs @@ -65,16 +65,23 @@ const fn host() -> &'static str { mod test { use super::*; + // This allows us to test the encoding without having to worry about the host, or absolute path + struct Encoded(&'static str); + + impl fmt::Display for Encoded { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + for byte in self.0.bytes() { + encode(f, byte)?; + } + Ok(()) + } + } + #[test] fn test_unicode_encoding() { - let path: PathBuf = "/$*\x1bßé/∫😃".into(); - let url = PathUrl::new(&path).unwrap(); assert_eq!( - url.to_string(), - format!( - "file://{}/%24%2A%1B%C3%9F%C3%A9/%E2%88%AB%F0%9F%98%83", - host() - ), + Encoded("$*\x1bßé/∫😃").to_string(), + "%24%2A%1B%C3%9F%C3%A9/%E2%88%AB%F0%9F%98%83", ); } }