Skip to content

Commit e534f2c

Browse files
author
T.J
committed
Adding schemas
Added ftp, ftps for #5 Added parse tests for ftp/ftps as well Currently some failing tests. Relative paths. Related: #6, #7
1 parent 31088d9 commit e534f2c

File tree

3 files changed

+101
-7
lines changed

3 files changed

+101
-7
lines changed

examples/multi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fn main() -> Result<()> {
1616
"~/path/to/repo.git/",
1717
"./path/to/repo.git/",
1818
"./path/to/repo.git",
19+
"../test_repo",
20+
"..\\test_repo",
1921
"[email protected]:v3/CompanyName/ProjectName/RepoName",
2022
"https://[email protected]/CompanyName/ProjectName/_git/RepoName",
2123
];

src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ use url::Url;
1010
#[derive(Debug, PartialEq, EnumString, EnumVariantNames, Clone, Display, Copy)]
1111
#[strum(serialize_all = "kebab_case")]
1212
pub enum Scheme {
13-
/// Represents No url scheme
14-
Unspecified,
1513
/// Represents `file://` url scheme
1614
File,
15+
/// Represents `ftp://` url scheme
16+
Ftp,
17+
/// Represents `ftps://` url scheme
18+
Ftps,
19+
/// Represents `git://` url scheme
20+
Git,
21+
/// Represents `git+ssh://` url scheme
22+
#[strum(serialize = "git+ssh")]
23+
GitSsh,
1724
/// Represents `http://` url scheme
1825
Http,
1926
/// Represents `https://` url scheme
2027
Https,
2128
/// Represents `ssh://` url scheme
2229
Ssh,
23-
/// Represents `git://` url scheme
24-
Git,
25-
/// Represents `git+ssh://` url scheme
26-
#[strum(serialize = "git+ssh")]
27-
GitSsh,
30+
/// Represents No url scheme
31+
Unspecified,
2832
}
2933

3034
/// GitUrl represents an input url that is a url used by git

tests/parse.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,91 @@ fn https_user_azure_devops() {
197197

198198
assert_eq!(parsed, expected);
199199
}
200+
201+
#[test]
202+
fn ftp_user() {
203+
let test_url = "ftp://[email protected]/user/project-name.git";
204+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
205+
let expected = GitUrl {
206+
host: Some("host.tld".to_string()),
207+
name: "project-name".to_string(),
208+
owner: Some("user".to_string()),
209+
organization: None,
210+
fullname: "user/project-name".to_string(),
211+
scheme: Scheme::Ftp,
212+
user: Some("git".to_string()),
213+
token: None,
214+
port: None,
215+
path: "/user/project-name.git".to_string(),
216+
git_suffix: true,
217+
scheme_prefix: true,
218+
};
219+
220+
assert_eq!(parsed, expected);
221+
}
222+
223+
#[test]
224+
fn ftps_user() {
225+
let test_url = "ftps://[email protected]/user/project-name.git";
226+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
227+
let expected = GitUrl {
228+
host: Some("host.tld".to_string()),
229+
name: "project-name".to_string(),
230+
owner: Some("user".to_string()),
231+
organization: None,
232+
fullname: "user/project-name".to_string(),
233+
scheme: Scheme::Ftps,
234+
user: Some("git".to_string()),
235+
token: None,
236+
port: None,
237+
path: "/user/project-name.git".to_string(),
238+
git_suffix: true,
239+
scheme_prefix: true,
240+
};
241+
242+
assert_eq!(parsed, expected);
243+
}
244+
245+
#[test]
246+
fn relative_unix_path() {
247+
let test_url = "../project-name.git";
248+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
249+
let expected = GitUrl {
250+
host: Some("host.tld".to_string()),
251+
name: "project-name".to_string(),
252+
owner: Some("user".to_string()),
253+
organization: None,
254+
fullname: "../project-name.git".to_string(),
255+
scheme: Scheme::Ftps,
256+
user: Some("git".to_string()),
257+
token: None,
258+
port: None,
259+
path: "../project-name.git".to_string(),
260+
git_suffix: true,
261+
scheme_prefix: true,
262+
};
263+
264+
assert_eq!(parsed, expected);
265+
}
266+
267+
#[test]
268+
fn relative_windows_path() {
269+
let test_url = "..\\project-name.git";
270+
let parsed = GitUrl::parse(test_url).expect("URL parse failed");
271+
let expected = GitUrl {
272+
host: Some("host.tld".to_string()),
273+
name: "project-name".to_string(),
274+
owner: Some("user".to_string()),
275+
organization: None,
276+
fullname: "..\\project-name.git".to_string(),
277+
scheme: Scheme::Ftps,
278+
user: Some("git".to_string()),
279+
token: None,
280+
port: None,
281+
path: "..\\project-name.git".to_string(),
282+
git_suffix: true,
283+
scheme_prefix: true,
284+
};
285+
286+
assert_eq!(parsed, expected);
287+
}

0 commit comments

Comments
 (0)