markphelps / optional

Optional is a library of optional Go types
https://godoc.org/github.com/markphelps/optional
MIT License
209 stars 19 forks source link

Unit tests #10

Closed mwielbut closed 5 years ago

mwielbut commented 5 years ago

This pull request adds unit test coverage for the string and int types, specifically for the core functionality.

*@markphelps, I considered templating this to make it work for "all" types and get generated like the rest of the code but it's tough to handle all the various type-specific cases or custom-types. I think it's still useful to have some test coverage for common types, as a sanity check, and example code for seeing expected results. Hope you find it useful. We really like the library but we feel safer using it if we add some test coverage.

markphelps commented 5 years ago

@mwielbut thanks for another great PR! I agree it could use some better test coverage. I too struggled with how to best accomplish this because of the reasons you cited. Thats why I decided to just test the code generation with goldenfiles and the like.

But I do think having more 'real tests' would help make others feel better about using this lib like you mentioned. I'm gonna think on how to best generate tests for all types, perhaps by creating some kind of value generators and using your tests as a template? Let me know if you have any thoughts!

Thanks again!