Skip to content

Commit 07cd833

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 07cd833

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/lib.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,49 @@ 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+
&[
513+
Script::Inherited,
514+
Script::Common,
515+
Script::Inherited,
516+
Script::Latin,
517+
],
518+
),
519+
(
520+
ScriptExtension::new_inherited()
521+
.union(script_extensions::LATIN)
522+
.union(script_extensions::CYRILLIC),
523+
&[
524+
Script::Inherited,
525+
Script::Common,
526+
Script::Inherited,
527+
Script::Latin,
528+
Script::Cyrillic,
529+
],
530+
),
531+
];
532+
for &(full_extension, component_scripts) in cases {
533+
for &script in component_scripts.iter() {
534+
assert!(full_extension.contains_script(script));
535+
let script_ext = script.into();
536+
assert_eq!(full_extension.intersection(script_ext), script_ext);
537+
assert_eq!(full_extension.union(script_ext), full_extension);
538+
}
539+
let scripts = component_scripts.iter().cloned().collect::<Vec<_>>();
540+
let scripts_iterated = full_extension.iter().collect::<Vec<_>>();
541+
assert_eq!(scripts, scripts_iterated);
542+
}
543+
}
544+
502545
#[cfg(feature = "bench")]
503546
#[bench]
504547
fn bench_script_intersection(b: &mut Bencher) {

0 commit comments

Comments
 (0)