Lark.js icon indicating copy to clipboard operation
Lark.js copied to clipboard

`isupper` bug

Open thekevinscott opened this issue 1 year ago • 2 comments

The javascript definition of isupper is defined here:

function isupper(a) {
  return /^[A-Z_$]*$/.test(a);
}

This is slightly different from the Python implementation, with respect to digits:

'__IGNORE_0'.isupper()
# True
/^[A-Z_$]*$/.test('__IGNORE_0');
// false

The regex should be updated to /^[A-Z0-9_$]*$/

thekevinscott avatar Feb 20 '24 14:02 thekevinscott

Okay, thanks for reporting it!

It still isn't right, because in Python '0'.isupper() == False. But you're right that it needs fixing.

erezsh avatar Feb 20 '24 17:02 erezsh

Ah, very true. Good catch!

https://docs.python.org/3/library/stdtypes.html#str.isupper

Return True if all cased characters [4] in the string are uppercase and there is at least one cased character, False otherwise.

It sounds like the main edge case is that there must be one cased character.

I opened a PR here that adds test cases that I think covers all the edge cases: https://github.com/lark-parser/Lark.js/pull/45

thekevinscott avatar Feb 23 '24 11:02 thekevinscott