Add missing overloads for String#byte_slice#12809
Add missing overloads for String#byte_slice#12809straight-shoota merged 5 commits intocrystal-lang:masterfrom
String#byte_slice#12809Conversation
| @@ -1173,9 +1173,9 @@ class String | |||
| # "hello".byte_slice(-2, 5) # => "he" | |||
There was a problem hiding this comment.
This and the two calls above actually return "lo". I don't know why these aren't caught by the routine "fix examples in the docs" PRs
(those lines are due to #8447 so they are fairly old)
There was a problem hiding this comment.
The basic premise is that my checkers cannot handle all EXAMPLES.
EXAMPLES that cannot be handled are managed as an "exclusion list" and excluded from testing.
In this case, the entire code block is excluded because the incorrect comment syntax would interfere with the automatic generation of tests.
"¥hello".byte_slice(0, 1) # => "\C2" (invalid UTF-8 character)
^^^^^^^^^^^^^^^^^^^^^^^^^The following code is generated and fails.
$ cd tmp/string/working && LC_ALL=C /v/crystal/bin/crystal run -D preview_overflow ../all_spec.cr 2>&1
Using compiled compiler at /v/crystal/.build/crystal
In /v/tmp/string/all_spec.cr:509:46
509 | �[0m�[1m( "¥hello".byte_slice(0, 1) ).should eq( "�" (invalid UTF-8 character) )
^
Error: expecting token ')', not '('I understand. So how many examples of such exclusions do you have?
1979 test
1341 success 43 pending 3 general 147 pseudo 71 macro 9 wrong 44 random 321 failure
There was a problem hiding this comment.
Perhaps we could fix a format for such comments on the output value.
My initial idea for this would be to just append another comment:
"¥hello".byte_slice(0, 1) # => "\C2" # invalid UTF-8 characterThis should be fairly readable, unambiguous and easy to parse.
There was a problem hiding this comment.
It's good. I think it is the best choice so far. 💯
There was a problem hiding this comment.
@straight-shoota
I would like to inspect the excluded EXAMPLES like this one once again.
There are probably about 300 cases, and it takes about a week.
I smell a 1.7 release, will it be ready in time?
There was a problem hiding this comment.
There should be time. 1.7.0 is scheduled for January 6.
Co-authored-by: Quinton Miller <nicetas.c@gmail.com>
|
@HertzDevil Thanks for digging into the examples. I know there were some issues with that and meant to look into using https://github.com/maiha/crystal-examples for checking. But I didn't get anywhere and lost track before publishing the PR. |
String#byte_sliceand#byte_slicehave signatures accepting a start index plus count.String#byte_slicealso has an overload with only a start index.There are no overloads accepting a
Rangeargument, which is typically present in similar methods (most prominentlyIndexable#[]).This patch adds:
String#byte_slice(range : Range)- resolves range indices and delegates to#byte_slice(start : Int, count : Int)String#byte_slice?(range : Range)- resolves range indices and delegates to#byte_slice?(start : Int, count : Int)String#byte_slice?(start : Int)- counterpart toString#byte_slice(start : Int)