Skip to content
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

Added XML support for NullDecimal #192

Merged
merged 1 commit into from Feb 18, 2021

Conversation

bharath23
Copy link
Contributor

  • Added UnmarshalText and MarshalText support for NullDecimal
  • Add tests for XML operations on NullDecimal

Comment on lines +1315 to +1393
if str == "" {
d.Valid = false
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this case necessary? Wouldn't the below if statement be enough?

Copy link
Contributor Author

@bharath23 bharath23 Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decimal.Unmarshal returns error. For NullDecimal it is not an error as NullDecimal.Valid will be set to false.

https://play.golang.org/p/YJWM2pykj75

Also, we cannot assume that if its an errors its null. There could be other reasons why Decimal.Unmarshal could fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is similar to how NullDecimal.UnmarshalJSON works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it :3 Thanks!
I will get back to your PR tomorrow if you don't mind :) I would love to check the unit test too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any updates?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so sorry :<. I completely forgot about your pull request Bharath. I'm leaving in about an hour for holiday dinner with family, but I will check those unit test tomorrow.
I'm adding this to my TODO list, so I will not forget about it :D

Copy link
Member

@mwoss mwoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall look good :3 just few comments

func (d *NullDecimal) UnmarshalText(text []byte) error {
str := string(text)

if str == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is basically the case for empty XMLs and XMLs withotu the body e.g <test></test>?
Could you add a short comment that would denote that, so it will be easier to refactor in the future if needed? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

decimal.go Outdated
Comment on lines 1319 to 1396
if err := d.Decimal.UnmarshalText(text); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we explicitly set here d.Valid = false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are returning error. d is invalid and shouldn't be used by caller. We can set it to false, I dont have strong opinion about it.

@@ -766,6 +766,75 @@ func TestBadXML(t *testing.T) {
}
}

func TestNullDecimalXML(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you've based those unit test on NullDecimal JSON tests and there is 3 uni test combined into one. It's not a bad thing in my opinion, but could you separate them by adding a one-liner comment before each section? So next contributors would know what test cases are covered here :3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments.

* Added UnmarshalText and MarshalText support for NullDecimal
* Add tests for XML operations on NullDecimal
Copy link
Member

@mwoss mwoss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think I've missed an email notification with your PR update.
Looks good IMO. :3

@mwoss mwoss merged commit 9328d16 into shopspring:master Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants