", numbered_attrs("a", n)); + let result = tokenize_tags(&input); + + let tags = result.tags.borrow(); + assert_eq!(tags[0].attrs.len(), n); + assert_eq!(attr(&tags[0], 0), ("a0", "0")); + assert!(tags[0].had_duplicate_attributes); + assert_eq!(*result.errors.borrow(), vec!["Duplicate attribute"]); + } + } + + #[test] + fn duplicate_of_an_attribute_after_the_threshold() { + // id comes after the threshold, so its duplicate is found among the + // names added to the set one by one. + let input = format!("
", numbered_attrs("a", MANY_ATTRS)); + let result = tokenize_tags(&input); + + let tags = result.tags.borrow(); + assert_eq!(tags[0].attrs.len(), MANY_ATTRS + 1); + assert_eq!(attr(&tags[0], MANY_ATTRS), ("id", "first")); + assert!(tags[0].had_duplicate_attributes); + assert_eq!(*result.errors.borrow(), vec!["Duplicate attribute"]); + } + + #[test] + fn no_duplicates_on_a_next_tag_with_the_same_attributes() { + // The set is cleared for each tag, so the second tag doesn't find the + // first tag's names. + let attrs = numbered_attrs("a", MANY_ATTRS); + let input = format!("
"); + let result = tokenize_tags(&input); + + let tags = result.tags.borrow(); + assert_eq!(tags.len(), 2); + assert_eq!(tags[1].attrs.len(), MANY_ATTRS); + assert!(!tags[1].had_duplicate_attributes); + assert!(result.errors.borrow().is_empty()); + } + + #[test] + fn duplicate_on_a_next_tag_with_other_attributes() { + let input = format!( + "
", + numbered_attrs("a", MANY_ATTRS), + numbered_attrs("b", MANY_ATTRS) + ); + let result = tokenize_tags(&input); + + let tags = result.tags.borrow(); + assert!(!tags[0].had_duplicate_attributes); + // The set is filled again for each tag, so the second tag finds its own + // duplicate. + assert_eq!(tags[1].attrs.len(), MANY_ATTRS); + assert!(tags[1].had_duplicate_attributes); + assert_eq!(*result.errors.borrow(), vec!["Duplicate attribute"]); + } }