diff --git a/src/utils.rs b/src/utils.rs index 8e738ed..a458cd8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -732,8 +732,7 @@ pub async fn error(req: Request, msg: impl ToString) -> Resulthttps://www.reddit.com/r/linux_gaming/comments/x/just_a_test/"# ) } + + #[test] + fn test_format_url() { + assert_eq!(format_url("https://a.thumbs.redditmedia.com/XYZ.jpg"), "/thumb/a/XYZ.jpg"); + assert_eq!(format_url("https://emoji.redditmedia.com/a/b"), "/emoji/a/b"); + + assert_eq!( + format_url("https://external-preview.redd.it/foo.jpg?auto=webp&s=bar"), + "/preview/external-pre/foo.jpg?auto=webp&s=bar" + ); + + assert_eq!(format_url("https://i.redd.it/foobar.jpg"), "/img/foobar.jpg"); + assert_eq!( + format_url("https://preview.redd.it/qwerty.jpg?auto=webp&s=asdf"), + "/preview/pre/qwerty.jpg?auto=webp&s=asdf" + ); + assert_eq!(format_url("https://v.redd.it/foo/DASH_360.mp4?source=fallback"), "/vid/foo/360.mp4"); + assert_eq!( + format_url("https://v.redd.it/foo/HLSPlaylist.m3u8?a=bar&v=1&f=sd"), + "/hls/foo/HLSPlaylist.m3u8?a=bar&v=1&f=sd" + ); + assert_eq!(format_url("https://www.redditstatic.com/gold/awards/icon/icon.png"), "/static/gold/awards/icon/icon.png"); + + assert_eq!(format_url(""), ""); + assert_eq!(format_url("self"), ""); + assert_eq!(format_url("default"), ""); + assert_eq!(format_url("nsfw"), ""); + assert_eq!(format_url("spoiler"), ""); + } }