enable most tnewruntime_strutils tests

This commit is contained in:
Araq 2019-04-10 15:49:04 +02:00
commit bc50795d9c
2 changed files with 27 additions and 37 deletions

View file

@ -86,7 +86,7 @@ proc resize(old: int): int {.inline.} =
else: result = old * 3 div 2 # for large arrays * 3/2 is better else: result = old * 3 div 2 # for large arrays * 3/2 is better
proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} = proc prepareAdd(s: var NimStringV2; addlen: int) {.compilerRtl.} =
if isLiteral(s): if isLiteral(s) and addlen > 0:
let oldP = s.p let oldP = s.p
# can't mutate a literal, so we need a fresh copy here: # can't mutate a literal, so we need a fresh copy here:
let allocator = getLocalAllocator() let allocator = getLocalAllocator()

View file

@ -1,7 +1,6 @@
discard """ discard """
cmd: '''nim c --newruntime $file''' cmd: '''nim c --newruntime $file'''
output: '''136 136''' output: '''316 316'''
disabled: "true"
""" """
import strutils, os import strutils, os
@ -135,33 +134,34 @@ proc staticTests =
doAssert join([1, 2, 3]) == "123" doAssert join([1, 2, 3]) == "123"
doAssert join(@[1, 2, 3], ", ") == "1, 2, 3" doAssert join(@[1, 2, 3], ", ") == "1, 2, 3"
doAssert """~~!!foo when false:
~~!!bar doAssert """~~!!foo
~~!!baz""".unindent(2, "~~!!") == "foo\nbar\nbaz" ~~!!bar
~~!!baz""".unindent(2, "~~!!") == "foo\nbar\nbaz"
doAssert """~~!!foo doAssert """~~!!foo
~~!!bar ~~!!bar
~~!!baz""".unindent(2, "~~!!aa") == "~~!!foo\n~~!!bar\n~~!!baz" ~~!!baz""".unindent(2, "~~!!aa") == "~~!!foo\n~~!!bar\n~~!!baz"
doAssert """~~foo doAssert """~~foo
~~ bar ~~ bar
~~ baz""".unindent(4, "~") == "foo\n bar\n baz" ~~ baz""".unindent(4, "~") == "foo\n bar\n baz"
doAssert """foo doAssert """foo
bar
baz
""".unindent(4) == "foo\nbar\nbaz\n"
doAssert """foo
bar bar
baz baz
""".unindent(2) == "foo\n bar\n baz\n" """.unindent(4) == "foo\nbar\nbaz\n"
doAssert """foo doAssert """foo
bar bar
baz baz
""".unindent(100) == "foo\nbar\nbaz\n" """.unindent(2) == "foo\n bar\n baz\n"
doAssert """foo
bar
baz
""".unindent(100) == "foo\nbar\nbaz\n"
doAssert """foo doAssert """foo
foo foo
bar bar
""".unindent() == "foo\nfoo\nbar\n" """.unindent() == "foo\nfoo\nbar\n"
let s = " this is an example " let s = " this is an example "
let s2 = ":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=3) == @["this", "is", "an", "example "]
doAssert s.splitWhitespace(maxsplit=4) == @["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() nonStaticTests()
staticTests() staticTests()