Skip to content

Commit a5a3cb2

Browse files
committed
Implement test to clarify and fix iterator and subset relationships
Description: On reviewing the source code, it appears that the iterator implementation for `ScriptExtension` only ever yields a single element. I did not see this documented, and assuming this is a bug, I have written a test case to clarify the expected subset, union, and iterator behavior. If maintainers believe this behavior as shown in the test is correct, I can go ahead and implement the fixes in the rest of the library.
1 parent 1f84c2e commit a5a3cb2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,43 @@ mod tests {
499499
assert!(scr.is_err());
500500
}
501501

502+
#[test]
503+
fn test_subsets_and_iter() {
504+
let cases: &[(ScriptExtension, &[Script])] = &[
505+
(ScriptExtension::new_inherited(), &[Script::Inherited]),
506+
(
507+
ScriptExtension::new_common(),
508+
&[Script::Inherited, Script::Common],
509+
),
510+
(
511+
ScriptExtension::new_inherited().union(script_extensions::LATIN),
512+
&[Script::Inherited, Script::Common, Script::Latin],
513+
),
514+
(
515+
ScriptExtension::new_inherited()
516+
.union(script_extensions::LATIN)
517+
.union(script_extensions::CYRILLIC),
518+
&[
519+
Script::Inherited,
520+
Script::Common,
521+
Script::Latin,
522+
Script::Cyrillic,
523+
],
524+
),
525+
];
526+
for &(full_extension, component_scripts) in cases {
527+
for &script in component_scripts.iter() {
528+
assert!(full_extension.contains_script(script));
529+
let script_ext = script.into();
530+
assert_eq!(full_extension.intersection(script_ext), script_ext);
531+
assert_eq!(full_extension.union(script_ext), full_extension);
532+
}
533+
let scripts = component_scripts.iter().cloned().collect::<Vec<_>>();
534+
let scripts_iterated = full_extension.iter().collect::<Vec<_>>();
535+
assert_eq!(scripts, scripts_iterated);
536+
}
537+
}
538+
502539
#[cfg(feature = "bench")]
503540
#[bench]
504541
fn bench_script_intersection(b: &mut Bencher) {

0 commit comments

Comments
 (0)