new tester; all tests categorized

This commit is contained in:
Araq 2014-01-13 02:10:03 +01:00
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

View file

@ -0,0 +1,15 @@
discard """
output: "an identifier"
"""
const
SymChars: set[char] = {'a'..'z', 'A'..'Z', '\x80'..'\xFF'}
proc classify(s: string) =
case s[0]
of SymChars, '_': echo "an identifier"
of {'0'..'9'}: echo "a number"
else: echo "other"
classify("Hurra")

View file

@ -0,0 +1,30 @@
discard """
file: "tcaseexpr1.nim"
line: 29
errormsg: "type mismatch: got (string) but expected 'int'"
line: 23
errormsg: "not all cases are covered"
"""
type
E = enum A, B, C
proc foo(x): auto =
return case x
of 1..9: "digit"
else: "number"
var r = foo(10)
var x = C
var t1 = case x:
of A: "a"
of B: "b"
var t2 = case x:
of A: 10
of B, C: "23"

View file

@ -0,0 +1,15 @@
discard """
line: 13
errormsg: "duplicate case label"
"""
type
TE = enum A, B, C, D
var
e: TE
case e
of A..D, B..C:
echo "redundant"
else: nil

View file

@ -0,0 +1,18 @@
discard """
line: 13
errormsg: "duplicate case label"
"""
proc checkDuplicates(myval: int32): bool =
case myval
of 0x7B:
echo "this should not compile"
of 0x78 .. 0x7D:
result = true
else:
nil
echo checkDuplicates(0x7B)

View file

@ -0,0 +1,40 @@
discard """
file: "tcasestm.nim"
output: "ayyydd"
"""
# Test the case statement
type
tenum = enum eA, eB, eC
var
x: string = "yyy"
y: Tenum = eA
i: int
case y
of eA: write(stdout, "a")
of eB, eC: write(stdout, "b or c")
case x
of "Andreas", "Rumpf": write(stdout, "Hallo Meister!")
of "aa", "bb": write(stdout, "Du bist nicht mein Meister")
of "cc", "hash", "when": nil
of "will", "it", "finally", "be", "generated": nil
var z = case i
of 1..5, 8, 9: "aa"
of 6, 7: "bb"
elif x == "Ha":
"cc"
elif x == "yyy":
write(stdout, x)
"dd"
else:
"zz"
echo z
#OUT ayyy

View file

@ -0,0 +1,47 @@
discard """
output: '''yeah A enumB
yeah A enumB
yeah CD enumD
yeah CD enumE
yeah A enumB
yeah CD enumE
yeah CD enumD
yeah A enumB
yeah B enumC
yeah A enumB
yeah A enumB
yeah A enumB'''
"""
type
MyEnum = enum
enumA, enumB, enumC, enumD, enumE
proc vm() =
var instructions: array [0..100, MyEnum]
instructions[2] = enumC
instructions[3] = enumD
instructions[4] = enumA
instructions[5] = enumD
instructions[6] = enumC
instructions[7] = enumA
instructions[8] = enumB
instructions[12] = enumE
var pc = 0
while true:
{.computedGoto.}
let instr = instructions[pc]
let ra = instr.succ # instr.regA
case instr
of enumA:
echo "yeah A ", ra
of enumC, enumD:
echo "yeah CD ", ra
of enumB:
echo "yeah B ", ra
of enumE:
break
inc(pc)
vm()

View file

@ -0,0 +1,24 @@
import strutils
var x = 343
case stdin.readline.parseInt
of 0:
echo "most common case"
of 1:
{.linearScanEnd.}
echo "second most common case"
of 2: echo "unlikely: use branch table"
else:
echo "unlikely too: use branch table"
case x
of 23: echo "23"
of 343: echo "343"
of 21: echo "21"
else:
{.linearScanEnd.}
echo "default"