File: 2_fixture_validator.go

package info (click to toggle)
golang-github-smartystreets-gunit 1.2.0%2Bgit20180314.6f0d627-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 200 kB
  • sloc: makefile: 5
file content (31 lines) | stat: -rwxr-xr-x 698 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package scan

import "go/ast"

type fixtureValidator struct {
	Parent      *fixtureCollector
	FixtureName string
}

func (this *fixtureValidator) Visit(node ast.Node) ast.Visitor {
	// We start at a TypeSpec and look for an embedded pointer field: `*gunit.Fixture`.
	field, isField := node.(*ast.Field)
	if !isField {
		return this
	}
	pointer, isPointer := field.Type.(*ast.StarExpr)
	if !isPointer {
		return this
	}

	selector, isSelector := pointer.X.(*ast.SelectorExpr)
	if !isSelector {
		return this
	}
	gunit, isGunit := selector.X.(*ast.Ident)
	if selector.Sel.Name != "Fixture" || !isGunit || gunit.Name != "gunit" {
		return this
	}
	this.Parent.Validate(this.FixtureName)
	return nil
}