Skip to content

Conversation

@roshats
Copy link

@roshats roshats commented May 27, 2025

I've noticed that support for uint was missing, so I've added it in this pull request. Let me know if any changes are needed.

Copy link

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

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

LGTM 👍

It's a legitimate use case.

One minor remark anyway.

Jane,2023-06-15T09:30:00Z,false,75.2,100,2.718,prod;live`
csvData := `name,created_at,active,score,count,rate,tags,rank
John,2023-01-02T15:04:05Z,true,98.6,42,3.14,test;debug,1
Jane,2023-06-15T09:30:00Z,false,75.2,100,2.718,prod;live,42`

Choose a reason for hiding this comment

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

Could you add a test about sending a negative number via a CSV into a uint field ?

I feel like it could be useful to validate how the library behaves in such use case.

Also, it would help to avoid regression

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the comment. I've added a test for invalid values.

Comment on lines 208 to 214
if expectedMessage != actualMessage {
t.Errorf("Expected a panic for input '%s' with error message '%s', but got '%s'", input, expectedMessage, actualMessage)
}
}

test(t, "score\nnot-float", `error setting field Score: strconv.ParseFloat: parsing "not-float": invalid syntax`)
test(t, "rank\n-1", `error setting field Rank: strconv.ParseUint: parsing "-1": invalid syntax`)

Choose a reason for hiding this comment

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

Here the test are too dependent from the implementation. You can see the error message is about strconv failing to parse.

I'm doing this comment here, but I mean it's interesting to change the implementation, and so the tests

Choose a reason for hiding this comment

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

Never mind ... The whole lib is like that...
It's out of the scope of this PR

shared_test.go Outdated
Count int `csv:"count"`
Rate float32 `csv:"rate"`
Tags string `csv:"tags"`
Rank uint `csv:"rank"`

Choose a reason for hiding this comment

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

Please use a uint8 so you could also use 1000 as an invalid value, and simulate an issue an int64 might have with a huge number

Copy link
Author

Choose a reason for hiding this comment

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

I've added overflow check for both uint and int.

roshats and others added 2 commits June 8, 2025 13:36
Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
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.

2 participants