summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/enum/tbasicenum.nim11
-rw-r--r--tests/enum/tenumhole.nim24
-rw-r--r--tests/enum/tenumoffset.nim20
-rw-r--r--tests/js/tbasicenum.nim10
-rw-r--r--tests/js/tenumhole.nim12
-rw-r--r--tests/js/tenumnegkey.nim12
-rw-r--r--tests/js/tenumoffset.nim19
7 files changed, 92 insertions, 16 deletions
diff --git a/tests/enum/tbasicenum.nim b/tests/enum/tbasicenum.nim
new file mode 100644
index 000000000..eb2182f71
--- /dev/null
+++ b/tests/enum/tbasicenum.nim
@@ -0,0 +1,11 @@
+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/tenumhole.nim b/tests/enum/tenumhole.nim
index 68b82e283..4928572f9 100644
--- a/tests/enum/tenumhole.nim
+++ b/tests/enum/tenumhole.nim
@@ -1,24 +1,16 @@
 discard """
   file: "tenumhole.nim"
-  output: "my value A1my value Bconc2valueCabc4abc"
+  output: "first0second32third64"
 """
 
-const
-  strValB = "my value B"
+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
 
-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
+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
new file mode 100644
index 000000000..e67164604
--- /dev/null
+++ b/tests/enum/tenumoffset.nim
@@ -0,0 +1,20 @@
+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/js/tbasicenum.nim b/tests/js/tbasicenum.nim
new file mode 100644
index 000000000..a9e9ce2da
--- /dev/null
+++ b/tests/js/tbasicenum.nim
@@ -0,0 +1,10 @@
+discard """
+  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/js/tenumhole.nim b/tests/js/tenumhole.nim
new file mode 100644
index 000000000..71a493e8c
--- /dev/null
+++ b/tests/js/tenumhole.nim
@@ -0,0 +1,12 @@
+discard """
+  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/js/tenumnegkey.nim b/tests/js/tenumnegkey.nim
new file mode 100644
index 000000000..f96c554d4
--- /dev/null
+++ b/tests/js/tenumnegkey.nim
@@ -0,0 +1,12 @@
+discard """
+  output: "first-12second32third64"
+"""
+
+type Holed = enum
+  hFirst = (-12,"first")
+  hSecond = (32,"second")
+  hThird = (64,"third")
+  
+var x = @[-12,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/js/tenumoffset.nim b/tests/js/tenumoffset.nim
new file mode 100644
index 000000000..5bdc4c105
--- /dev/null
+++ b/tests/js/tenumoffset.nim
@@ -0,0 +1,19 @@
+discard """
+  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