start of tests refactoring; sqlite3 new wrapper fixes

This commit is contained in:
rumpf_a@web.de
2010-02-21 19:42:36 +01:00
parent 6bc16904ed
commit d913fdb280
173 changed files with 206 additions and 238 deletions

View File

@@ -0,0 +1 @@
# Test if the compiler detects invalid module names

28
tests/reject/t99bott.nim Normal file
View File

@@ -0,0 +1,28 @@
## 99 Bottles of Beer
## http://www.99-bottles-of-beer.net/
## Nimrod version
## Author: Philippe Lhoste <PhiLho(a)GMX.net> http://Phi.Lho.free.fr
# 2009-11-25
# Loosely based on my old Lua version... Updated to current official lyrics.
proc GetBottleNumber(n: int): string =
var bs: string
if n == 0:
bs = "No more bottles"
elif n == 1:
bs = "1 bottle"
else:
bs = $n & " bottles"
return bs & " of beer"
for bn in countdown(99, 1):
const cur = GetBottleNumber(bn) #ERROR_MSG constant expression expected
echo(cur, " on the wall, ", cur, ".")
echo("Take one down and pass it around, ", GetBottleNumber(bn-1),
" on the wall.\n")
echo "No more bottles of beer on the wall, no more bottles of beer."
echo "Go to the store and buy some more, 99 bottles of beer on the wall."

16
tests/reject/tadrdisc.nim Normal file
View File

@@ -0,0 +1,16 @@
# Test that the address of a dicriminants cannot be taken
type
TKind = enum ka, kb, kc
TA = object
case k: TKind
of ka: x, y: int
of kb: a, b: string
of kc: c, d: float
proc setKind(k: var TKind) =
k = kc
var a: TA
setKind(a.k) #ERROR_MSG for a 'var' type a variable needs to be passed

8
tests/reject/tambsym.nim Normal file
View File

@@ -0,0 +1,8 @@
# Test ambiguous symbols
import mambsym1, mambsym2
var
v: TExport #ERROR_MSG ambiguous identifier
v = y

View File

@@ -0,0 +1,8 @@
# Test ambiguous symbols
import mambsym1, times
var
v = mDec #ERROR_MSG ambiguous identifier
writeln(stdout, ord(v))

10
tests/reject/tbind2.nim Normal file
View File

@@ -0,0 +1,10 @@
# Test the new ``bind`` keyword for templates
proc p1(x: int8, y: int): int = return x + y
proc p1(x: int, y: int8): int = return x - y
template tempBind(x, y: expr): expr =
bind p1(x, y) #ERROR_MSG ambiguous call
echo tempBind(1'i8, 2'i8)

6
tests/reject/tbind4.nim Normal file
View File

@@ -0,0 +1,6 @@
# Module B
import mbind4
echo genId() #ERROR_MSG instantiation from here

11
tests/reject/tblock1.nim Normal file
View File

@@ -0,0 +1,11 @@
# check for forward label and
# for failure when label is not declared
proc main =
block endLess:
write(stdout, "Muaahh!\N")
break endLess
break ha #ERROR
main()

23
tests/reject/tconstr1.nim Normal file
View File

@@ -0,0 +1,23 @@
# Test array, record constructors
type
TComplexRecord = tuple[
s: string,
x, y: int,
z: float,
chars: set[Char]]
proc testSem =
var
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a', 'b', 'c'})]
write(stdout, things[0].x)
const
things: array [0..1, TComplexRecord] = [
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0)] #ERROR
otherThings = [ # the same
(s: "hi", x: 69, y: 45, z: 0.0, chars: {'a', 'b', 'c'}),
(s: "hi", x: 69, y: 45, z: 1.0, chars: {'a'})]

10
tests/reject/tillrec.nim Normal file
View File

@@ -0,0 +1,10 @@
# test illegal recursive types
type
TLegal {.final.} = object
x: int
kids: seq[TLegal]
TIllegal {.final.} = object #ERROR_MSG illegal recursion in type 'TIllegal'
y: Int
x: array[0..3, TIllegal]

9
tests/reject/tinout.nim Normal file
View File

@@ -0,0 +1,9 @@
# Test in out checking for parameters
proc abc(x: var int) =
x = 0
proc b() =
abc(3) #ERROR
b()

View File

@@ -0,0 +1,20 @@
import regexprs, strutils
type
TURL = tuple[protocol, subdomain, domain, port: string, path: seq[string]]
proc parseURL(url: string): TURL =
#([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?
var pattern: string = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
var m: array[0..6, string] #Array with the matches
newSeq(m, 7) #ERROR
discard regexprs.match(url, pattern, m)
result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
port: m[5], path: m[6].split('/'))
var r: TUrl
r = parseUrl(r"http://google.com/search?var=bleahdhsad")
echo(r.domain)

View File

@@ -0,0 +1,8 @@
# This was parsed even though it should not!
proc chdir(path: CString): cint {.importc: "chdir", header: "dirHeader".}
proc getcwd(buf: CString, buflen: cint): CString
when defined(unix): {.importc: "getcwd", header: "<unistd.h>".} #ERROR_MSG invalid indentation
elif defined(windows): {.importc: "getcwd", header: "<direct.h>"}
else: {.error: "os library not ported to your OS. Please help!".}

