// TestResolution checks that identifiers are resolved to the declarations // annotated in the source, by comparing the positions of the resulting // Ident.Obj.Decl to positions marked in the source via special comments. // // In the test source, any comment prefixed with '=' or '@' (or both) marks the // previous token position as the declaration ('=') or a use ('@') of an // identifier. The text following '=' and '@' in the comment string is the // label to use for the location. Declaration labels must be unique within the // file, and use labels must refer to an existing declaration label. It's OK // for a comment to denote both the declaration and use of a label (e.g. // '=@foo'). Leading and trailing whitespace is ignored. Any comment not // beginning with '=' or '@' is ignored. func TestResolution(t *testing.T) { … } // declsFromParser walks the file and collects the map associating an // identifier position with its declaration position. func declsFromParser(file *ast.File) map[token.Pos]token.Pos { … } // declsFromComments looks at comments annotating uses and declarations, and // maps each identifier use to its corresponding declaration. See the // description of these annotations in the documentation for TestResolution. func declsFromComments(handle *token.File, src []byte) map[token.Pos]token.Pos { … } // positionMarkers extracts named positions from the source denoted by comments // prefixed with '=' (declarations) and '@' (uses): for example '@foo' or // '=@bar'. It returns a map of name->position for declarations, and // name->position(s) for uses. func positionMarkers(handle *token.File, src []byte) (decls map[string]token.Pos, uses map[string][]token.Pos) { … } func annotatedObj(lit string) (name string, decl, use bool) { … }