Repository: mmcloughlin/avo
Pull request #177 (2021-04-11 06:51:03)

attr: flag test methods

codecov-io: # [Codecov](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=h1) Report
> Merging [#177](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=desc) (a2a8c83) into [master](https://codecov.io/gh/mmcloughlin/avo/commit/c5faaae5837f9e1591dbf278f2a513912bed939f?el=desc) (c5faaae) will **decrease** coverage by `0.02%`.
> The diff coverage is `0.00%`.

> :exclamation: Current head a2a8c83 differs from pull request most recent head 21f011b. Consider uploading reports for the commit 21f011b to get more accurate results
[![Impacted file tree graph](https://codecov.io/gh/mmcloughlin/avo/pull/177/graphs/tree.svg?width=650&height=150&src=pr&token=DaOLKxzdQS)](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #177      +/-   ##
==========================================
- Coverage   79.47%   79.44%   -0.03%     
==========================================
  Files          55       56       +1     
  Lines       30884    30895      +11     
==========================================
  Hits        24546    24546              
- Misses       6192     6203      +11     
  Partials      146      146              
```

| Flag | Coverage Δ | |
|---|---|---|
| integration | `7.37% <0.00%> (-0.01%)` | :arrow_down: |
| unittests | `77.56% <0.00%> (-0.03%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [attr/ztextflag.go](https://codecov.io/gh/mmcloughlin/avo/pull/177/diff?src=pr&el=tree#diff-YXR0ci96dGV4dGZsYWcuZ28=) | `0.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=footer). Last update [c5faaae...21f011b](https://codecov.io/gh/mmcloughlin/avo/pull/177?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/attr/make_textflag.go b/attr/make_textflag.go
index 83d7220..88f1d77 100644
--- a/attr/make_textflag.go
+++ b/attr/make_textflag.go
@@ -197,4 +197,10 @@ func PrintFlagAttributes(w io.Writer, fs []Flag) {
 		fmt.Fprintf(w, "\t%s: %q,\n", f.Name, f.Name)
 	}
 	fmt.Fprintf(w, "}\n")
+
+	// Flag test methods.
+	for _, f := range fs {
+		fmt.Fprintf(w, "\n// %s reports whether the %s flag is set.\n", f.Name, f.Name)
+		fmt.Fprintf(w, "func (a Attribute) %s() bool { return (a & %s) != 0 }\n", f.Name, f.Name)
+	}
 }
diff --git a/attr/ztextflag.go b/attr/ztextflag.go
index 9330a19..4c7163a 100644
--- a/attr/ztextflag.go
+++ b/attr/ztextflag.go
@@ -55,3 +55,36 @@ var attrname = map[Attribute]string{
 	REFLECTMETHOD: "REFLECTMETHOD",
 	TOPFRAME:      "TOPFRAME",
 }
+
+// NOPROF reports whether the NOPROF flag is set.
+func (a Attribute) NOPROF() bool { return (a & NOPROF) != 0 }
+
+// DUPOK reports whether the DUPOK flag is set.
+func (a Attribute) DUPOK() bool { return (a & DUPOK) != 0 }
+
+// NOSPLIT reports whether the NOSPLIT flag is set.
+func (a Attribute) NOSPLIT() bool { return (a & NOSPLIT) != 0 }
+
+// RODATA reports whether the RODATA flag is set.
+func (a Attribute) RODATA() bool { return (a & RODATA) != 0 }
+
+// NOPTR reports whether the NOPTR flag is set.
+func (a Attribute) NOPTR() bool { return (a & NOPTR) != 0 }
+
+// WRAPPER reports whether the WRAPPER flag is set.
+func (a Attribute) WRAPPER() bool { return (a & WRAPPER) != 0 }
+
+// NEEDCTXT reports whether the NEEDCTXT flag is set.
+func (a Attribute) NEEDCTXT() bool { return (a & NEEDCTXT) != 0 }
+
+// TLSBSS reports whether the TLSBSS flag is set.
+func (a Attribute) TLSBSS() bool { return (a & TLSBSS) != 0 }
+
+// NOFRAME reports whether the NOFRAME flag is set.
+func (a Attribute) NOFRAME() bool { return (a & NOFRAME) != 0 }
+
+// REFLECTMETHOD reports whether the REFLECTMETHOD flag is set.
+func (a Attribute) REFLECTMETHOD() bool { return (a & REFLECTMETHOD) != 0 }
+
+// TOPFRAME reports whether the TOPFRAME flag is set.
+func (a Attribute) TOPFRAME() bool { return (a & TOPFRAME) != 0 }


Test patch:
diff --git a/attr/attr_test.go b/attr/attr_test.go
index caeded9..13121b3 100644
--- a/attr/attr_test.go
+++ b/attr/attr_test.go
@@ -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)
+		}
+	}
+}