3
tests/reject/titer4.nim Normal file
View File

@@ -0,0 +1,3 @@
for x in {'a'..'z'}: #ERROR_MSG iterator within for loop context expected
nil

5
tests/reject/tnamspc.nim Normal file
View File

@@ -0,0 +1,5 @@
# Test17 - test correct handling of namespaces
import mnamspc1
global = 9 #ERROR

6
tests/reject/tnoop.nim Normal file
View File

@@ -0,0 +1,6 @@
# Tests the new check in the semantic pass
var
a: int
a() #ERROR_MSG expression 'a()' cannot be called

15
tests/reject/tnot.nim Normal file
View File

@@ -0,0 +1,15 @@
# BUG: following compiles, but should not:
proc nodeOfDegree(x: Int): bool =
result = false
proc main =
for j in 0..2:
for i in 0..10:
if not nodeOfDegree(1) >= 0: #ERROR_MSG type mismatch
Echo "Yes"
else:
Echo "No"
main()

11
tests/reject/topaque.nim Normal file
View File

@@ -0,0 +1,11 @@
# Test the new opaque types
import
mopaque
var
L: TLexer
L.filename = "ha"
L.line = 34
L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer'

5
tests/reject/topena1.nim Normal file
View File

@@ -0,0 +1,5 @@
# Tests a special bug
var
x: ref openarray[string] #ERROR_MSG invalid type

6
tests/reject/toverl.nim Normal file
View File

@@ -0,0 +1,6 @@
# Test for overloading
type
TNone {.exportc: "_NONE", final.} = object
proc TNone(a, b: int) = nil #ERROR_MSG attempt to redefine 'TNone'

5
tests/reject/trawstr.nim Normal file
View File

@@ -0,0 +1,5 @@
# Test the new raw strings:
const
xxx = r"This is a raw string!"
yyy = "This not\" #ERROR

View File

@@ -0,0 +1,5 @@
# Test recursive includes
include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim'
echo "trecina"

View File

@@ -0,0 +1,6 @@
# Test recursive includes
include trecincb #ERROR_MSG recursive dependency: 'tests/trecincb.nim'
echo "trecinb"

View File

@@ -0,0 +1,7 @@
# Test that an error message occurs for a recursive iterator
iterator myrec(n: int): int =
for x in myrec(n-1): #ERROR_MSG recursive dependency: 'myrec'
yield x
for x in myrec(10): echo x

21
tests/reject/trectype.nim Normal file
View File

@@ -0,0 +1,21 @@
# Test recursive type descriptions
# (mainly for the C code generator)
type
PA = ref TA
TA = array [0..2, PA]
PRec = ref TRec
TRec {.final.} = object
a, b: TA
P1 = ref T1
PB = ref TB
TB = array [0..3, P1]
T1 = array [0..6, PB]
var
x: PA
new(x)
#ERROR_MSG internal error: cannot generate C type for: PA

16
tests/reject/trefs.nim Normal file
View File

@@ -0,0 +1,16 @@
# test for ref types (including refs to procs)
type
TProc = proc (a, b: int): int {.stdcall.}
proc foo(c, d: int): int {.stdcall.} =
return 0
proc wrongfoo(c, e: int): int {.inline.} =
return 0
var p: TProc
p = foo
write(stdout, "success!")
p = wrongfoo #ERROR_MSG type mismatch

11
tests/reject/tsidee1.nim Normal file
View File

@@ -0,0 +1,11 @@
var
global: int
proc dontcare(x: int): int = return x + global
proc SideEffectLyer(x, y: int): int {.noSideEffect.} = #ERROR_MSG 'SideEffectLyer' can have side effects
return x + y + dontcare(x)
echo SideEffectLyer(1, 3)

10
tests/reject/tsidee4.nim Normal file
View File

@@ -0,0 +1,10 @@
var
global: int
proc dontcare(x: int): int = return x
proc noSideEffect(x, y: int, p: proc (a: int): int {.noSideEffect.}): int {.noSideEffect.} =
return x + y + dontcare(x)
echo noSideEffect(1, 3, dontcare) #ERROR_MSG type mismatch

View File

@@ -0,0 +1,5 @@
# Test 2
# Simple type checking
var a: string
a = false #ERROR

View File

@@ -0,0 +1,5 @@
# no statement after return
proc main() =
return
echo("huch?") #ERROR_MSG statement not allowed after

View File

@@ -0,0 +1,3 @@
# Test 3
1+4 #ERROR_MSG value returned by statement has to be discarded

14
tests/reject/ttempl2.nim Normal file
View File

@@ -0,0 +1,14 @@
template declareInScope(x: expr, t: typeDesc): stmt =
var x: t
template declareInNewScope(x: expr, t: typeDesc): stmt =
# open a new scope:
block:
var x: t
declareInScope(a, int)
a = 42 # works, `a` is known here
declareInNewScope(b, int)
b = 42 #ERROR_MSG undeclared identifier: 'b'

View File

@@ -0,0 +1,7 @@
# Bug #502670
var ef_ = 3 #ERROR_MSG invalid token: _
var a__b = 1
var c___d = 2
echo(ab, cd, ef_)

View File

@@ -0,0 +1,3 @@
type
Uint8 = Uint8 #ERROR_MSG illegal recursion in type 'Uint8'