add tests, lib

This commit is contained in:
2020-01-25 02:04:53 +08:00
parent fe0b952301
commit db82f58a42
3 changed files with 58 additions and 39 deletions

16
tests/test_make_url.rs Normal file
View File

@@ -0,0 +1,16 @@
use m3u8download::make_url;
#[test]
fn test_make_url() {
assert_eq!("http://example.com/a/b.ts", &make_url("", "http://example.com/a/b.ts").unwrap());
assert_eq!("https://example.com/a/b.ts", &make_url("", "https://example.com/a/b.ts").unwrap());
assert_eq!("http://example.com/a/b.ts", &make_url("HTTP://example.com/x/y.m3u8", "//example.com/a/b.ts").unwrap());
assert_eq!("http://example.com/a/b.ts", &make_url("http://example.com/x/y.m3u8", "//example.com/a/b.ts").unwrap());
assert_eq!("https://example.com/a/b.ts", &make_url("HTTPS://example.com/x/y.m3u8", "//example.com/a/b.ts").unwrap());
assert_eq!("https://example.com/a/b.ts", &make_url("https://example.com/x/y.m3u8", "//example.com/a/b.ts").unwrap());
assert_eq!("https://example.com/a/b.ts", &make_url("https://example.com/x/y.m3u8", "/a/b.ts").unwrap());
assert_eq!("https://example.com/x/b.ts", &make_url("https://example.com/x/y.m3u8", "b.ts").unwrap());
assert_eq!("https://example.com/x/b.ts", &make_url("https://example.com/x/y", "b.ts").unwrap());
assert_eq!("https://example.com/x/y/b.ts", &make_url("https://example.com/x/y/", "b.ts").unwrap());
assert_eq!("https://example.com/x/y/a/b.ts", &make_url("https://example.com/x/y/", "a/b.ts").unwrap());
}