pub mod counter;
pub mod margin_box;
pub mod parser;
pub mod running;
use margin_box::MarginBoxPosition;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ParsedSelector {
Class(String),
Id(String),
Tag(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RunningMapping {
pub parsed: ParsedSelector,
pub running_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ContentItem {
Element(String),
Counter(CounterType),
String(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum CounterType {
Page,
Pages,
}
#[derive(Debug, Clone, PartialEq)]
pub struct MarginBoxRule {
pub page_selector: Option<String>,
pub position: MarginBoxPosition,
pub content: Vec<ContentItem>,
pub declarations: String,
}
#[derive(Debug, Clone)]
pub struct GcpmContext {
pub margin_boxes: Vec<MarginBoxRule>,
pub running_mappings: Vec<RunningMapping>,
pub cleaned_css: String,
}
impl GcpmContext {
pub fn is_empty(&self) -> bool {
self.margin_boxes.is_empty() && self.running_mappings.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_gcpm_context_is_empty() {
let ctx = GcpmContext {
margin_boxes: vec![],
running_mappings: vec![],
cleaned_css: String::new(),
};
assert!(ctx.is_empty());
}
#[test]
fn test_gcpm_context_not_empty_with_margin_box() {
let ctx = GcpmContext {
margin_boxes: vec![MarginBoxRule {
page_selector: None,
position: MarginBoxPosition::TopCenter,
content: vec![ContentItem::Counter(CounterType::Page)],
declarations: String::new(),
}],
running_mappings: vec![],
cleaned_css: String::new(),
};
assert!(!ctx.is_empty());
}
#[test]
fn test_gcpm_context_not_empty_with_running_name() {
let ctx = GcpmContext {
margin_boxes: vec![],
running_mappings: vec![RunningMapping {
parsed: ParsedSelector::Class("header".to_string()),
running_name: "header".to_string(),
}],
cleaned_css: String::new(),
};
assert!(!ctx.is_empty());
}
}