Skip to content

Commit

Permalink
fix: handle empty content
Browse files Browse the repository at this point in the history
  • Loading branch information
mhatzl committed Apr 27, 2022
1 parent 921ad24 commit e92e9be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/unimarkup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ impl Html<'_> {
///
/// Returns a [`CoreError`], if error occurs during compilation.
pub fn compile(um_content: &str, mut config: Config) -> Result<UnimarkupDocument, CoreError> {
if um_content.is_empty() {
return Ok(UnimarkupDocument {
elements: vec![],
config,
});
}

let mut connection = middleend::setup_ir_connection()?;
middleend::setup_ir(&connection)?;

Expand Down
17 changes: 17 additions & 0 deletions core/tests/unimarkup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(non_snake_case)]

use clap::Parser;
use unimarkup_core::config::Config;

#[test]
fn test__compile__empty_content() {
let cfg: Config = Config::parse_from(vec![
"unimarkup",
"--output-formats=html",
"tests/test_files/all_syntax.um",
]);

let rendered_result = unimarkup_core::unimarkup::compile("", cfg);

assert!(rendered_result.unwrap().elements.is_empty());
}

0 comments on commit e92e9be

Please sign in to comment.