diff options
author | Miran <narimiran@users.noreply.github.com> | 2018-10-13 14:58:31 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-13 14:58:31 +0200 |
commit | 3c9fcc4c30dd76becacaab67f2587d88490806b9 (patch) | |
tree | 6b79838f8699f0993ac36e89549df94c0bbf7cd6 /tests/enum | |
parent | ef820769a47722cd33935dd94642aca9ecc09a8b (diff) | |
download | Nim-3c9fcc4c30dd76becacaab67f2587d88490806b9.tar.gz |
Merge tests into a larger file (part 2 of ∞) (#9335)
* merge controlflow tests * merge distinct tests * merge enum tests * merge fields tests * merge implicit tests * merge iter issues tests
Diffstat (limited to 'tests/enum')
-rw-r--r-- | tests/enum/tbasicenum.nim | 11 | ||||
-rw-r--r-- | tests/enum/tenum.nim | 155 | ||||
-rw-r--r-- | tests/enum/tenum2.nim | 16 | ||||
-rw-r--r-- | tests/enum/tenum3.nim | 16 | ||||
-rw-r--r-- | tests/enum/tenumalias.nim | 7 | ||||
-rw-r--r-- | tests/enum/tenumhole.nim | 17 | ||||
-rw-r--r-- | tests/enum/tenumoffset.nim | 20 | ||||
-rw-r--r-- | tests/enum/tnamedenumfields.nim | 23 | ||||
-rw-r--r-- | tests/enum/toptions.nim | 18 |
9 files changed, 144 insertions, 139 deletions
diff --git a/tests/enum/tbasicenum.nim b/tests/enum/tbasicenum.nim deleted file mode 100644 index eb2182f71..000000000 --- a/tests/enum/tbasicenum.nim +++ /dev/null @@ -1,11 +0,0 @@ -discard """ - file: "tbasicenum.nim" - output: "ABCDC" -""" - -type - MyEnum = enum - A,B,C,D -# trick the optimizer with an seq: -var x = @[A,B,C,D] -echo x[0],x[1],x[2],x[3],MyEnum(2) \ No newline at end of file diff --git a/tests/enum/tenum.nim b/tests/enum/tenum.nim index 6d9bdd539..72f1837f5 100644 --- a/tests/enum/tenum.nim +++ b/tests/enum/tenum.nim @@ -1,14 +1,147 @@ -# Test enums +discard """ + output: ''' +B +B +ABCDC +foo +first0second32third64 +my value A1my value Bconc2valueCabc4abc +my value A0my value Bconc1valueCabc3valueC +''' +""" -type - E = enum a, b, c, x, y, z -var - en: E -en = a - -# Bug #4066 import macros -macro genEnum(): untyped = newNimNode(nnkEnumTy).add(newEmptyNode(), newIdentNode("geItem1")) -type GeneratedEnum = genEnum() -doAssert(type(geItem1) is GeneratedEnum) + +block tenum1: + type E = enum a, b, c, x, y, z + var en: E + en = a + + # Bug #4066 + macro genEnum(): untyped = newNimNode(nnkEnumTy).add(newEmptyNode(), newIdentNode("geItem1")) + type GeneratedEnum = genEnum() + doAssert(type(geItem1) is GeneratedEnum) + + + +block tenum2: + 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" + + + +block tenum3: + 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" + + + +block tbasic: + type + MyEnum = enum + A,B,C,D + # trick the optimizer with an seq: + var x = @[A,B,C,D] + echo x[0],x[1],x[2],x[3],MyEnum(2) + + + +block talias: + # bug #5148 + type + A = enum foo, bar + B = A + + echo B.foo + + + +block thole: + type Holed = enum + hFirst = (0,"first") + hSecond = (32,"second") + hThird = (64,"third") + + var x = @[0,32,64] # This is just to avoid the compiler inlining the value of the enum + + echo Holed(x[0]),ord Holed(x[0]),Holed(x[1]),ord Holed(x[1]),Holed(x[2]),ord Holed(x[2]) + + + +block toffset: + const + strValB = "my value B" + + type + TMyEnum = enum + valueA = (1, "my value A"), + valueB = strValB & "conc", + valueC, + valueD = (4, "abc") + + proc getValue(i:int): TMyEnum = TMyEnum(i) + + # trick the optimizer with a variable: + var x = getValue(4) + echo getValue(1), ord(valueA), getValue(2), ord(valueB), getValue(3), getValue(4), ord(valueD), x + + + +block tnamedfields: + 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 + + + +block toptions: + 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, 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 diff --git a/tests/enum/tenum2.nim b/tests/enum/tenum2.nim deleted file mode 100644 index 3e34a21ce..000000000 --- a/tests/enum/tenum2.nim +++ /dev/null @@ -1,16 +0,0 @@ -# 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" - diff --git a/tests/enum/tenum3.nim b/tests/enum/tenum3.nim deleted file mode 100644 index 49cbf04d5..000000000 --- a/tests/enum/tenum3.nim +++ /dev/null @@ -1,16 +0,0 @@ -# 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" - diff --git a/tests/enum/tenumalias.nim b/tests/enum/tenumalias.nim deleted file mode 100644 index 2d1f70d0e..000000000 --- a/tests/enum/tenumalias.nim +++ /dev/null @@ -1,7 +0,0 @@ -# bug #5148 - -type - A = enum foo, bar - B = A - -echo B.foo diff --git a/tests/enum/tenumhole.nim b/tests/enum/tenumhole.nim deleted file mode 100644 index 4928572f9..000000000 --- a/tests/enum/tenumhole.nim +++ /dev/null @@ -1,17 +0,0 @@ -discard """ - file: "tenumhole.nim" - output: "first0second32third64" -""" - -type Holed = enum - hFirst = (0,"first") - hSecond = (32,"second") - hThird = (64,"third") - -var x = @[0,32,64] # This is just to avoid the compiler inlining the value of the enum - -echo Holed(x[0]),ord Holed(x[0]),Holed(x[1]),ord Holed(x[1]),Holed(x[2]),ord Holed(x[2]) - - - - diff --git a/tests/enum/tenumoffset.nim b/tests/enum/tenumoffset.nim deleted file mode 100644 index e67164604..000000000 --- a/tests/enum/tenumoffset.nim +++ /dev/null @@ -1,20 +0,0 @@ -discard """ - file: "tenumoffset.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") - -proc getValue(i:int): TMyEnum = TMyEnum(i) - -# trick the optimizer with a variable: -var x = getValue(4) -echo getValue(1), ord(valueA), getValue(2), ord(valueB), getValue(3), getValue(4), ord(valueD), x diff --git a/tests/enum/tnamedenumfields.nim b/tests/enum/tnamedenumfields.nim deleted file mode 100644 index e9ac88a42..000000000 --- a/tests/enum/tnamedenumfields.nim +++ /dev/null @@ -1,23 +0,0 @@ -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 - - - - diff --git a/tests/enum/toptions.nim b/tests/enum/toptions.nim deleted file mode 100644 index da66f0067..000000000 --- a/tests/enum/toptions.nim +++ /dev/null @@ -1,18 +0,0 @@ - -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, 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 |