Skip to content

Commit eab205a

Browse files
authored
Merge pull request #137 from kas-gui/push-pkvrnomuxsqx
Disable font-fallback breaking in tests
2 parents a087ae3 + 842c664 commit eab205a

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/display/text_runs.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl TextDisplay {
7070
/// Resolve font face and shape run
7171
///
7272
/// This may sub-divide text as required to find matching fonts.
73+
#[cfg_attr(test, allow(unused_mut))]
7374
fn push_run(
7475
&mut self,
7576
font: FontSelector,
@@ -101,11 +102,14 @@ impl TextDisplay {
101102
let mut face = preferred_face;
102103

103104
let mut start = 0;
105+
#[cfg_attr(test, allow(unused_variables))]
104106
for (index, c) in text.char_indices() {
105107
if DefaultIgnorableCodePoint::for_char(c) {
106108
continue;
107109
}
108110

111+
// HACK: disable font-fallback breaking in tests to get repeatable results
112+
#[cfg(not(test))]
109113
if let Some(new_face) = fonts
110114
.face_for_char(font_id, Some(preferred_face), c)
111115
.expect("invalid FontId")
@@ -705,11 +709,10 @@ mod test {
705709
test_breaking(sample, Direction::Rtl, &expected_rtl[..]);
706710
}
707711

712+
// Additional tests for right-to-left languages: Hebrew, Arabic.
713+
// Samples are translations of the first article of the UDHR from https://r12a.github.io/
708714
#[test]
709-
fn test_breaking_rtl() {
710-
// Additional tests for right-to-left languages: Hebrew, Arabic.
711-
// Samples are translations of the first article of the UDHR from https://r12a.github.io/
712-
715+
fn test_breaking_hebrew() {
713716
let sample = "סעיף א. כל בני אדם נולדו בני חורין ושווים בערכם ובזכויותיהם. כולם חוננו בתבונה ובמצפון, לפיכך חובה עליהם לנהוג איש ברעהו ברוח של אחוה.";
714717
test_breaking(
715718
sample,
@@ -725,7 +728,10 @@ mod test {
725728
],
726729
)],
727730
);
731+
}
728732

733+
#[test]
734+
fn test_breaking_arabic() {
729735
let sample = "المادة 1 يولد جميع الناس أحرارًا متساوين في الكرامة والحقوق. وقد وهبوا عقلاً وضميرًا وعليهم أن يعامل بعضهم بعضًا بروح الإخاء.";
730736
test_breaking(
731737
sample,
@@ -753,9 +759,6 @@ mod test {
753759
);
754760
}
755761

756-
// TODO: find a way to enable this test which is permissive of font
757-
// variability (namely whether or not font fallbacks cause extra breaks).
758-
#[cfg(false)]
759762
#[test]
760763
fn test_breaking_complex_arabic() {
761764
// Another, more complex, Arabic sample. Source: https://r12a.github.io/scripts/tutorial/summaries/arabic
@@ -786,20 +789,11 @@ mod test {
786789
&[55],
787790
),
788791
(
789-
58..196,
792+
58..197,
790793
RunSpecial::NoBreak,
791794
Level::rtl(),
792795
Script::Arabic,
793-
&[62, 69, 82, 91, 107, 118, 127, 138, 153, 166, 179],
794-
),
795-
(
796-
// Note that this break occurs due to font fallback where
797-
// the Arabic font doesn't contain a (round) bracket.
798-
196..197,
799-
RunSpecial::NoBreak,
800-
Level::rtl(),
801-
Script::Arabic,
802-
&[],
796+
&[62, 69, 82, 91, 107, 118, 127, 138, 153, 166, 179, 196],
803797
),
804798
(
805799
197..215,
@@ -809,16 +803,7 @@ mod test {
809803
&[205],
810804
),
811805
(
812-
// Note that this break occurs due to font fallback where
813-
// the Arabic font doesn't contain a (round) bracket.
814-
215..216,
815-
RunSpecial::NoBreak,
816-
Level::rtl(),
817-
Script::Arabic,
818-
&[],
819-
),
820-
(
821-
216..244,
806+
215..244,
822807
RunSpecial::None,
823808
Level::rtl(),
824809
Script::Arabic,

0 commit comments

Comments
 (0)