Go language: Using package name inside package scope (for Examples) -
I am currently writing exampleFuncs in my Go Test Script for example:
Now, I get two benefits from this:
- This example is executed when I am running
go test and
This appears in the Godok document under
func GetSymbol
One thing bothers me And I wonder if I should have done anything about it. For the user trying to learn from this example, line
data: = GetSymbol ("AAPL")
should really be
Data: Hello = Hello Gate Simbol ("AAPL")
But since the package is in the same area as a package, I can not use it this way.
So I think the disturbing version of my question will be: Is there a way to allow
package.field notation inside the package?
Thanks
Hello Put it in the package,
hello_test . You have permission for both
Hello and
Hello_Test packages in the same directory, and this allows you to create the way you are suggesting your examples (required) .
Incidentally, this causes you to write for your test cases (at least for this file) only for public APIs. This is often a good thing but if you have to write in personal work , You can split your test into separate files, some in the
Hello package and some
hello_test .
BTW, documentation for this is a little buried in the "Test package" section.
Comments
Post a Comment