Exemple #1
0
func TestNoPos(t *testing.T) {
	if token.NoPos.IsValid() {
		t.Errorf("NoPos should not be valid")
	}
	var fset *token.FileSet
	checkPos(t, "nil NoPos", fset.Position(token.NoPos), token.Position{})
	fset = token.NewFileSet()
	checkPos(t, "fset NoPos", fset.Position(token.NoPos), token.Position{})
}
Exemple #2
0
func verifyPositions(t *testing.T, fset *token.FileSet, f *token.File, lines []int) {
	for offs := 0; offs < f.Size(); offs++ {
		p := f.Pos(offs)
		offs2 := f.Offset(p)
		if offs2 != offs {
			t.Errorf("%s, Offset: expected offset %d; got %d", f.Name(), offs, offs2)
		}
		line, col := linecol(lines, offs)
		msg := fmt.Sprintf("%s (offs = %d, p = %d)", f.Name(), offs, p)
		checkPos(t, msg, f.Position(f.Pos(offs)), token.Position{f.Name(), offs, line, col})
		checkPos(t, msg, fset.Position(p), token.Position{f.Name(), offs, line, col})
	}
}