new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
8
tests/enum/tenum.nim
Normal file
8
tests/enum/tenum.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Test enums
|
||||
|
||||
type
|
||||
E = enum a, b, c, x, y, z
|
||||
|
||||
var
|
||||
en: E
|
||||
en = a
|
||||
16
tests/enum/tenum2.nim
Normal file
16
tests/enum/tenum2.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Test that enum with holes is handled correctly by case statement
|
||||
|
||||
type
|
||||
TEnumHole = enum
|
||||
eA = 0,
|
||||
eB = 4,
|
||||
eC = 5
|
||||
|
||||
var
|
||||
e: TEnumHole = eB
|
||||
|
||||
case e
|
||||
of eA: echo "A"
|
||||
of eB: echo "B"
|
||||
of eC: echo "C"
|
||||
|
||||
16
tests/enum/tenum3.nim
Normal file
16
tests/enum/tenum3.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Test enum with explicit size
|
||||
|
||||
type
|
||||
TEnumHole {.size: sizeof(int).} = enum
|
||||
eA = 0,
|
||||
eB = 4,
|
||||
eC = 5
|
||||
|
||||
var
|
||||
e: TEnumHole = eB
|
||||
|
||||
case e
|
||||
of eA: echo "A"
|
||||
of eB: echo "B"
|
||||
of eC: echo "C"
|
||||
|
||||
25
tests/enum/tenumhole.nim
Normal file
25
tests/enum/tenumhole.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
discard """
|
||||
file: "tenumhole.nim"
|
||||
output: "my value A1my value Bconc2valueCabc4abc"
|
||||
"""
|
||||
|
||||
const
|
||||
strValB = "my value B"
|
||||
|
||||
type
|
||||
TMyEnum = enum
|
||||
valueA = (1, "my value A"),
|
||||
valueB = strValB & "conc",
|
||||
valueC,
|
||||
valueD = (4, "abc")
|
||||
|
||||
# test the new "proc body can be an expr" feature:
|
||||
proc getValue: TMyEnum = valueD
|
||||
|
||||
# trick the optimizer with a variable:
|
||||
var x = getValue()
|
||||
echo valueA, ord(valueA), valueB, ord(valueB), valueC, valueD, ord(valueD), x
|
||||
|
||||
|
||||
|
||||
|
||||
9
tests/enum/tenumitems.nim
Normal file
9
tests/enum/tenumitems.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
discard """
|
||||
line: 7
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
|
||||
type a = enum b,c,d
|
||||
a.items()
|
||||
|
||||
|
||||
14
tests/enum/tenumitems2.nim
Normal file
14
tests/enum/tenumitems2.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
discard """
|
||||
output: "A\nB\nC"
|
||||
"""
|
||||
|
||||
type TAlphabet = enum
|
||||
A, B, C
|
||||
|
||||
iterator items(E: typedesc[enum]): E =
|
||||
for v in low(E)..high(E):
|
||||
yield v
|
||||
|
||||
for c in TAlphabet:
|
||||
echo($c)
|
||||
|
||||
11
tests/enum/tenummix.nim
Normal file
11
tests/enum/tenummix.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
discard """
|
||||
file: "tenummix.nim"
|
||||
line: 11
|
||||
errormsg: "type mismatch"
|
||||
"""
|
||||
|
||||
type
|
||||
TE1 = enum eA, eB
|
||||
TE2 = enum eC, eD
|
||||
|
||||
assert eA != eC
|
||||
23
tests/enum/tnamedenumfields.nim
Normal file
23
tests/enum/tnamedenumfields.nim
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
discard """
|
||||
file: "tnamedenumfields.nim"
|
||||
output: "my value A0my value Bconc1valueCabc3abc"
|
||||
"""
|
||||
|
||||
const
|
||||
strValB = "my value B"
|
||||
|
||||
type
|
||||
TMyEnum = enum
|
||||
valueA = (0, "my value A"),
|
||||
valueB = strValB & "conc",
|
||||
valueC,
|
||||
valueD = (3, "abc"),
|
||||
valueE = 4
|
||||
|
||||
# trick the optimizer with a variable:
|
||||
var x = valueD
|
||||
echo valueA, ord(valueA), valueB, ord(valueB), valueC, valueD, ord(valueD), x
|
||||
|
||||
|
||||
|
||||
|
||||
18
tests/enum/toptions.nim
Normal file
18
tests/enum/toptions.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
type
|
||||
# please make sure we have under 32 options (improves code efficiency!)
|
||||
TOption = enum
|
||||
optNone, optForceFullMake, optBoehmGC, optRefcGC, optRangeCheck,
|
||||
optBoundsCheck, optOverflowCheck, optNilCheck, optAssert, optLineDir,
|
||||
optWarns, optHints, optDeadCodeElim, optListCmd, optCompileOnly,
|
||||
optSafeCode, # only allow safe code
|
||||
optStyleCheck, optOptimizeSpeed, optOptimizeSize, optGenDynLib,
|
||||
optGenGuiApp, optStackTrace
|
||||
|
||||
TOptionset = set[TOption]
|
||||
|
||||
var
|
||||
gOptions: TOptionset = {optRefcGC, optRangeCheck, optBoundsCheck,
|
||||
optOverflowCheck, optAssert, optWarns, optHints, optLineDir, optStackTrace}
|
||||
compilerArgs: int
|
||||
gExitcode: int8
|
||||
Loading…
Add table
Add a link
Reference in a new issue