@Test
public void testParseMalformedNestedElements() throws Exception {

  Spanned text = parseCueText("<b><u>An unclosed u tag with <i>italic</u> inside</i></b>");
  assertThat(text.toString()).isEqualTo("An unclosed u tag with italic inside");
  UnderlineSpan[] underlineSpans = getSpans(text, UnderlineSpan.class);
  StyleSpan[] styleSpans = getSpans(text, StyleSpan.class);
  assertThat(underlineSpans).hasLength(1);
  assertThat(styleSpans).hasLength(2);
  // all tags applied until matching start tag found
  assertThat(text.getSpanStart(underlineSpans[0])).isEqualTo(0);
  assertThat(text.getSpanEnd(underlineSpans[0])).isEqualTo(29);
  if (styleSpans[0].getStyle() == Typeface.BOLD) {
    assertThat(text.getSpanStart(styleSpans[0])).isEqualTo(0);
    assertThat(text.getSpanStart(styleSpans[1])).isEqualTo(23);
    assertThat(text.getSpanEnd(styleSpans[1])).isEqualTo(29);
    assertThat(text.getSpanEnd(styleSpans[0])).isEqualTo(36);
  } else {
    assertThat(text.getSpanStart(styleSpans[1])).isEqualTo(0);
    assertThat(text.getSpanStart(styleSpans[0])).isEqualTo(23);
    assertThat(text.getSpanEnd(styleSpans[0])).isEqualTo(29);
    assertThat(text.getSpanEnd(styleSpans[1])).isEqualTo(36);
  }
}