You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All these tests should pass, but this is the output:
β Failed 'π' should be at index 5 of 'πΏABCπc' but it is 7
4 assertions, 1 failures
From this message, it is apparent that the sπ‘ πβ method is returning the index in terms of UTF-8 bytes, not grapheme index. This is inconsistent with the sπ‘ πͺβmethod, which is using grapheme index (as shown in the tests).
This inconsistency makes the sπ‘ πβmethod confusing at best and useless at the worst case when strings are outside of the ASCII range.
Ideally the workaround for this issue would be to first convert the string into a list via sπ‘ πΆβ, then find the index with sπ¨ πβ, but unfortunately that does not exist. I intend to submit a pull request for that method shortly.
Edit: you can't implement πβ on sπ¨πβͺπ since you can't compare two βͺs with π or anything else, and you can't cast the βͺ to protocol π since it's generic π’. Looks like the only way to do this is fix the sπ‘πβ method.
The text was updated successfully, but these errors were encountered:
joeskeen
changed the title
Incorrect or inconsistent behavior with sπ’ πβ method
Incorrect or inconsistent behavior with sπ‘ πβ method
Nov 27, 2022
joeskeen
added a commit
to joeskeen/emojicode
that referenced
this issue
Nov 27, 2022
Consider the following unit tests:
All these tests should pass, but this is the output:
From this message, it is apparent that the sπ‘ πβ method is returning the index in terms of UTF-8 bytes, not grapheme index. This is inconsistent with the sπ‘ πͺβmethod, which is using grapheme index (as shown in the tests).
This inconsistency makes the sπ‘ πβmethod confusing at best and useless at the worst case when strings are outside of the ASCII range.
Ideally the workaround for this issue would be to first convert the string into a list via sπ‘ πΆβ, then find the index with sπ¨ πβ, but unfortunately that does not exist. I intend to submit a pull request for that method shortly.Edit: you can't implement πβ on sπ¨πβͺπ since you can't compare two βͺs with π or anything else, and you can't cast the βͺ to protocol π since it's generic π’. Looks like the only way to do this is fix the sπ‘πβ method.
The text was updated successfully, but these errors were encountered: