mirror of
https://github.com/vlang/v.git
synced 2025-09-19 12:27:02 -04:00
builtin: fix empty string lower / upper assert (#21358)
This commit is contained in:
parent
712a9125bf
commit
5329a0a671
@ -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 {
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user