Skip to content

Commit

Permalink
feat: add support for convert local string
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 23, 2021
1 parent 04b6cea commit 5ee4591
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/infrastructure/url_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use crate::settings::Settings;
pub fn from(text: &str) -> String {
let uri_path = match Url::parse(text) {
Ok(url) => url,
Err(e) => panic!("failed to parsed: {}", e),
Err(_e) => {
let path = Path::new(text);
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
return format!("{}.{}", file_name, "json");
}
};

let paths = uri_path
Expand Down Expand Up @@ -44,16 +48,27 @@ pub fn uri_to_path(url: &str) -> PathBuf {
#[cfg(test)]
mod test {
use crate::infrastructure::url_format::{from, uri_to_path};
use std::path::PathBuf;

#[test]
fn format_github_with_url_http() {
fn should_format_github_with_url_http() {
let string = from("https://github.com/coco-rs/coco.fixtures");
assert_eq!("coco.fixtures.json", string);
}

#[test]
fn url_to_path() {
let string = uri_to_path("https://github.com/coco-rs/coco.fixtures");
fn should_format_local_url() {
let path = PathBuf::from(".coco");
let framework_path = path.join("framework");

let string = from(&*format!("{}", framework_path.display()));
assert_eq!("framework.json", string);
}

#[test]
fn should_url_to_path() {
let url = "https://github.com/coco-rs/coco.fixtures";
let string = uri_to_path(url);
assert_eq!(
".coco/github.com/coco-rs/coco.fixtures",
string.to_str().unwrap()
Expand Down

0 comments on commit 5ee4591

Please sign in to comment.