cleanup tests/stdlib/tstring.nim (#17158)
* cleanup tests/stdlib/tstring.nim * cleanup tests/stdlib/tstring.nim * cleanup rest of test
This commit is contained in:
parent
cbe3c993b6
commit
0bb7e8dcb4
1 changed files with 80 additions and 96 deletions
|
|
@ -2,10 +2,24 @@ discard """
|
|||
targets: "c cpp js"
|
||||
"""
|
||||
|
||||
const characters = "abcdefghijklmnopqrstuvwxyz"
|
||||
const numbers = "1234567890"
|
||||
from std/sequtils import toSeq, map
|
||||
from std/sugar import `=>`
|
||||
|
||||
proc tester[T](x: T) =
|
||||
let test = toSeq(0..4).map(i => newSeq[int]())
|
||||
doAssert $test == "@[@[], @[], @[], @[], @[]]"
|
||||
|
||||
func reverse*(a: string): string =
|
||||
result = a
|
||||
for i in 0 ..< a.len div 2:
|
||||
swap(result[i], result[^(i + 1)])
|
||||
|
||||
proc main() =
|
||||
block: # ..
|
||||
const
|
||||
characters = "abcdefghijklmnopqrstuvwxyz"
|
||||
numbers = "1234567890"
|
||||
|
||||
proc test_string_slice() =
|
||||
# test "slice of length == len(characters)":
|
||||
# replace characters completely by numbers
|
||||
var s: string
|
||||
|
|
@ -56,8 +70,7 @@ proc test_string_slice() =
|
|||
doAssertRaises(IndexDefect):
|
||||
discard s[0..999]
|
||||
|
||||
|
||||
proc test_string_cmp() =
|
||||
block: # ==, cmp
|
||||
let world = "hello\0world"
|
||||
let earth = "hello\0earth"
|
||||
let short = "hello\0"
|
||||
|
|
@ -76,33 +89,10 @@ proc test_string_cmp() =
|
|||
doAssert cmp(world, hello) > 0
|
||||
doAssert cmp(world, goodbye) > 0
|
||||
|
||||
|
||||
#--------------------------
|
||||
# bug #7816
|
||||
import sugar
|
||||
import sequtils
|
||||
|
||||
proc tester[T](x: T) =
|
||||
let test = toSeq(0..4).map(i => newSeq[int]())
|
||||
doAssert $test == "@[@[], @[], @[], @[], @[]]"
|
||||
|
||||
|
||||
|
||||
# #14497
|
||||
func reverse*(a: string): string =
|
||||
result = a
|
||||
for i in 0 ..< a.len div 2:
|
||||
swap(result[i], result[^(i + 1)])
|
||||
|
||||
|
||||
proc main() =
|
||||
# xxx put all tests here to test in VM and RT
|
||||
test_string_slice()
|
||||
test_string_cmp()
|
||||
|
||||
block: # bug #7816
|
||||
tester(1)
|
||||
|
||||
block: # reverse
|
||||
block: # bug #14497, reverse
|
||||
doAssert reverse("hello") == "olleh"
|
||||
|
||||
block: # len, high
|
||||
|
|
@ -123,16 +113,10 @@ proc main() =
|
|||
doAssert "".cstring.len == 0
|
||||
doAssert "".cstring.high == -1
|
||||
|
||||
block: # bug #16674
|
||||
var c: cstring = nil
|
||||
template impl() =
|
||||
doAssert c.len == 0
|
||||
doAssert c.high == -1
|
||||
when defined js:
|
||||
when nimvm: impl()
|
||||
else:
|
||||
# xxx pending bug #16674
|
||||
discard
|
||||
else: impl()
|
||||
|
||||
static: main()
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue