github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/schemadsl/input/sourcepositionmapper_test.go (about)

     1  package input
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestPositionMapping(t *testing.T) {
    11  	mappingText, err := os.ReadFile("tests/mapping.txt")
    12  	if !assert.Nil(t, err, "Got error reading mapping file") {
    13  		return
    14  	}
    15  
    16  	mapper := CreateSourcePositionMapper(mappingText)
    17  
    18  	for runePosition := range mappingText {
    19  		lineNumber, colPosition, err := mapper.RunePositionToLineAndCol(runePosition)
    20  		if !assert.Nil(t, err, "Got error mapping file") {
    21  			return
    22  		}
    23  
    24  		// Check mapping back.
    25  		foundRunePosition, err := mapper.LineAndColToRunePosition(lineNumber, colPosition)
    26  		if !assert.Nil(t, err, "Got error mapping file") {
    27  			return
    28  		}
    29  
    30  		if !assert.Equal(t, runePosition, foundRunePosition, "Rune position mismatch for position %v", runePosition) {
    31  			return
    32  		}
    33  	}
    34  }