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

add str::substring #158

Merged
merged 5 commits into from
Dec 9, 2023
Merged

add str::substring #158

merged 5 commits into from
Dec 9, 2023

Conversation

lovasoa
Copy link
Contributor

@lovasoa lovasoa commented Dec 6, 2023

No description provided.

Copy link
Owner

@ISibboI ISibboI left a comment

Choose a reason for hiding this comment

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

Thanks, this is nice! I made some comments in the changed files, it would be good to fix these before merging.

src/function/builtin.rs Show resolved Hide resolved
src/function/builtin.rs Outdated Show resolved Hide resolved
src/function/builtin.rs Outdated Show resolved Hide resolved
src/function/builtin.rs Outdated Show resolved Hide resolved
@lovasoa
Copy link
Contributor Author

lovasoa commented Dec 7, 2023

@ISibboI , the usize overflow was already handled, but I changed the behavior to raise an error instead of returning an empty string when supplied indices are out of bounds. Let me know if that's ok :)

src/error/mod.rs Outdated Show resolved Hide resolved
assert!(eval("str::substring(\"foobar\", 2, 1)").is_err());
assert!(eval("str::substring(\"foobar\", 99999)").is_err());
assert!(eval("str::substring(\"foobar\", -1)").is_err());
assert!(eval("str::substring(\"foobar\", 0, -1)").is_err());
Copy link
Owner

Choose a reason for hiding this comment

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

I think currently, the function accepts also the case where it gets four or more arguments, and silently drops them. Let's add a test case for that, expecting an error. And then if the function does not return an error in that case, let's make it return one.

Copy link
Owner

@ISibboI ISibboI left a comment

Choose a reason for hiding this comment

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

Thanks for the changes so far! I think this is going nicely. I noticed one more edge case that we overlooked, see the comment.

@ISibboI
Copy link
Owner

ISibboI commented Dec 8, 2023

Also, in case I get to implement #159 before merging this, it may be good to use it as well. But I can also do that.

@ISibboI
Copy link
Owner

ISibboI commented Dec 8, 2023

Yeah, now you can use wrong_function_argument_amount_range instead of wrong_function_argument_amount to report that the new function can handle two or three arguments.

@lovasoa
Copy link
Contributor Author

lovasoa commented Dec 8, 2023

Okay, I'm leaving this in your hands. thanks !

@ISibboI ISibboI merged commit ea4241b into ISibboI:main Dec 9, 2023
13 of 14 checks passed
@lovasoa lovasoa deleted the substring branch December 9, 2023 09:29
@lovasoa
Copy link
Contributor Author

lovasoa commented Dec 9, 2023

Thank you 🙏

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