summary refs log tree commit diff stats
path: root/tests/concepts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/concepts')
-rw-r--r--tests/concepts/mvarconcept.nim13
-rw-r--r--tests/concepts/tmanual.nim7
-rw-r--r--tests/concepts/tswizzle.nim2
-rw-r--r--tests/concepts/tusertypeclasses.nim8
-rw-r--r--tests/concepts/tusertypeclasses2.nim4
-rw-r--r--tests/concepts/tvarconcept.nim9
6 files changed, 32 insertions, 11 deletions
diff --git a/tests/concepts/mvarconcept.nim b/tests/concepts/mvarconcept.nim
new file mode 100644
index 000000000..0f9d0beff
--- /dev/null
+++ b/tests/concepts/mvarconcept.nim
@@ -0,0 +1,13 @@
+type RNG* = concept var rng
+  rng.randomUint32() is uint32
+
+type MersenneTwister* = object
+
+proc randomUint32*(self: var MersenneTwister): uint32 = 5
+
+proc randomInt*(rng: var RNG; max: Positive): Natural = 5
+
+var mersenneTwisterInst = MersenneTwister()
+
+proc randomInt*(max: Positive): Natural =
+  mersenneTwisterInst.randomInt(max)
diff --git a/tests/concepts/tmanual.nim b/tests/concepts/tmanual.nim
index 243992aed..7cf08af06 100644
--- a/tests/concepts/tmanual.nim
+++ b/tests/concepts/tmanual.nim
@@ -12,7 +12,6 @@ e
 s
 t
 '''
-  disabled: "true"
 """
 
 template accept(e: expr) =
@@ -22,10 +21,10 @@ template reject(e: expr) =
   static: assert(not compiles(e))
 
 type
-  Container[T] = generic C
-    C.len is Ordinal
+  Container[T] = concept c
+    c.len is Ordinal
     items(c) is iterator
-    for value in C:
+    for value in c:
       type(value) is T
 
 proc takesIntContainer(c: Container[int]) =
diff --git a/tests/concepts/tswizzle.nim b/tests/concepts/tswizzle.nim
index 9bbdb67e6..07205d454 100644
--- a/tests/concepts/tswizzle.nim
+++ b/tests/concepts/tswizzle.nim
@@ -40,7 +40,7 @@ proc isSwizzle(s: string): bool {.compileTime.} =
   return false
 
 type
-  StringIsSwizzle = generic value
+  StringIsSwizzle = concept value
     value.isSwizzle
 
   SwizzleStr = static[string] and StringIsSwizzle
diff --git a/tests/concepts/tusertypeclasses.nim b/tests/concepts/tusertypeclasses.nim
index 4e5e6221c..612556949 100644
--- a/tests/concepts/tusertypeclasses.nim
+++ b/tests/concepts/tusertypeclasses.nim
@@ -16,10 +16,10 @@ type
   TObj = object
     x: int
 
-  Sortable = generic x, y
+  Sortable = concept x, y
     (x < y) is bool
 
-  ObjectContainer = generic C
+  ObjectContainer = concept C
     C.len is Ordinal
     for v in items(C):
       v.type is tuple|object
@@ -38,7 +38,7 @@ proc intval(x: int): int = 10
 
 # check real and virtual fields
 type
-  TFoo = generic T
+  TFoo = concept T
     T.x
     y(T)
     intval T.y
@@ -50,7 +50,7 @@ proc testFoo(x: TFoo) = discard
 testFoo(TObj(x: 10))
 
 type
-  Matrix[Rows, Cols: static[int]; T] = generic M
+  Matrix[Rows, Cols: static[int]; T] = concept M
     M.M == Rows
     M.N == Cols
     M.T is T
diff --git a/tests/concepts/tusertypeclasses2.nim b/tests/concepts/tusertypeclasses2.nim
index 77c70d7a6..ae05540cd 100644
--- a/tests/concepts/tusertypeclasses2.nim
+++ b/tests/concepts/tusertypeclasses2.nim
@@ -1,5 +1,5 @@
 type
-  hasFieldX = generic z
+  hasFieldX = concept z
     z.x is int
 
   obj_x = object
@@ -7,7 +7,7 @@ type
 
   ref_obj_x = ref object
     x: int
-  
+
   ref_to_obj_x = ref obj_x
 
   p_o_x = ptr obj_x
diff --git a/tests/concepts/tvarconcept.nim b/tests/concepts/tvarconcept.nim
new file mode 100644
index 000000000..203ef3cdc
--- /dev/null
+++ b/tests/concepts/tvarconcept.nim
@@ -0,0 +1,9 @@
+discard """
+  output: "5"
+"""
+
+# bug #2346, bug #2404
+
+import mvarconcept
+
+echo randomInt(5)