@Test
void testSingle() {

    final RefParser refParser = new RefParser();
    List<RefFactory> sections = null;
    StoreRefFactory refDesc = null;
    MatchIndex matchIndex = null;
    // Try null.
    sections = refParser.parse(null);
    assertThat(sections.size()).isEqualTo(0);
    // Try empty string.
    sections = refParser.parse("");
    assertThat(sections.size()).isEqualTo(0);
    // Try remote ref.
    sections = refParser.parse("$heading$");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isEqualTo("heading");
    assertThat(refDesc.getRefGroup()).isEqualTo(0);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex).isNull();
    // Try group.
    sections = refParser.parse("$");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isNull();
    assertThat(refDesc.getRefGroup()).isEqualTo(0);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex).isNull();
    // Try numbered group.
    sections = refParser.parse("$6");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isNull();
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex).isNull();
    // Try numbered group with array.
    sections = refParser.parse("$6[2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isNull();
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(false);
    assertThat(matchIndex.getIndex()).isEqualTo(2);
    // Try numbered group with array with positive offset.
    sections = refParser.parse("$6[+2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isNull();
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(true);
    assertThat(matchIndex.getIndex()).isEqualTo(2);
    // Try numbered group with array with negative offset.
    sections = refParser.parse("$6[-2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isNull();
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(true);
    assertThat(matchIndex.getIndex()).isEqualTo(-2);
    // Try remote ref and numbered group.
    sections = refParser.parse("$heading$6");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isEqualTo("heading");
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex).isNull();
    // Try remote ref and numbered group and array.
    sections = refParser.parse("$heading$6[2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isEqualTo("heading");
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(false);
    assertThat(matchIndex.getIndex()).isEqualTo(2);
    // Try remote ref and numbered group and array with positive offset.
    sections = refParser.parse("$heading$6[+2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isEqualTo("heading");
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(true);
    assertThat(matchIndex.getIndex()).isEqualTo(2);
    // Try remote ref and numbered group and array with negative offset.
    sections = refParser.parse("$heading$6[-2]");
    assertThat(sections.size()).isEqualTo(1);
    refDesc = (StoreRefFactory) sections.get(0);
    assertThat(refDesc.getRefId()).isEqualTo("heading");
    assertThat(refDesc.getRefGroup()).isEqualTo(6);
    matchIndex = refDesc.getMatchIndex();
    assertThat(matchIndex.isOffset()).isEqualTo(true);
    assertThat(matchIndex.getIndex()).isEqualTo(-2);
}