Add tests for categories and tags
This commit is contained in:
parent
d8995c156c
commit
6df68da84b
|
@ -8,6 +8,11 @@ use toml::{Value as Toml, self};
|
||||||
use errors::{Result, ResultExt};
|
use errors::{Result, ResultExt};
|
||||||
|
|
||||||
|
|
||||||
|
// TO ADD:
|
||||||
|
// highlight code theme
|
||||||
|
// generate_tags_pages
|
||||||
|
// generate_categories_pages
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
/// Title of the site
|
/// Title of the site
|
||||||
|
|
|
@ -163,9 +163,45 @@ fn test_can_build_site_with_categories() {
|
||||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||||
path.push("test_site");
|
path.push("test_site");
|
||||||
let mut site = Site::new(&path).unwrap();
|
let mut site = Site::new(&path).unwrap();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
for (_, page) in &mut site.pages {
|
||||||
|
page.meta.category = if i % 2 == 0 {
|
||||||
|
Some("A".to_string())
|
||||||
|
} else {
|
||||||
|
Some("B".to_string())
|
||||||
|
};
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||||
site.set_output_path(&tmp_dir);
|
let public = &tmp_dir.path().join("public");
|
||||||
|
site.set_output_path(&public);
|
||||||
site.build().unwrap();
|
site.build().unwrap();
|
||||||
|
|
||||||
|
assert!(Path::new(&public).exists());
|
||||||
|
|
||||||
|
assert!(file_exists!(public, "index.html"));
|
||||||
|
assert!(file_exists!(public, "sitemap.xml"));
|
||||||
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
||||||
|
|
||||||
|
assert!(file_exists!(public, "posts/python/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
||||||
|
|
||||||
|
// Sections
|
||||||
|
assert!(file_exists!(public, "posts/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
|
||||||
|
// TODO: add assertion for syntax highlighting
|
||||||
|
|
||||||
|
// Categories are there
|
||||||
|
assert!(file_exists!(public, "categories/index.html"));
|
||||||
|
assert!(file_exists!(public, "categories/a/index.html"));
|
||||||
|
assert!(file_exists!(public, "categories/b/index.html"));
|
||||||
|
// Tags aren't
|
||||||
|
assert_eq!(file_exists!(public, "tags/index.html"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -173,7 +209,44 @@ fn test_can_build_site_with_tags() {
|
||||||
let mut path = env::current_dir().unwrap().to_path_buf();
|
let mut path = env::current_dir().unwrap().to_path_buf();
|
||||||
path.push("test_site");
|
path.push("test_site");
|
||||||
let mut site = Site::new(&path).unwrap();
|
let mut site = Site::new(&path).unwrap();
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
for (_, page) in &mut site.pages {
|
||||||
|
page.meta.tags = if i % 2 == 0 {
|
||||||
|
Some(vec!["tag1".to_string(), "tag2".to_string()])
|
||||||
|
} else {
|
||||||
|
Some(vec!["tag with space".to_string()])
|
||||||
|
};
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
let tmp_dir = TempDir::new("example").expect("create temp dir");
|
||||||
site.set_output_path(&tmp_dir);
|
let public = &tmp_dir.path().join("public");
|
||||||
|
site.set_output_path(&public);
|
||||||
site.build().unwrap();
|
site.build().unwrap();
|
||||||
|
|
||||||
|
assert!(Path::new(&public).exists());
|
||||||
|
|
||||||
|
assert!(file_exists!(public, "index.html"));
|
||||||
|
assert!(file_exists!(public, "sitemap.xml"));
|
||||||
|
assert!(file_exists!(public, "a-fixed-url/index.html"));
|
||||||
|
|
||||||
|
assert!(file_exists!(public, "posts/python/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/devops/nix/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/with-assets/index.html"));
|
||||||
|
|
||||||
|
// Sections
|
||||||
|
assert!(file_exists!(public, "posts/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/devops/index.html"));
|
||||||
|
assert!(file_exists!(public, "posts/tutorials/programming/index.html"));
|
||||||
|
// TODO: add assertion for syntax highlighting
|
||||||
|
|
||||||
|
// Tags are there
|
||||||
|
assert!(file_exists!(public, "tags/index.html"));
|
||||||
|
assert!(file_exists!(public, "tags/tag1/index.html"));
|
||||||
|
assert!(file_exists!(public, "tags/tag2/index.html"));
|
||||||
|
assert!(file_exists!(public, "tags/tag-with-space/index.html"));
|
||||||
|
// Categories aren't
|
||||||
|
assert_eq!(file_exists!(public, "categories/index.html"), false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue