use std::path::{Path, PathBuf};
use googletest::prelude::*;
use super::{Config, TEST_CONFIG};
#[gtest]
fn rejects_an_unknown_domain() -> Result<()> {
let source = TEST_CONFIG.replace("[domains.cargo]", "[domains.unknown]");
let error = Config::parse(&source, Path::new(".markupwright/config.toml"))
.unwrap_err()
.to_string();
verify_that!(error, contains_substring("unknown domain \"unknown\""))
}
#[gtest]
fn rejects_a_glob_as_the_source_suffix() -> Result<()> {
let source = TEST_CONFIG.replace("source-suffix = \".in\"", "source-suffix = \".in*\"");
let error = Config::parse(&source, Path::new(".markupwright/config.toml"))
.unwrap_err()
.to_string();
verify_that!(error, contains_substring("render.source-suffix"))
}
#[gtest]
fn requires_document_patterns_to_end_with_the_source_suffix() -> Result<()> {
let source = TEST_CONFIG.replace(
"include = [\"*.md.in\", \"**/*.md.in\"]",
"include = [\"*.md\"]",
);
let error = Config::parse(&source, Path::new(".markupwright/config.toml"))
.unwrap_err()
.to_string();
verify_that!(error, contains_substring("every pattern must end"))
}
#[gtest]
fn derives_source_and_output_paths_from_the_configured_suffix() -> Result<()> {
let source = TEST_CONFIG
.replace("source-suffix = \".in\"", "source-suffix = \".tmpl\"")
.replace(".md.in", ".md.tmpl");
let config = Config::parse(&source, Path::new(".markupwright/config.toml")).or_fail()?;
verify_eq!(
config.output_path(Path::new("docs/README.md.tmpl")),
PathBuf::from("docs/README.md")
)?;
verify_eq!(
config.source_path(Path::new("docs/README.md")),
PathBuf::from("docs/README.md.tmpl")
)
}
#[gtest]
fn rejects_invalid_domain_owned_paths() -> Result<()> {
let invalid = [
TEST_CONFIG.replacen(
"manifests = [\"__markupwright_test_no_manifest__\"]",
"manifests = [\"../Cargo.toml\"]",
1,
),
TEST_CONFIG.replace(
"[domains.node]\nmanifests = [\"__markupwright_test_no_manifest__\"]",
"[domains.node]\nmanifests = [\"/package.json\"]",
),
TEST_CONFIG.replace(
"[[documents]]",
"[domains.dotenv.environment]\npath = \"../.env\"\n\n[[documents]]",
),
TEST_CONFIG.replace(
"[[documents]]",
"[domains.frontmatter.records]\ninclude = []\nfields = [\"name\"]\n\n[[documents]]",
),
];
for source in invalid {
verify_true!(Config::parse(&source, Path::new(".markupwright/config.toml")).is_err())?;
}
Ok(())
}