attr: flag test methods (#177)

Adds a method to the Attribute type to test for each flag in the textflag.h header.
This commit is contained in:
Michael McLoughlin
2021-04-11 13:25:13 -07:00
committed by GitHub
parent c5faaae583
commit e9f28cafb8
3 changed files with 70 additions and 0 deletions

View File

@@ -42,3 +42,34 @@ func TestAttributeContainsTextFlags(t *testing.T) {
}
}
}
func TestAttributeTestMethods(t *testing.T) {
cases := []struct {
Attribute Attribute
Predicate func(Attribute) bool
Expect bool
}{
// Confirm logic works as expected.
{DUPOK | NOSPLIT, Attribute.DUPOK, true},
{DUPOK | NOSPLIT, Attribute.NOSPLIT, true},
{DUPOK | NOSPLIT, Attribute.NOFRAME, false},
// Basic test for every method.
{NOPROF, Attribute.NOPROF, true},
{DUPOK, Attribute.DUPOK, true},
{NOSPLIT, Attribute.NOSPLIT, true},
{RODATA, Attribute.RODATA, true},
{NOPTR, Attribute.NOPTR, true},
{WRAPPER, Attribute.WRAPPER, true},
{NEEDCTXT, Attribute.NEEDCTXT, true},
{TLSBSS, Attribute.TLSBSS, true},
{NOFRAME, Attribute.NOFRAME, true},
{REFLECTMETHOD, Attribute.REFLECTMETHOD, true},
{TOPFRAME, Attribute.TOPFRAME, true},
}
for _, c := range cases {
if c.Predicate(c.Attribute) != c.Expect {
t.Errorf("%s: expected %#v", c.Attribute.Asm(), c.Expect)
}
}
}