github.com/Schaudge/hts@v0.0.0-20240223063651-737b4d69d68c/sam/auxtags_test.go (about)

     1  package sam
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/grailbio/testutil/assert"
     7  )
     8  
     9  var (
    10  	diTag = Tag{'D', 'I'}
    11  	dsTag = Tag{'D', 'S'}
    12  )
    13  
    14  func TestGetUnique(t *testing.T) {
    15  	r := GetFromFreePool()
    16  	// Case 1: No Aux fields.  Return should be nil, nil.
    17  	r.AuxFields = AuxFields{}
    18  	tag, err := r.AuxFields.GetUnique(diTag)
    19  	assert.NoError(t, err)
    20  	assert.Nil(t, tag)
    21  
    22  	// Case 2: Tag appears once.
    23  	var newAux Aux
    24  	newAux, err = NewAux(diTag, "1")
    25  	assert.NoError(t, err)
    26  	r.AuxFields = append(r.AuxFields, newAux)
    27  	newAux, err = NewAux(dsTag, 2)
    28  	assert.NoError(t, err)
    29  	r.AuxFields = append(r.AuxFields, newAux)
    30  
    31  	tag, err = r.AuxFields.GetUnique(diTag)
    32  	assert.NoError(t, err)
    33  	assert.NotNil(t, tag)
    34  
    35  	// Case 3: Tag appears multiple times.
    36  	newAux, err = NewAux(diTag, "3")
    37  	assert.NoError(t, err)
    38  	r.AuxFields = append(r.AuxFields, newAux)
    39  	newAux, err = NewAux(dsTag, 4)
    40  	assert.NoError(t, err)
    41  	r.AuxFields = append(r.AuxFields, newAux)
    42  
    43  	tag, err = r.AuxFields.GetUnique(diTag)
    44  	assert.NotNil(t, err)
    45  }