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"
|
targets: "c cpp js"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
const characters = "abcdefghijklmnopqrstuvwxyz"
|
from std/sequtils import toSeq, map
|
||||||
const numbers = "1234567890"
|
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)":
|
# test "slice of length == len(characters)":
|
||||||
# replace characters completely by numbers
|
# replace characters completely by numbers
|
||||||
var s: string
|
var s: string
|
||||||
|
|
@ -56,8 +70,7 @@ proc test_string_slice() =
|
||||||
doAssertRaises(IndexDefect):
|
doAssertRaises(IndexDefect):
|
||||||
discard s[0..999]
|
discard s[0..999]
|
||||||
|
|
||||||
|
block: # ==, cmp
|
||||||
proc test_string_cmp() =
|
|
||||||
let world = "hello\0world"
|
let world = "hello\0world"
|
||||||
let earth = "hello\0earth"
|
let earth = "hello\0earth"
|
||||||
let short = "hello\0"
|
let short = "hello\0"
|
||||||
|
|
@ -76,33 +89,10 @@ proc test_string_cmp() =
|
||||||
doAssert cmp(world, hello) > 0
|
doAssert cmp(world, hello) > 0
|
||||||
doAssert cmp(world, goodbye) > 0
|
doAssert cmp(world, goodbye) > 0
|
||||||
|
|
||||||
|
block: # bug #7816
|
||||||
#--------------------------
|
|
||||||
# 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()
|
|
||||||
|
|
||||||
tester(1)
|
tester(1)
|
||||||
|
|
||||||
block: # reverse
|
block: # bug #14497, reverse
|
||||||
doAssert reverse("hello") == "olleh"
|
doAssert reverse("hello") == "olleh"
|
||||||
|
|
||||||
block: # len, high
|
block: # len, high
|
||||||
|
|
@ -123,16 +113,10 @@ proc main() =
|
||||||
doAssert "".cstring.len == 0
|
doAssert "".cstring.len == 0
|
||||||
doAssert "".cstring.high == -1
|
doAssert "".cstring.high == -1
|
||||||
|
|
||||||
|
block: # bug #16674
|
||||||
var c: cstring = nil
|
var c: cstring = nil
|
||||||
template impl() =
|
|
||||||
doAssert c.len == 0
|
doAssert c.len == 0
|
||||||
doAssert c.high == -1
|
doAssert c.high == -1
|
||||||
when defined js:
|
|
||||||
when nimvm: impl()
|
|
||||||
else:
|
|
||||||
# xxx pending bug #16674
|
|
||||||
discard
|
|
||||||
else: impl()
|
|
||||||
|
|
||||||
static: main()
|
static: main()
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue