builtin: fix empty string lower / upper assert (#21358)

This commit is contained in:
Turiiya 2024-04-26 20:03:44 +02:00 committed by GitHub
parent 712a9125bf
commit 5329a0a671
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -1524,7 +1524,7 @@ pub fn (s string) to_lower() string {
// Example: assert 'hello developer'.is_lower() == true
@[direct_array_access]
pub fn (s string) is_lower() bool {
if s.len > 0 && s[0].is_digit() {
if s == '' || s[0].is_digit() {
return false
}
for i in 0 .. s.len {
@ -1558,7 +1558,7 @@ pub fn (s string) to_upper() string {
// Example: assert 'HELLO V'.is_upper() == true
@[direct_array_access]
pub fn (s string) is_upper() bool {
if s.len > 0 && s[0].is_digit() {
if s == '' || s[0].is_digit() {
return false
}
for i in 0 .. s.len {

View File

@ -1016,6 +1016,8 @@ fn test_lower() {
s = '123'
assert !s.is_lower()
assert s.to_lower() == '123'
s = ''
assert !s.is_lower()
}
fn test_upper() {
@ -1039,6 +1041,8 @@ fn test_upper() {
s = '123'
assert !s.is_upper()
assert s.to_upper() == '123'
s = ''
assert !s.is_upper()
}
fn test_capitalize() {