summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/core/strs.nim2
-rw-r--r--tests/destructor/tnewruntime_strutils.nim66
2 files changed, 29 insertions, 39 deletions
diff --git a/lib/core/strs.nim b/lib/core/strs.nim
index 49dc59508..b00042dc9 100644
--- a/lib/core/strs.nim
+++ b/lib/core/strs.nim
@@ -86,7 +86,7 @@ proc resize(old: int): int {.inline.} =
   else: result = old * 3 div 2 # for large arrays * 3/2 is better
 
 proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} =
-  if isLiteral(s):
+  if isLiteral(s) and addlen > 0:
     let oldP = s.p
     # can't mutate a literal, so we need a fresh copy here:
     let allocator = getLocalAllocator()
diff --git a/tests/destructor/tnewruntime_strutils.nim b/tests/destructor/tnewruntime_strutils.nim
index 51ace8a42..2ac6b5845 100644
--- a/tests/destructor/tnewruntime_strutils.nim
+++ b/tests/destructor/tnewruntime_strutils.nim
@@ -1,7 +1,6 @@
 discard """
   cmd: '''nim c --newruntime $file'''
-  output: '''136 136'''
-  disabled: "true"
+  output: '''316 316'''
 """
 
 import strutils, os
@@ -135,33 +134,34 @@ proc staticTests =
   doAssert join([1, 2, 3]) == "123"
   doAssert join(@[1, 2, 3], ", ") == "1, 2, 3"
 
-  doAssert """~~!!foo
-~~!!bar
-~~!!baz""".unindent(2, "~~!!") == "foo\nbar\nbaz"
-
-  doAssert """~~!!foo
-~~!!bar
-~~!!baz""".unindent(2, "~~!!aa") == "~~!!foo\n~~!!bar\n~~!!baz"
-  doAssert """~~foo
-~~  bar
-~~  baz""".unindent(4, "~") == "foo\n  bar\n  baz"
-  doAssert """foo
-bar
-  baz
-""".unindent(4) == "foo\nbar\nbaz\n"
-  doAssert """foo
+  when false:
+    doAssert """~~!!foo
+  ~~!!bar
+  ~~!!baz""".unindent(2, "~~!!") == "foo\nbar\nbaz"
+
+    doAssert """~~!!foo
+  ~~!!bar
+  ~~!!baz""".unindent(2, "~~!!aa") == "~~!!foo\n~~!!bar\n~~!!baz"
+    doAssert """~~foo
+  ~~  bar
+  ~~  baz""".unindent(4, "~") == "foo\n  bar\n  baz"
+    doAssert """foo
   bar
-  baz
-""".unindent(2) == "foo\n  bar\n  baz\n"
-  doAssert """foo
-  bar
-  baz
-""".unindent(100) == "foo\nbar\nbaz\n"
-
-  doAssert """foo
-  foo
-  bar
-""".unindent() == "foo\nfoo\nbar\n"
+    baz
+  """.unindent(4) == "foo\nbar\nbaz\n"
+    doAssert """foo
+    bar
+    baz
+  """.unindent(2) == "foo\n  bar\n  baz\n"
+    doAssert """foo
+    bar
+    baz
+  """.unindent(100) == "foo\nbar\nbaz\n"
+
+    doAssert """foo
+    foo
+    bar
+  """.unindent() == "foo\nfoo\nbar\n"
 
   let s = " this is an example  "
   let s2 = ":this;is;an:example;;"
@@ -178,16 +178,6 @@ bar
   doAssert s.splitWhitespace(maxsplit=3) == @["this", "is", "an", "example  "]
   doAssert s.splitWhitespace(maxsplit=4) == @["this", "is", "an", "example"]
 
-  block: # startsWith / endsWith char tests
-    var s = "abcdef"
-    doAssert s.startsWith('a')
-    doAssert s.startsWith('b') == false
-    doAssert s.endsWith('f')
-    doAssert s.endsWith('a') == false
-    doAssert s.endsWith('\0') == false
-
-  #echo("strutils tests passed")
-
 nonStaticTests()
 staticTests()