mirror of
https://github.com/Theaninova/mhlib.git
synced 2026-01-03 07:12:50 +00:00
add archive tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use serde::Deserialize;
|
|
||||||
use crate::media::ui::UiTag;
|
use crate::media::ui::UiTag;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct UiMenu {
|
pub struct UiMenu {
|
||||||
@@ -9,3 +9,18 @@ pub struct UiMenu {
|
|||||||
#[serde(rename = "$value", default)]
|
#[serde(rename = "$value", default)]
|
||||||
pub children: Vec<UiTag>,
|
pub children: Vec<UiTag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::media::ui::menu::UiMenu;
|
||||||
|
|
||||||
|
// language=xml
|
||||||
|
const MENU: &str = "<Menu selected='item' OnBack='back' />";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_should_read() {
|
||||||
|
let menu: UiMenu = serde_xml_rs::from_str(MENU).unwrap();
|
||||||
|
assert_eq!(menu.selected, "item".to_string());
|
||||||
|
assert_eq!(menu.on_back, Some("back".to_string()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ impl UiTag {
|
|||||||
area_stack.push(children);
|
area_stack.push(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
if area.position.is_some() && area.size.is_some() {
|
if !area.is_closing_tag() {
|
||||||
let children = area.children.drain(..).collect();
|
let children = area.children.drain(..).collect();
|
||||||
area_stack.last_mut().unwrap().push(UiTag::TextArea(area));
|
area_stack.last_mut().unwrap().push(UiTag::TextArea(area));
|
||||||
area_stack.push(children);
|
area_stack.push(children);
|
||||||
@@ -86,3 +86,33 @@ impl UiTag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::media::ui::menu::UiMenu;
|
||||||
|
use crate::media::ui::text_area::UiTextArea;
|
||||||
|
use crate::media::ui::UiTag;
|
||||||
|
|
||||||
|
// language=xml
|
||||||
|
const XML: &str = "<Menu selected='test' OnBack='back'> \
|
||||||
|
<TextArea position='1,2' size='3,4'/> \
|
||||||
|
<StaticText position='1,2' text='test' /> \
|
||||||
|
<TextArea /> \
|
||||||
|
</Menu>";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_should_post_process() {
|
||||||
|
let mut xml: UiTag = serde_xml_rs::from_str(XML).unwrap();
|
||||||
|
xml.post_process();
|
||||||
|
|
||||||
|
if let UiTag::Menu(UiMenu { children, .. }) = xml {
|
||||||
|
if let &[UiTag::TextArea(UiTextArea { children, .. })] = &children.as_slice() {
|
||||||
|
assert!(matches!(&children.as_slice(), &[UiTag::StaticText(..)]));
|
||||||
|
} else {
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,3 +13,35 @@ pub struct UiTextArea {
|
|||||||
#[serde(rename = "$value", default)]
|
#[serde(rename = "$value", default)]
|
||||||
pub children: Vec<UiTag>,
|
pub children: Vec<UiTag>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl UiTextArea {
|
||||||
|
pub fn is_closing_tag(&self) -> bool {
|
||||||
|
self.position.is_none() && self.size.is_none() && self.children.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::media::ui::text_area::UiTextArea;
|
||||||
|
|
||||||
|
// language=xml
|
||||||
|
const TEXT_AREA: &str = "<TextArea position='1,2' size='3,4' />";
|
||||||
|
// language=xml
|
||||||
|
const EMPTY: &str = "<TextArea />";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_should_read() {
|
||||||
|
let text_area: UiTextArea = serde_xml_rs::from_str(TEXT_AREA).unwrap();
|
||||||
|
assert_eq!(text_area.position, Some([1, 2]));
|
||||||
|
assert_eq!(text_area.size, Some([3, 4]));
|
||||||
|
assert!(!text_area.is_closing_tag());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_should_read_empty() {
|
||||||
|
let text_area: UiTextArea = serde_xml_rs::from_str(EMPTY).unwrap();
|
||||||
|
assert_eq!(text_area.position, None);
|
||||||
|
assert_eq!(text_area.size, None);
|
||||||
|
assert!(text_area.is_closing_tag());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user