From 35408f03b1d5e08e9986506e9609571afd95e182 Mon Sep 17 00:00:00 2001 From: ef3d0c3e Date: Tue, 13 Aug 2024 23:17:08 +0200 Subject: [PATCH] Tests --- src/compiler/postprocess.rs | 4 ++-- src/compiler/process.rs | 4 ++-- src/elements/reference.rs | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/compiler/postprocess.rs b/src/compiler/postprocess.rs index b8a50be..e4d3388 100644 --- a/src/compiler/postprocess.rs +++ b/src/compiler/postprocess.rs @@ -35,7 +35,7 @@ impl PostProcess { if let Some(found) = doc.borrow().references.get(name) { // Check for duplicates 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)); @@ -71,7 +71,7 @@ impl PostProcess { "Unable to get the output. Aborting postprocessing." ))?; 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(); } else { return Err(format!("Cannot find reference `{cross_ref}` from document `{}`. Aborting postprocessing.", doc.borrow().input)); diff --git a/src/compiler/process.rs b/src/compiler/process.rs index 5c86708..a8980aa 100644 --- a/src/compiler/process.rs +++ b/src/compiler/process.rs @@ -157,7 +157,7 @@ pub fn process( /// Processes sources from in-memory strings /// This function is indented for testing -fn process_in_memory(target: Target, sources: Vec) -> Result, Option)>, String> { +pub fn process_from_memory(target: Target, sources: Vec) -> Result, Option)>, String> { let mut compiled = vec![]; let parser = LangParser::default(); @@ -169,7 +169,7 @@ fn process_in_memory(target: Target, sources: Vec) -> Result

#refa#ref

")); + assert!(result[2].0.borrow().body.starts_with("

from 0from 1

")); + } }