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
This commit is contained in:
parent
1a9b301f52
commit
f22ac32c2c
@ -157,18 +157,16 @@ public final class SpannedSubject extends Subject {
|
||||
return ALREADY_FAILED_WITH_FLAGS;
|
||||
}
|
||||
|
||||
if (styles.size() == 1 && styles.contains(Typeface.BOLD_ITALIC)
|
||||
|| styles.size() == 2
|
||||
&& styles.contains(Typeface.BOLD)
|
||||
&& styles.contains(Typeface.ITALIC)) {
|
||||
if (styles.contains(Typeface.BOLD_ITALIC)
|
||||
|| (styles.contains(Typeface.BOLD) && styles.contains(Typeface.ITALIC))) {
|
||||
return check("StyleSpan (start=%s,end=%s)", start, end).about(spanFlags()).that(allFlags);
|
||||
}
|
||||
failWithoutActual(
|
||||
simpleFact(
|
||||
String.format("No matching StyleSpans found between start=%s,end=%s", start, end)),
|
||||
fact("in text", actual.toString()),
|
||||
fact("expected either styles", Collections.singletonList(Typeface.BOLD_ITALIC)),
|
||||
fact("or styles", Arrays.asList(Typeface.BOLD, Typeface.ITALIC)),
|
||||
fact("expected to contain either", Collections.singletonList(Typeface.BOLD_ITALIC)),
|
||||
fact("or both", Arrays.asList(Typeface.BOLD, Typeface.ITALIC)),
|
||||
fact("but found styles", styles));
|
||||
return ALREADY_FAILED_WITH_FLAGS;
|
||||
}
|
||||
|
@ -151,6 +151,21 @@ public class SpannedSubjectTest {
|
||||
.withFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
@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() {
|
||||
SpannableString spannable = SpannableString.valueOf("test with italic section");
|
||||
|
Loading…
x
Reference in New Issue
Block a user