The current test code in weather_forecast_test.go fails to correctly parse inline comments for the CurrentCondition and CurrentLocation variables. It wrongly asserts that the comments are empty and therefore fails the tests. Example:
var (
CurrentCondition string // CurrentCondition describes the current weather condition.
CurrentLocation string // CurrentLocation is the location where the forecast is being made.
)
So trailing comments may be “free-floating” and not directly associated with the neighboring variable declaration node but instead indicated positionally, so will require more complicated parsing to handle correctly.
Maybe this test is being too ambitious given the current state of the language reflection tooling.
After inspecting the Go source code and tests, it seems that it’s not a bug, just a confusing inconsistency in the API. A CommentGroup.Text has the comment markers removed while each individual Comment.Text does not.
I think the exercise should give an error when making inline comments.
The reason for this is that tools like go doc work best when the comment precedes the declaration and has no lines between them:
The convention is simple: to document a type, variable, constant, function, or even a package, write a regular comment directly preceding its declaration, with no intervening blank line.