Fix missing attribut
This commit is contained in:
@@ -8,6 +8,8 @@ pub struct AttributeName {
|
||||
element: Arc<schema::XsElement>,
|
||||
/// Buffer containing the attribute name characters processed so far
|
||||
buffer: String,
|
||||
/// Track which attributes have already been set for this element
|
||||
attributes_set: Vec<String>,
|
||||
}
|
||||
|
||||
impl AttributeName {
|
||||
@@ -16,14 +18,25 @@ impl AttributeName {
|
||||
Self {
|
||||
element,
|
||||
buffer: String::new(),
|
||||
attributes_set: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new AttributeName with the given buffer
|
||||
pub fn with_buffer(element: Arc<schema::XsElement>, buffer: String) -> Self {
|
||||
pub fn with_buffer(element: Arc<schema::XsElement>, buffer: String, attributes_set: Vec<String>) -> Self {
|
||||
Self {
|
||||
element,
|
||||
buffer,
|
||||
attributes_set,
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new AttributeName with attributes already set
|
||||
pub fn with_attributes(element: Arc<schema::XsElement>, attributes_set: Vec<String>) -> Self {
|
||||
Self {
|
||||
element,
|
||||
buffer: String::new(),
|
||||
attributes_set,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +54,7 @@ impl AttributeName {
|
||||
return vec![Token::AttributeValue(AttributeValue::new(
|
||||
Arc::clone(&self.element),
|
||||
self.buffer,
|
||||
self.attributes_set,
|
||||
))];
|
||||
}
|
||||
}
|
||||
@@ -59,6 +73,7 @@ impl AttributeName {
|
||||
return vec![Token::AttributeName(AttributeName::with_buffer(
|
||||
Arc::clone(&self.element),
|
||||
new_buffer,
|
||||
self.attributes_set.clone(),
|
||||
))];
|
||||
}
|
||||
}
|
||||
@@ -147,4 +162,35 @@ mod attribute_name_tests {
|
||||
let next_tokens = token.append('x'); // 'x' doesn't start any valid attribute
|
||||
assert!(next_tokens.is_empty(), "Should reject invalid attribute name");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_attribute_tracking() {
|
||||
let element = create_element_with_attributes();
|
||||
|
||||
// Create AttributeName with pre-existing attributes
|
||||
let attributes_set = vec!["other".to_string()];
|
||||
let token = AttributeName::with_attributes(Arc::clone(&element), attributes_set.clone());
|
||||
|
||||
// Build attribute name and transition to AttributeValue
|
||||
let mut current_token = token;
|
||||
for c in "id".chars() {
|
||||
let next_tokens = current_token.append(c);
|
||||
match &next_tokens[0] {
|
||||
Token::AttributeName(next) => current_token = next.clone(),
|
||||
_ => panic!("Expected AttributeName, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
|
||||
// Test equals sign
|
||||
let next_tokens = current_token.append('=');
|
||||
|
||||
match &next_tokens[0] {
|
||||
Token::AttributeValue(value) => {
|
||||
// Verify that pre-existing attributes are preserved
|
||||
assert!(value.attributes_set.contains(&"other".to_string()),
|
||||
"Pre-existing attribute should be preserved");
|
||||
},
|
||||
_ => panic!("Expected AttributeValue, got {:?}", next_tokens[0]),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user