Skip to content

Commit

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

Fixes nim-lang#19067

* Add tests for nimIdentNormalize
  • Loading branch information
EliteTK authored and PMunch committed Mar 28, 2022
1 parent 830f06d commit 23ad057
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 @@ -281,8 +281,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 23ad057

Please sign in to comment.