Skip to content

Commit

Permalink
test: add testcases for directives and add comments for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Jan 1, 2024
1 parent 3dbc1ba commit 18ef01c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions analyzer/testdata/src/i/directives.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
package i

func excludedConsumer(e TestExcluded) string {
return e.A
}

func shouldNotFailOnIgnoreDirective() (Test, error) {
// directive on previous line
//exhaustruct:ignore
_ = Test2{}

// directive at the end of the line
_ = Test{} //exhaustruct:ignore

// some style weirdness
_ =
//exhaustruct:ignore
Test3{
B: 0,
}

// directive after the literal
_ = Test{
B: 0,
} //exhaustruct:ignore

//exhaustruct:ignore
return Test{}, nil
}

func shouldNotFailOnIgnoreDirectivePlacedOnEOL() (Test, error) {
return Test{}, nil //exhaustruct:ignore
}
func shouldFailOnExcludedButEnforced() {
// directive on previous line associated with different ast leaf
//exhaustruct:enforce
_ = excludedConsumer(TestExcluded{B: 0}) // want "i.TestExcluded is missing field A"

func shouldNotPassExcludedButEnforced() {
// initially excluded, but enforced
//exhaustruct:enforce
_ = TestExcluded{} // want "i.TestExcluded is missing fields A, B"
}

func shouldFailOnMisappliedDirectives() {
// wrong directive name
//exhaustive:enforce
_ = TestExcluded{B: 0}
}

0 comments on commit 18ef01c

Please sign in to comment.