123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // use chrono::NaiveDate;
-
- // #[derive(Debug)]
- // pub struct Post {
- // pub title: String,
- // pub body: String,
- // pub slug: String,
- // pub date: NaiveDate,
- // }
-
- // impl Post {
- // fn date(&self) -> String {
- // self.date.format("%Y-%m-%d").to_string()
- // }
-
- // fn render(&self, template: &str) -> String {
- // template
- // .replace("{{ title }}", &self.title)
- // .replace("{{ slug }}", &self.slug)
- // .replace("{{ body }}", &self.body)
- // .replace("{{ date }}", &self.date())
- // }
- // }
-
- // #[cfg(test)]
- // mod tests {
- // #[allow(unused_imports)]
- // use super::*;
- // #[allow(unused_imports)]
- // #[allow(unused_imports)]
- // use std::{env, fs, path};
- // #[allow(unused_imports)]
- // use uuid::Uuid;
-
- // #[test]
- // fn test_read_posts_dir() {
- // let temp_dir = env::temp_dir();
- // let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
- // fs::create_dir(&working_dir).unwrap();
- // env::set_current_dir(&working_dir).unwrap();
-
- // let cwd = env::current_dir().unwrap();
- // fs::create_dir(cwd.join("posts")).unwrap();
-
- // let post_body = "# This is a post\n\nHere is some content that goes in the post";
-
- // let mut uuids: Vec<String> = vec![];
-
- // for _ in 1..11 {
- // let uuid = String::from(Uuid::new_v4().to_string());
- // uuids.push(uuid.clone());
- // fs::write(
- // cwd.join("posts").join(format!("{}.md", &uuid)),
- // &String::from(post_body),
- // )
- // .unwrap();
- // }
-
- // let mut expected_paths: Vec<String> = uuids
- // .into_iter()
- // .map(|uuid| {
- // String::from(
- // cwd.join("posts")
- // .join(format!("{}.md", uuid))
- // .to_str()
- // .unwrap(),
- // )
- // })
- // .collect();
- // expected_paths.sort();
- // let mut actual_paths: Vec<String> = read_posts_dir(&cwd.join("posts"))
- // .into_iter()
- // .map(|dir_entry| String::from(dir_entry.path().to_str().unwrap()))
- // .collect();
- // actual_paths.sort();
-
- // assert_eq!(expected_paths, actual_paths);
-
- // fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
- // }
-
- // #[test]
- // fn test_parse_post() {
- // let temp_dir = env::temp_dir();
- // let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
- // fs::create_dir(&working_dir).unwrap();
- // env::set_current_dir(&working_dir).unwrap();
-
- // let cwd = env::current_dir().unwrap();
- // fs::create_dir(cwd.join("posts")).unwrap();
-
- // let slug = Uuid::new_v4().to_string();
- // let filetitle = format!("{}.md", slug);
- // fs::write(
- // cwd.join("posts").join(&filetitle),
- // "# This is a post | 2019-01-01\n\nHere is some content that goes in the post",
- // )
- // .unwrap();
-
- // let post = parse_post(cwd.join("posts").join(&filetitle));
- // let date = NaiveDate::from_ymd(2019, 1, 1);
- // assert_eq!("This is a post", post.title);
- // assert_eq!("Here is some content that goes in the post", post.body);
- // assert_eq!(slug, post.slug);
- // assert_eq!(date, post.date);
-
- // fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
- // }
-
- // #[test]
- // fn test_post_with_multiple_paragraphs() {
- // let temp_dir = env::temp_dir();
- // let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
- // fs::create_dir(&working_dir).unwrap();
- // env::set_current_dir(&working_dir).unwrap();
-
- // let cwd = env::current_dir().unwrap();
- // fs::create_dir(cwd.join("posts")).unwrap();
-
- // let slug = Uuid::new_v4().to_string();
- // let filetitle = format!("{}.md", slug);
- // fs::write(
- // cwd.join("posts").join(&filetitle),
- // "# This is a post | 2019-01-01\n\nHere is a line\n\nHere is another line\n\nAnd a third",
- // )
- // .unwrap();
-
- // let post = parse_post(cwd.join("posts").join(&filetitle));
- // let date = NaiveDate::from_ymd(2019, 1, 1);
- // assert_eq!("This is a post", post.title);
- // assert_eq!(
- // "Here is a line\n\nHere is another line\n\nAnd a third",
- // post.body
- // );
- // assert_eq!(slug, post.slug);
- // assert_eq!(date, post.date);
-
- // fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
- // }
- // }
|