some test cleanups & category reorganization (#22010)

* clean up some test categories

* mention exact slice issue

* magics into system

* move trangechecks into overflow

* move tmemory to system

* try fix CI

* try fix CI

* final CI fix
This commit is contained in:
metagn
2023-06-06 07:54:07 +03:00
committed by GitHub
parent 2ab948ce53
commit b97d603cd0
134 changed files with 189 additions and 374 deletions

68
tests/vm/tcnstseq.nim Normal file
View File

@@ -0,0 +1,68 @@
discard """
output: '''
AngelikaAnneAnnaAnkaAnja
AngelikaAnneAnnaAnkaAnja
AngelikaAnneAnnaAnkaAnja
onetwothree
onetwothree
onetwothree
one1two2three3
'''
"""
# Test the new implicit conversion from sequences to arrays in a constant
# context.
import strutils
block t1:
const
myWords = "Angelika Anne Anna Anka Anja".split()
for x in items(myWords):
write(stdout, x) #OUT AngelikaAnneAnnaAnkaAnja
echo ""
block t2:
const
myWords = @["Angelika", "Anne", "Anna", "Anka", "Anja"]
for i in 0 .. high(myWords):
write(stdout, myWords[i]) #OUT AngelikaAnneAnnaAnkaAnja
echo ""
block t3:
for w in items(["Angelika", "Anne", "Anna", "Anka", "Anja"]):
write(stdout, w) #OUT AngelikaAnneAnnaAnkaAnja
echo ""
block t2656:
iterator it1(args: seq[string]): string =
for s in args: yield s
iterator it2(args: seq[string]): string {.closure.} =
for s in args: yield s
iterator it3(args: openArray[string]): string {.closure.} =
for s in args: yield s
iterator it4(args: openArray[(string, string)]): string {.closure.} =
for s1, s2 in items(args): yield s1 & s2
block:
const myConstSeq = @["one", "two", "three"]
for s in it1(myConstSeq):
stdout.write s
echo ""
for s in it2(myConstSeq):
stdout.write s
echo ""
for s in it3(myConstSeq):
stdout.write s
echo ""
block:
const myConstSeq = @[("one", "1"), ("two", "2"), ("three", "3")]
for s in it4(myConstSeq):
stdout.write s
echo ""

43
tests/vm/tfibconst.nim Normal file
View File

@@ -0,0 +1,43 @@
discard """
nimout: '''
Fibonacci sequence: 0, 1, 1, 2, 3
Sequence continues: 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610
'''
"""
import strformat
var fib_n {.compileTime.}: int
var fib_prev {.compileTime.}: int
var fib_prev_prev {.compileTime.}: int
proc next_fib(): int {.compileTime.} =
let fib = if fib_n < 2:
fib_n
else:
fib_prev_prev + fib_prev
inc(fib_n)
fib_prev_prev = fib_prev
fib_prev = fib
fib
const f0 = next_fib()
const f1 = next_fib()
const f2 = next_fib()
const f3 = next_fib()
const f4 = next_fib()
static:
echo fmt"Fibonacci sequence: {f0}, {f1}, {f2}, {f3}, {f4}"
const fib_continues = block:
var result = fmt"Sequence continues: "
for i in 0..10:
if i > 0:
add(result, ", ")
add(result, $next_fib())
result
static:
echo fib_continues

View File

@@ -0,0 +1,14 @@
discard """
errormsg: "request to generate code for .compileTime proc: foo"
"""
# ensure compileTime funcs can't be called from runtime
func foo(a: int): int {.compileTime.} =
a * a
proc doAThing(): int =
for i in 0..2:
result += foo(i)
echo doAThing()

View File

@@ -0,0 +1,6 @@
discard """
errormsg: "request to generate code for .compileTime proc: :anonymous"
"""
let a = func(a: varargs[int]) {.compileTime, closure.} =
discard a[0]