Skip to content

Commit

Permalink
Fix nimIdentNormalize, fixes #19067 (#19068)
Browse files Browse the repository at this point in the history
* Make nimIdentNormalize return "" when passed ""; fixes #19067

Fixes #19067

* Add tests for nimIdentNormalize

(cherry picked from commit ee703c5)
  • Loading branch information
EliteTK authored and narimiran committed Apr 24, 2023
1 parent b21f81d commit 01dc38a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pure/strutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,9 @@ func nimIdentNormalize*(s: string): string =
runnableExamples:
doAssert nimIdentNormalize("Foo_bar") == "Foobar"
result = newString(s.len)
if s.len > 0:
result[0] = s[0]
if s.len == 0:
return
result[0] = s[0]
var j = 1
for i in 1..len(s) - 1:
if s[i] in {'A'..'Z'}:
Expand Down
7 changes: 7 additions & 0 deletions tests/stdlib/tstrutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,12 @@ bar
doAssert s.endsWith('a') == false
doAssert s.endsWith('\0') == false

block: # nimIdentNormalize
doAssert nimIdentNormalize("") == ""
doAssert nimIdentNormalize("foo") == "foo"
doAssert nimIdentNormalize("foo_bar") == "foobar"
doAssert nimIdentNormalize("Foo_bar") == "Foobar"
doAssert nimIdentNormalize("_Foo_bar") == "_foobar"

static: main()
main()

0 comments on commit 01dc38a

Please sign in to comment.