@@ -44,3 +44,70 @@ pub fn source(upstream: &Url) -> Option<Source> {
4444
4545 None
4646}
47+
48+ #[ cfg( test) ]
49+ mod tests {
50+ use super :: * ;
51+ use url:: Url ;
52+
53+ #[ test]
54+ fn test_automatic_regex ( ) {
55+ let url_str = "https://github.com/GNOME/pango/archive/refs/tags/1.57.0.tar.gz" ;
56+ let url = Url :: parse ( url_str) . unwrap ( ) ;
57+
58+ let source = source ( & url) ;
59+ assert ! ( source. is_some( ) ) ;
60+
61+ let source = source. unwrap ( ) ;
62+ assert_eq ! ( source. name, "pango" ) ;
63+ assert_eq ! ( source. version, "1.57.0" ) ;
64+ assert_eq ! ( source. homepage, "https://github.com/GNOME/pango" ) ;
65+ assert_eq ! ( source. uri, url_str) ;
66+ }
67+
68+ #[ test]
69+ fn test_manual_regex ( ) {
70+ let url_str = "https://github.com/streamlink/streamlink/releases/download/8.2.0/streamlink-8.2.0.tar.gz" ;
71+ let url = Url :: parse ( url_str) . unwrap ( ) ;
72+
73+ let source = source ( & url) ;
74+ assert ! ( source. is_some( ) ) ;
75+
76+ let source = source. unwrap ( ) ;
77+ assert_eq ! ( source. name, "streamlink" ) ;
78+ assert_eq ! ( source. version, "8.2.0" ) ;
79+ assert_eq ! ( source. homepage, "https://github.com/streamlink/streamlink" ) ;
80+ assert_eq ! ( source. uri, url_str) ;
81+ }
82+
83+ #[ test]
84+ fn test_automatic_regex_with_v_prefix ( ) {
85+ let url_str = "https://github.com/chatty/chatty/archive/refs/tags/v0.28.tar.gz" ;
86+ let url = Url :: parse ( url_str) . unwrap ( ) ;
87+
88+ let source = source ( & url) ;
89+ assert ! ( source. is_some( ) ) ;
90+
91+ let source = source. unwrap ( ) ;
92+ assert_eq ! ( source. name, "chatty" ) ;
93+ assert_eq ! ( source. version, "0.28" ) ;
94+ assert_eq ! ( source. homepage, "https://github.com/chatty/chatty" ) ;
95+ assert_eq ! ( source. uri, url_str) ;
96+ }
97+
98+ #[ test]
99+ fn test_manual_regex_string_version ( ) {
100+ let url_str = "https://github.com/unicode-org/icu/releases/download/release-76-1/icu4c-76_1-src.tgz" ;
101+ let url = Url :: parse ( url_str) . unwrap ( ) ;
102+
103+ let source = source ( & url) ;
104+ assert ! ( source. is_some( ) ) ;
105+
106+ let source = source. unwrap ( ) ;
107+ assert_eq ! ( source. name, "icu" ) ;
108+ // TODO: we do not handle string version prefixes
109+ assert_eq ! ( source. version, "release-76-1" ) ;
110+ assert_eq ! ( source. homepage, "https://github.com/unicode-org/icu" ) ;
111+ assert_eq ! ( source. uri, url_str) ;
112+ }
113+ }
0 commit comments