-
Notifications
You must be signed in to change notification settings - Fork 1
[WIP] Strhelpers #5
Conversation
|
|
||
| func TestAfter(t *testing.T) { | ||
|
|
||
| assert.Equal(t, "nah", After("hannah", "han")) |
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.
I start each test with empty values as parameters. As an example:
assert.Equal(t, "", After("", ""))
assert.Equal(t, "", After("hannah", ""))
assert.Equal(t, "", After("", "hannah"))
(I'm not sure if the result is what it should be.)
Would you like to add that to this test and check it in the other tests?
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.
Good idea.
|
This looks good and is very useful! 🥇 |
Codecov Report
@@ Coverage Diff @@
## main #5 +/- ##
=======================================
Coverage ? 77.52%
=======================================
Files ? 15
Lines ? 574
Branches ? 0
=======================================
Hits ? 445
Misses ? 108
Partials ? 21 Continue to review full report at Codecov.
|
|
Great changes! Do you mind merging main into this branch? Then we get a better idea of whether code coverage has improved. |
| } | ||
|
|
||
| func ContainsAllInSlice(haystack string, needle []string) bool { | ||
| func ContainsAllFromSlice(haystack string, needle []string) bool { |
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.
What do you think of the following?
ContainsBySlice()
ContainsAllBySlice()
But it doesn't really matter to me 🤷♂️
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.
Of course. I will change this. I had just worked for some minutes on it and simply pushed the changes. More to come when I have the time to do so.
| } | ||
|
|
||
| // Return the remainder of a string after the first occurrence of a given value. | ||
| func After(subject string, search string) string { |
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.
This can be reduced to
func After(subject string, search string) string {
if len(search) == 0 {
return input
}
results := strings.SplitN(subject, search, 2)
return results[len(results)-1]
}| } | ||
|
|
||
| // Return the remainder of a string after the last occurrence of a given value. | ||
| func AfterLast(subject string, search string) string { |
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.
This code can be reduced to
func AfterLast(subject string, search string) string {
if len(search) == 0 {
return subject
}
position := strings.LastIndex(subject, search)
if position == -1 {
return subject
}
return subject[position+len(search):]
}| } | ||
|
|
||
| // Get the portion of a string before the first occurrence of a given value. | ||
| func Before(subject string, search string) string { |
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.
This code can be reduced to
func Before(subject string, search string) string {
if len(search) == 0 {
return subject
}
position := strings.Index(subject, search)
if position == -1 {
return subject
}
return subject[:position]
}| return result | ||
| } | ||
|
|
||
| func BeforeLast(subject string, search string) string { |
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.
This code can be reduced to
func BeforeLast(subject string, search string) string {
if len(search) == 0 {
return subject
}
position := strings.LastIndex(subject, search)
if position == -1 {
return subject
}
return subject[:position]
}|
@octoper feel free to continue working on this PR. I don't know how you can easily work on this with @Wulfheart. Perhaps can fork Wulfheart:strhelpers and build on it. I think it would be good if this PR is not open for too long. Maybe it would be better if few functions work, we already merge them. |
|
@octoper I can give you write access to repository if you want and we can continue this fork together. |
|
Yeah @Wulfheart if I would love to help! |
|
I hope the invitation has been sent. How can we avoid duplication? How would you like to solve it? How can we coordinate it? |
|
Do you have a Discord account or something else so we can talk there or Twitter maybe? |
|
@octoper @Wulfheart I have given you write access. You should have received an invitation. I will create a branch for the above. |
|
New pull-request: @Wulfheart and @octoper you can develop on branch |
|
@reindert-vetter Thank you! |
This pull request is opened to show a progress of the implementation of some string helpers from Laravel.
This will address confetti-framework/confetti#102