dmarkham / enumer

A Go tool to auto generate methods for your enums
Other
411 stars 63 forks source link

Fixed: Error when transformer emptied the values #35

Closed xescugc closed 4 years ago

xescugc commented 4 years ago

I've added the test to the linecomment on the golden_test.go which fixes #27 and closes #34

And added the logic to name it fail when generating the code with the transformers. There is no way to test this now as nothing returns error and it has to "fail" to actually output.

I tested it by adding another parameter to the runGoldenTest which was the transformer and used instead of the noop and so I wrote a test and see that it failed with snake transformer and code like:

const (
    Common    DeltaType = iota + 1 //
    LeftOnly                       // -
    RightOnly                      // +
    Unknown                        // ?
)

And the error was

2020/06/08 21:17:50 transformation of "-" (LeftOnly) got an empty result

I meant to allow // as an option so it'll only fail if the actual linecomment was defined with a value (so empty values are allowed).

Another solution that I thought while implementing was to, instead of FAIL, use the previous value (before the transformation) but that would still have had an incorrect behavior.

If there is a way to test that let me know and I'll write the test, for what I've seen the endtoend_test.go is also not possible to test it.

codecov-commenter commented 4 years ago

Codecov Report

Merging #35 into master will increase coverage by 0.00%. The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #35   +/-   ##
=======================================
  Coverage   66.14%   66.15%           
=======================================
  Files           3        3           
  Lines         449      452    +3     
=======================================
+ Hits          297      299    +2     
- Misses        140      142    +2     
+ Partials       12       11    -1     
Impacted Files Coverage Δ
stringer.go 61.26% <0.00%> (+0.04%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 9741c5a...cb6196d. Read the comment docs.

dmarkham commented 4 years ago

This change looks great. I'm going to merge this in, I wonder how many people were using a transformer to try and get a empty value, it sounds little crazy. At least anyone that is hit by this will know there is a issue and can quickly downgrade and report a the issue