Пример #1
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})
	}
}