|
@@ -1,140 +0,0 @@
|
1
|
|
-// use chrono::NaiveDate;
|
2
|
|
-
|
3
|
|
-// #[derive(Debug)]
|
4
|
|
-// pub struct Post {
|
5
|
|
-// pub title: String,
|
6
|
|
-// pub body: String,
|
7
|
|
-// pub slug: String,
|
8
|
|
-// pub date: NaiveDate,
|
9
|
|
-// }
|
10
|
|
-
|
11
|
|
-// impl Post {
|
12
|
|
-// fn date(&self) -> String {
|
13
|
|
-// self.date.format("%Y-%m-%d").to_string()
|
14
|
|
-// }
|
15
|
|
-
|
16
|
|
-// fn render(&self, template: &str) -> String {
|
17
|
|
-// template
|
18
|
|
-// .replace("{{ title }}", &self.title)
|
19
|
|
-// .replace("{{ slug }}", &self.slug)
|
20
|
|
-// .replace("{{ body }}", &self.body)
|
21
|
|
-// .replace("{{ date }}", &self.date())
|
22
|
|
-// }
|
23
|
|
-// }
|
24
|
|
-
|
25
|
|
-// #[cfg(test)]
|
26
|
|
-// mod tests {
|
27
|
|
-// #[allow(unused_imports)]
|
28
|
|
-// use super::*;
|
29
|
|
-// #[allow(unused_imports)]
|
30
|
|
-// #[allow(unused_imports)]
|
31
|
|
-// use std::{env, fs, path};
|
32
|
|
-// #[allow(unused_imports)]
|
33
|
|
-// use uuid::Uuid;
|
34
|
|
-
|
35
|
|
-// #[test]
|
36
|
|
-// fn test_read_posts_dir() {
|
37
|
|
-// let temp_dir = env::temp_dir();
|
38
|
|
-// let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
|
39
|
|
-// fs::create_dir(&working_dir).unwrap();
|
40
|
|
-// env::set_current_dir(&working_dir).unwrap();
|
41
|
|
-
|
42
|
|
-// let cwd = env::current_dir().unwrap();
|
43
|
|
-// fs::create_dir(cwd.join("posts")).unwrap();
|
44
|
|
-
|
45
|
|
-// let post_body = "# This is a post\n\nHere is some content that goes in the post";
|
46
|
|
-
|
47
|
|
-// let mut uuids: Vec<String> = vec![];
|
48
|
|
-
|
49
|
|
-// for _ in 1..11 {
|
50
|
|
-// let uuid = String::from(Uuid::new_v4().to_string());
|
51
|
|
-// uuids.push(uuid.clone());
|
52
|
|
-// fs::write(
|
53
|
|
-// cwd.join("posts").join(format!("{}.md", &uuid)),
|
54
|
|
-// &String::from(post_body),
|
55
|
|
-// )
|
56
|
|
-// .unwrap();
|
57
|
|
-// }
|
58
|
|
-
|
59
|
|
-// let mut expected_paths: Vec<String> = uuids
|
60
|
|
-// .into_iter()
|
61
|
|
-// .map(|uuid| {
|
62
|
|
-// String::from(
|
63
|
|
-// cwd.join("posts")
|
64
|
|
-// .join(format!("{}.md", uuid))
|
65
|
|
-// .to_str()
|
66
|
|
-// .unwrap(),
|
67
|
|
-// )
|
68
|
|
-// })
|
69
|
|
-// .collect();
|
70
|
|
-// expected_paths.sort();
|
71
|
|
-// let mut actual_paths: Vec<String> = read_posts_dir(&cwd.join("posts"))
|
72
|
|
-// .into_iter()
|
73
|
|
-// .map(|dir_entry| String::from(dir_entry.path().to_str().unwrap()))
|
74
|
|
-// .collect();
|
75
|
|
-// actual_paths.sort();
|
76
|
|
-
|
77
|
|
-// assert_eq!(expected_paths, actual_paths);
|
78
|
|
-
|
79
|
|
-// fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
|
80
|
|
-// }
|
81
|
|
-
|
82
|
|
-// #[test]
|
83
|
|
-// fn test_parse_post() {
|
84
|
|
-// let temp_dir = env::temp_dir();
|
85
|
|
-// let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
|
86
|
|
-// fs::create_dir(&working_dir).unwrap();
|
87
|
|
-// env::set_current_dir(&working_dir).unwrap();
|
88
|
|
-
|
89
|
|
-// let cwd = env::current_dir().unwrap();
|
90
|
|
-// fs::create_dir(cwd.join("posts")).unwrap();
|
91
|
|
-
|
92
|
|
-// let slug = Uuid::new_v4().to_string();
|
93
|
|
-// let filetitle = format!("{}.md", slug);
|
94
|
|
-// fs::write(
|
95
|
|
-// cwd.join("posts").join(&filetitle),
|
96
|
|
-// "# This is a post | 2019-01-01\n\nHere is some content that goes in the post",
|
97
|
|
-// )
|
98
|
|
-// .unwrap();
|
99
|
|
-
|
100
|
|
-// let post = parse_post(cwd.join("posts").join(&filetitle));
|
101
|
|
-// let date = NaiveDate::from_ymd(2019, 1, 1);
|
102
|
|
-// assert_eq!("This is a post", post.title);
|
103
|
|
-// assert_eq!("Here is some content that goes in the post", post.body);
|
104
|
|
-// assert_eq!(slug, post.slug);
|
105
|
|
-// assert_eq!(date, post.date);
|
106
|
|
-
|
107
|
|
-// fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
|
108
|
|
-// }
|
109
|
|
-
|
110
|
|
-// #[test]
|
111
|
|
-// fn test_post_with_multiple_paragraphs() {
|
112
|
|
-// let temp_dir = env::temp_dir();
|
113
|
|
-// let working_dir = temp_dir.join(&Uuid::new_v4().to_string());
|
114
|
|
-// fs::create_dir(&working_dir).unwrap();
|
115
|
|
-// env::set_current_dir(&working_dir).unwrap();
|
116
|
|
-
|
117
|
|
-// let cwd = env::current_dir().unwrap();
|
118
|
|
-// fs::create_dir(cwd.join("posts")).unwrap();
|
119
|
|
-
|
120
|
|
-// let slug = Uuid::new_v4().to_string();
|
121
|
|
-// let filetitle = format!("{}.md", slug);
|
122
|
|
-// fs::write(
|
123
|
|
-// cwd.join("posts").join(&filetitle),
|
124
|
|
-// "# This is a post | 2019-01-01\n\nHere is a line\n\nHere is another line\n\nAnd a third",
|
125
|
|
-// )
|
126
|
|
-// .unwrap();
|
127
|
|
-
|
128
|
|
-// let post = parse_post(cwd.join("posts").join(&filetitle));
|
129
|
|
-// let date = NaiveDate::from_ymd(2019, 1, 1);
|
130
|
|
-// assert_eq!("This is a post", post.title);
|
131
|
|
-// assert_eq!(
|
132
|
|
-// "Here is a line\n\nHere is another line\n\nAnd a third",
|
133
|
|
-// post.body
|
134
|
|
-// );
|
135
|
|
-// assert_eq!(slug, post.slug);
|
136
|
|
-// assert_eq!(date, post.date);
|
137
|
|
-
|
138
|
|
-// fs::remove_dir_all(temp_dir.join(&working_dir)).unwrap();
|
139
|
|
-// }
|
140
|
|
-// }
|