Commit f22ac32c by ibaker Committed by Oliver Woodman

Relax the check in SpannedSubject.hasBoldItalicSpanBetween

Ultimately we only care if the style is both bold & italic, if some of
those are specified multiple times there's no problem.

PiperOrigin-RevId: 288862235
parent 1a9b301f
...@@ -157,18 +157,16 @@ public final class SpannedSubject extends Subject { ...@@ -157,18 +157,16 @@ public final class SpannedSubject extends Subject {
return ALREADY_FAILED_WITH_FLAGS; return ALREADY_FAILED_WITH_FLAGS;
} }
if (styles.size() == 1 && styles.contains(Typeface.BOLD_ITALIC) if (styles.contains(Typeface.BOLD_ITALIC)
|| styles.size() == 2 || (styles.contains(Typeface.BOLD) && styles.contains(Typeface.ITALIC))) {
&& styles.contains(Typeface.BOLD)
&& styles.contains(Typeface.ITALIC)) {
return check("StyleSpan (start=%s,end=%s)", start, end).about(spanFlags()).that(allFlags); return check("StyleSpan (start=%s,end=%s)", start, end).about(spanFlags()).that(allFlags);
} }
failWithoutActual( failWithoutActual(
simpleFact( simpleFact(
String.format("No matching StyleSpans found between start=%s,end=%s", start, end)), String.format("No matching StyleSpans found between start=%s,end=%s", start, end)),
fact("in text", actual.toString()), fact("in text", actual.toString()),
fact("expected either styles", Collections.singletonList(Typeface.BOLD_ITALIC)), fact("expected to contain either", Collections.singletonList(Typeface.BOLD_ITALIC)),
fact("or styles", Arrays.asList(Typeface.BOLD, Typeface.ITALIC)), fact("or both", Arrays.asList(Typeface.BOLD, Typeface.ITALIC)),
fact("but found styles", styles)); fact("but found styles", styles));
return ALREADY_FAILED_WITH_FLAGS; return ALREADY_FAILED_WITH_FLAGS;
} }
......
...@@ -152,6 +152,21 @@ public class SpannedSubjectTest { ...@@ -152,6 +152,21 @@ public class SpannedSubjectTest {
} }
@Test @Test
// If the span is both BOLD and BOLD_ITALIC then the assertion should still succeed.
public void boldItalicSpan_withRepeatSpans() {
SpannableString spannable = SpannableString.valueOf("test with bold & italic section");
int start = "test with ".length();
int end = start + "bold & italic".length();
spannable.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
spannable.setSpan(
new StyleSpan(Typeface.BOLD_ITALIC), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
assertThat(spannable)
.hasBoldItalicSpanBetween(start, end)
.withFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
@Test
public void boldItalicSpan_onlyItalic() { public void boldItalicSpan_onlyItalic() {
SpannableString spannable = SpannableString.valueOf("test with italic section"); SpannableString spannable = SpannableString.valueOf("test with italic section");
int start = "test with ".length(); int start = "test with ".length();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment