-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor formatValue #202
Refactor formatValue #202
Conversation
Add unit test to cover formatFloat, formatRange, and formatTyped.
hi @gavv , I've added unit test to guard from potential breaking when refactoring the would you mind to take a look? thanks |
Nice! Tests look good, but I thought you were going to create tests based on FormatData instead of of format template? My understanding of the discussion was that template-based tests will be e2e tests covered by #165. |
i see, sry i thought it would be:
ok, will adjust accordingly, so that:
|
Update unit test to assert buildFormatData.
updated
|
@gavv hi, may i know what is the intention of i think it is a bit vague when we see the existing func formatFloat(value interface{}) string {
switch value.(type) {
case float32, float64:
return fmt.Sprintf("%f", value)
}
if isNumber(value) {
return fmt.Sprintf("%v", value)
}
return formatValue(value)
}
|
@gavv and maybe about is it safe for me to assume in Line 401 in 4e92716
that this part
has the same intention as Line 420 in 4e92716
|
Intention was to use %f for floats and %v for other numbers (i.e. integers). |
IIRC they're different. formatString is for printing bare strings. If value is formatValue is for printer arbitrary objects. It prints most values as JSON, with a few exceptions. If value is |
Note that when you pass a Maybe it makes sens to rename formatString to formatBareString (or formatBareStringOrValue) to make this detail clearer. |
We could also rename formatTyped to formatValueWithType. |
@gavv ok thanks for the feedbacks will revisit this pr either this weekend/next week sry for late responses |
Great, thanks! |
…o 190-enable-scientific-formatter
In addition, we also rename formatString to formatBareString.
Refactor formatValue to handle number types (e.g. int, float32, and float64). Deprecate formatFloat. Refactor formatRange and formatTyped to use formatValue for number types.
@gavv Hi, this MR is now ready for review.
However, I haven't done those renaming changes. I think the
I also haven't done this change because I think it shows that I think, they are different because At the end, discussion is very welcome. We can do the changes here, or it could also be in another MR. |
Btw, the e2e test will be done in another MR, can also have different issue for that. I think, we can focus on the unit tests first + impl of |
Makes sense. Let's keep it as is, then.
Agree. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for update! A few more comments.
Refactor TestFormatDataFailureActual to use table driven approach.
Update unit test to use table driven approach.
@gavv ready for review |
Awesome, thanks! |
Issue: (part of) #190
Refactoring before proceeding to introduce
DefaultFormatter.DisableScientific
as mentioned in #190 (comment).Refactoring (more detail #190 (comment)):
formatFloat
. Replace withformatValue
formatTyped
to useformatValue
formatRange
to useformatValue
Tasks:
PR will be draft, unless all tasks are checkedPR is now ready