| 1 | package attr |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestAttributeAsm(t *testing.T) { |
| 6 | cases := []struct { |
| 7 | Attribute Attribute |
| 8 | Expect string |
| 9 | }{ |
| 10 | {0, "0"}, |
| 11 | {32768, "32768"}, |
| 12 | {1, "NOPROF"}, |
| 13 | {DUPOK, "DUPOK"}, |
| 14 | {RODATA | NOSPLIT, "NOSPLIT|RODATA"}, |
| 15 | {WRAPPER | 16384 | NOPTR, "NOPTR|WRAPPER|16384"}, |
| 16 | {NEEDCTXT + NOFRAME + TLSBSS, "NEEDCTXT|TLSBSS|NOFRAME"}, |
| 17 | {REFLECTMETHOD, "REFLECTMETHOD"}, |
| 18 | {TOPFRAME, "TOPFRAME"}, |
| 19 | } |
| 20 | for _, c := range cases { |
| 21 | got := c.Attribute.Asm() |
| 22 | if got != c.Expect { |
| 23 | t.Errorf("Attribute(%d).Asm() = %#v; expect %#v", c.Attribute, got, c.Expect) |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func TestAttributeContainsTextFlags(t *testing.T) { |
| 29 | cases := []struct { |
| 30 | Attribute Attribute |
| 31 | Expect bool |
| 32 | }{ |
| 33 | {0, false}, |
| 34 | {32768, false}, |
| 35 | {1, true}, |
| 36 | {DUPOK, true}, |
| 37 | {WRAPPER | 16384 | NOPTR, true}, |
| 38 | } |
| 39 | for _, c := range cases { |
| 40 | if c.Attribute.ContainsTextFlags() != c.Expect { |
| 41 | t.Errorf("%s: ContainsTextFlags() expected %#v", c.Attribute.Asm(), c.Expect) |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | func TestAttributeTestMethods(t *testing.T) { |
| 47 | cases := []struct { |
| 48 | Attribute Attribute |
| 49 | Predicate func(Attribute) bool |
| 50 | Expect bool |
| 51 | }{ |
| 52 | // Confirm logic works as expected. |
| 53 | {DUPOK | NOSPLIT, Attribute.DUPOK, true}, |
| 54 | {DUPOK | NOSPLIT, Attribute.NOSPLIT, true}, |
| 55 | {DUPOK | NOSPLIT, Attribute.NOFRAME, false}, |
| 56 | |
| 57 | // Basic test for every method. |
| 58 | {NOPROF, Attribute.NOPROF, true}, |
| 59 | {DUPOK, Attribute.DUPOK, true}, |
| 60 | {NOSPLIT, Attribute.NOSPLIT, true}, |
| 61 | {RODATA, Attribute.RODATA, true}, |
| 62 | {NOPTR, Attribute.NOPTR, true}, |
| 63 | {WRAPPER, Attribute.WRAPPER, true}, |
| 64 | {NEEDCTXT, Attribute.NEEDCTXT, true}, |
| 65 | {TLSBSS, Attribute.TLSBSS, true}, |
| 66 | {NOFRAME, Attribute.NOFRAME, true}, |
| 67 | {REFLECTMETHOD, Attribute.REFLECTMETHOD, true}, |
| 68 | {TOPFRAME, Attribute.TOPFRAME, true}, |
| 69 | } |
| 70 | for _, c := range cases { |
| 71 | if c.Predicate(c.Attribute) != c.Expect { |
| 72 | t.Errorf("%s: expected %#v", c.Attribute.Asm(), c.Expect) |
| 73 | } |
| 74 | } |
| 75 | } |