Fixed attribute parsing
This commit is contained in:
@@ -1,84 +1,84 @@
|
||||
use std::sync::Arc;
|
||||
use crate::*;
|
||||
|
||||
/// Represents the text content within an XML element
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextContent {
|
||||
element: Arc<schema::XsElement>,
|
||||
}
|
||||
|
||||
impl TextContent {
|
||||
pub fn new(element: Arc<schema::XsElement>) -> Self {
|
||||
Self {
|
||||
element,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn append(self, c: char) -> Vec<Token> {
|
||||
if c == '<' {
|
||||
vec![Token::ElementCloseStart(ElementCloseStart::new(Arc::clone(&self.element)))]
|
||||
} else {
|
||||
vec![Token::TextContent(TextContent::new(
|
||||
Arc::clone(&self.element),
|
||||
))]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod text_content_tests {
|
||||
use super::*;
|
||||
use std::sync::Arc;
|
||||
use crate::schema;
|
||||
|
||||
fn create_test_element() -> Arc<schema::XsElement> {
|
||||
let element = schema::XsElement {
|
||||
name: "reasoning".to_string(),
|
||||
text: None,
|
||||
xs_complex_type: schema::XsComplexType {
|
||||
mixed: Some("true".to_string()),
|
||||
text: None,
|
||||
xs_attribute: None,
|
||||
xs_sequence: Some(schema::XsSequence {
|
||||
text: None,
|
||||
xs_any: schema::XsAny {
|
||||
min_occurs: "0".to_string(),
|
||||
max_occurs: "unbounded".to_string(),
|
||||
process_contents: "skip".to_string(),
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
Arc::new(element)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_content_normal_char() {
|
||||
let element = create_test_element();
|
||||
let token = TextContent::new(Arc::clone(&element));
|
||||
|
||||
// Test with normal character
|
||||
let next_tokens = token.append('a');
|
||||
assert!(!next_tokens.is_empty(), "Should accept normal character");
|
||||
|
||||
match &next_tokens[0] {
|
||||
Token::TextContent(_) => (),
|
||||
_ => panic!("Expected TextContent, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_content_less_than() {
|
||||
let element = create_test_element();
|
||||
let token = TextContent::new(Arc::clone(&element));
|
||||
|
||||
// Test with < (start of tag)
|
||||
let next_tokens = token.append('<');
|
||||
assert!(!next_tokens.is_empty(), "Should accept '<'");
|
||||
|
||||
match &next_tokens[0] {
|
||||
Token::ElementCloseStart(_) => (),
|
||||
_ => panic!("Expected ElementCloseStart, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// Represents the text content within an XML element
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TextContent {
|
||||
element: Arc<schema::XsElement>,
|
||||
}
|
||||
|
||||
impl TextContent {
|
||||
pub fn new(element: Arc<schema::XsElement>) -> Self {
|
||||
Self { element }
|
||||
}
|
||||
|
||||
pub fn append(self, c: char) -> Vec<Token> {
|
||||
if c == '<' {
|
||||
vec![Token::ElementCloseStart(ElementCloseStart::new(
|
||||
Arc::clone(&self.element),
|
||||
))]
|
||||
} else {
|
||||
vec![Token::TextContent(TextContent::new(Arc::clone(
|
||||
&self.element,
|
||||
)))]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod text_content_tests {
|
||||
use super::*;
|
||||
use crate::schema;
|
||||
use std::sync::Arc;
|
||||
|
||||
fn create_test_element() -> Arc<schema::XsElement> {
|
||||
let element = schema::XsElement {
|
||||
name: "reasoning".to_string(),
|
||||
text: None,
|
||||
xs_complex_type: schema::XsComplexType {
|
||||
mixed: Some("true".to_string()),
|
||||
text: None,
|
||||
xs_attribute: None,
|
||||
xs_sequence: Some(schema::XsSequence {
|
||||
text: None,
|
||||
xs_any: schema::XsAny {
|
||||
min_occurs: "0".to_string(),
|
||||
max_occurs: "unbounded".to_string(),
|
||||
process_contents: "skip".to_string(),
|
||||
},
|
||||
}),
|
||||
},
|
||||
};
|
||||
Arc::new(element)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_content_normal_char() {
|
||||
let element = create_test_element();
|
||||
let token = TextContent::new(Arc::clone(&element));
|
||||
|
||||
// Test with normal character
|
||||
let next_tokens = token.append('a');
|
||||
assert!(!next_tokens.is_empty(), "Should accept normal character");
|
||||
|
||||
match &next_tokens[0] {
|
||||
Token::TextContent(_) => (),
|
||||
_ => panic!("Expected TextContent, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_content_less_than() {
|
||||
let element = create_test_element();
|
||||
let token = TextContent::new(Arc::clone(&element));
|
||||
|
||||
// Test with < (start of tag)
|
||||
let next_tokens = token.append('<');
|
||||
assert!(!next_tokens.is_empty(), "Should accept '<'");
|
||||
|
||||
match &next_tokens[0] {
|
||||
Token::ElementCloseStart(_) => (),
|
||||
_ => panic!("Expected ElementCloseStart, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user