Tests
This commit is contained in:
parent
2211c44ee0
commit
35408f03b1
3 changed files with 36 additions and 5 deletions
|
@ -35,7 +35,7 @@ impl PostProcess {
|
||||||
if let Some(found) = doc.borrow().references.get(name) {
|
if let Some(found) = doc.borrow().references.get(name) {
|
||||||
// Check for duplicates
|
// Check for duplicates
|
||||||
if let Some((_, previous_doc)) = &found_ref {
|
if let Some((_, previous_doc)) = &found_ref {
|
||||||
return Err(format!("Cannot use an unspecific reference for reference named: `{found}`. Found in document `{}` but also in `{}`. Specify the source of the reference to resolve the conflict.", previous_doc.borrow().input, doc.borrow().input));
|
return Err(format!("Cannot use an unspecific reference for reference named: `{name}`. Found in document `{}` but also in `{}`. Specify the source of the reference to resolve the conflict.", previous_doc.borrow().input, doc.borrow().input));
|
||||||
}
|
}
|
||||||
|
|
||||||
found_ref = Some((found.clone(), &doc));
|
found_ref = Some((found.clone(), &doc));
|
||||||
|
@ -71,7 +71,7 @@ impl PostProcess {
|
||||||
"Unable to get the output. Aborting postprocessing."
|
"Unable to get the output. Aborting postprocessing."
|
||||||
))?;
|
))?;
|
||||||
let insert_content = format!("{found_path}#{found_ref}");
|
let insert_content = format!("{found_path}#{found_ref}");
|
||||||
content.insert_str(pos - offset, insert_content.as_str());
|
content.insert_str(pos + offset, insert_content.as_str());
|
||||||
offset += insert_content.len();
|
offset += insert_content.len();
|
||||||
} else {
|
} else {
|
||||||
return Err(format!("Cannot find reference `{cross_ref}` from document `{}`. Aborting postprocessing.", doc.borrow().input));
|
return Err(format!("Cannot find reference `{cross_ref}` from document `{}`. Aborting postprocessing.", doc.borrow().input));
|
||||||
|
|
|
@ -157,7 +157,7 @@ pub fn process(
|
||||||
|
|
||||||
/// Processes sources from in-memory strings
|
/// Processes sources from in-memory strings
|
||||||
/// This function is indented for testing
|
/// This function is indented for testing
|
||||||
fn process_in_memory(target: Target, sources: Vec<String>) -> Result<Vec<(RefCell<CompiledDocument>, Option<PostProcess>)>, String> {
|
pub fn process_from_memory(target: Target, sources: Vec<String>) -> Result<Vec<(RefCell<CompiledDocument>, Option<PostProcess>)>, String> {
|
||||||
let mut compiled = vec![];
|
let mut compiled = vec![];
|
||||||
|
|
||||||
let parser = LangParser::default();
|
let parser = LangParser::default();
|
||||||
|
@ -169,7 +169,7 @@ fn process_in_memory(target: Target, sources: Vec<String>) -> Result<Vec<(RefCel
|
||||||
|
|
||||||
// Compile
|
// Compile
|
||||||
let compiler = Compiler::new(target, None);
|
let compiler = Compiler::new(target, None);
|
||||||
let (mut compiled, postprocess) = compiler.compile(&*doc);
|
let (compiled, postprocess) = compiler.compile(&*doc);
|
||||||
|
|
||||||
Ok((compiled, Some(postprocess)))
|
Ok((compiled, Some(postprocess)))
|
||||||
};
|
};
|
||||||
|
|
|
@ -306,6 +306,7 @@ impl RegexRule for ReferenceRule {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::compiler::process::process_from_memory;
|
||||||
use crate::elements::paragraph::Paragraph;
|
use crate::elements::paragraph::Paragraph;
|
||||||
use crate::elements::section::Section;
|
use crate::elements::section::Section;
|
||||||
use crate::parser::langparser::LangParser;
|
use crate::parser::langparser::LangParser;
|
||||||
|
@ -363,4 +364,34 @@ use crate::parser::source::SourceFile;
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn test_external()
|
||||||
|
{
|
||||||
|
let result = process_from_memory(Target::HTML, vec![
|
||||||
|
r#"
|
||||||
|
@html.page_title = 0
|
||||||
|
@compiler.output = a.html
|
||||||
|
|
||||||
|
#{ref} Referenceable section
|
||||||
|
"#.into(),
|
||||||
|
r#"
|
||||||
|
@html.page_title = 1
|
||||||
|
@compiler.output = b.html
|
||||||
|
|
||||||
|
§{#ref}
|
||||||
|
§{a#ref}
|
||||||
|
#{ref2} Another Referenceable section
|
||||||
|
"#.into(),
|
||||||
|
r#"
|
||||||
|
@html.page_title = 2
|
||||||
|
|
||||||
|
§{#ref}[caption=from 0]
|
||||||
|
§{#ref2}[caption=from 1]
|
||||||
|
"#.into(),
|
||||||
|
]).unwrap();
|
||||||
|
|
||||||
|
assert!(result[1].0.borrow().body.starts_with("<div class=\"content\"><p><a href=\"a.html#Referenceable_section\">#ref</a><a href=\"a.html#Referenceable_section\">a#ref</a></p>"));
|
||||||
|
assert!(result[2].0.borrow().body.starts_with("<div class=\"content\"><p><a href=\"a.html#Referenceable_section\">from 0</a><a href=\"b.html#Another_Referenceable_section\">from 1</a></p>"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue