You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.9KB

  1. extern crate site;
  2. mod common;
  3. use std::env;
  4. use common::build_site;
  5. use site::Site;
  6. #[test]
  7. fn can_parse_multilingual_site() {
  8. let mut path = env::current_dir().unwrap().parent().unwrap().parent().unwrap().to_path_buf();
  9. path.push("test_site_i18n");
  10. let mut site = Site::new(&path, "config.toml").unwrap();
  11. site.load().unwrap();
  12. assert_eq!(site.library.pages().len(), 9);
  13. assert_eq!(site.library.sections().len(), 4);
  14. // default index sections
  15. let default_index_section =
  16. site.library.get_section(&path.join("content").join("_index.md")).unwrap();
  17. assert_eq!(default_index_section.pages.len(), 1);
  18. assert!(default_index_section.ancestors.is_empty());
  19. let fr_index_section =
  20. site.library.get_section(&path.join("content").join("_index.fr.md")).unwrap();
  21. assert_eq!(fr_index_section.pages.len(), 1);
  22. assert!(fr_index_section.ancestors.is_empty());
  23. // blog sections get only their own language pages
  24. let blog_path = path.join("content").join("blog");
  25. let default_blog = site.library.get_section(&blog_path.join("_index.md")).unwrap();
  26. assert_eq!(default_blog.subsections.len(), 0);
  27. assert_eq!(default_blog.pages.len(), 4);
  28. assert_eq!(
  29. default_blog.ancestors,
  30. vec![*site.library.get_section_key(&default_index_section.file.path).unwrap()]
  31. );
  32. for key in &default_blog.pages {
  33. let page = site.library.get_page_by_key(*key);
  34. assert_eq!(page.lang, None);
  35. }
  36. let fr_blog = site.library.get_section(&blog_path.join("_index.fr.md")).unwrap();
  37. assert_eq!(fr_blog.subsections.len(), 0);
  38. assert_eq!(fr_blog.pages.len(), 3);
  39. assert_eq!(
  40. fr_blog.ancestors,
  41. vec![*site.library.get_section_key(&fr_index_section.file.path).unwrap()]
  42. );
  43. for key in &fr_blog.pages {
  44. let page = site.library.get_page_by_key(*key);
  45. assert_eq!(page.lang, Some("fr".to_string()));
  46. }
  47. }
  48. #[test]
  49. fn can_build_multilingual_site() {
  50. let (_, _tmp_dir, public) = build_site("test_site_i18n");
  51. assert!(public.exists());
  52. // Index pages
  53. assert!(file_exists!(public, "index.html"));
  54. assert!(file_exists!(public, "fr/index.html"));
  55. assert!(file_contains!(public, "fr/index.html", "Une page"));
  56. assert!(file_contains!(public, "fr/index.html", "Language: fr"));
  57. assert!(file_exists!(public, "base/index.html"));
  58. assert!(file_exists!(public, "fr/base/index.html"));
  59. // Sections are there as well
  60. assert!(file_exists!(public, "blog/index.html"));
  61. assert!(file_exists!(public, "fr/blog/index.html"));
  62. assert!(file_contains!(public, "fr/blog/index.html", "Language: fr"));
  63. // sitemap contains all languages
  64. assert!(file_exists!(public, "sitemap.xml"));
  65. assert!(file_contains!(public, "sitemap.xml", "https://example.com/blog/something-else/"));
  66. assert!(file_contains!(public, "sitemap.xml", "https://example.com/fr/blog/something-else/"));
  67. }