Skip to content

Commit 36310a1

Browse files
committed
Use common xml patterns
1 parent 0bcccd4 commit 36310a1

3 files changed

Lines changed: 102 additions & 77 deletions

File tree

thoth-export-server/src/xml/dublincore_thoth.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use thoth_client::{
99
};
1010
use thoth_errors::{ThothError, ThothResult};
1111
use xml::writer::events::StartElementBuilder;
12-
use xml::writer::{EmitterConfig, EventWriter, XmlEvent};
12+
#[cfg(test)]
13+
use xml::writer::EmitterConfig;
14+
use xml::writer::{EventWriter, XmlEvent};
1315

1416
const DUBLIN_CORE_ERROR: &str = "dublin_core::thoth";
1517
const BY_WORK_ONLY_MESSAGE: &str = "Output can only be generated for one work at a time";
@@ -48,7 +50,11 @@ impl XmlElementBlock<DublinCoreThoth> for Work {
4850
}
4951
}
5052

51-
fn push_text_element<W: Write>(xml: &mut EventWriter<W>, name: &str, text: &str) -> ThothResult<()> {
53+
fn push_text_element<W: Write>(
54+
xml: &mut EventWriter<W>,
55+
name: &str,
56+
text: &str,
57+
) -> ThothResult<()> {
5258
write_element_block(name, xml, |xml| {
5359
xml.write(XmlEvent::Characters(text)).map_err(|e| e.into())
5460
})
@@ -431,6 +437,7 @@ fn write_dublin_core<W: Write>(work: &Work, xml: &mut EventWriter<W>) -> ThothRe
431437
push_close_tag(xml, "oai_dc:dc")
432438
}
433439

440+
#[cfg(test)]
434441
fn map_dublin_core(work: &Work) -> ThothResult<String> {
435442
let mut buffer = Vec::new();
436443
let mut writer = EmitterConfig::new()
@@ -912,7 +919,11 @@ mod tests {
912919
"<dc:title>Canonical Title: A Story</dc:title>",
913920
"<dc:title>Alternativer Titel</dc:title>",
914921
);
915-
assert_precedes(&xml, "<dc:type>book</dc:type>", "<dc:format>application/pdf</dc:format>");
922+
assert_precedes(
923+
&xml,
924+
"<dc:type>book</dc:type>",
925+
"<dc:format>application/pdf</dc:format>",
926+
);
916927
assert_precedes(
917928
&xml,
918929
"<dc:rights>http://creativecommons.org/licenses/by/4.0/</dc:rights>",

0 commit comments

Comments
 (0)