mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
2 changed files with 19 additions and 6 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,21 @@ public class SpannedSubjectTest {
|
||||||
.withFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
.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
|
@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");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue