summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/compile/tdictdestruct.nim16
-rw-r--r--tests/accept/compile/tgetstartmilsecs.nim7
-rw-r--r--tests/accept/run/texplicitgeneric1.nim32
-rw-r--r--tests/accept/run/texplicitgeneric2.nim30
-rw-r--r--tests/accept/run/treraise.nim17
-rw-r--r--tests/accept/run/tvariantasgn.nim24
-rw-r--r--tests/accept/run/tvariantstack.nim46
7 files changed, 172 insertions, 0 deletions
diff --git a/tests/accept/compile/tdictdestruct.nim b/tests/accept/compile/tdictdestruct.nim
new file mode 100644
index 000000000..20ca4ba94
--- /dev/null
+++ b/tests/accept/compile/tdictdestruct.nim
@@ -0,0 +1,16 @@
+
+type
+  TDict[TK, TV] = object
+    k: TK
+    v: TV
+  PDict[TK, TV] = ref TDict[TK, TV]
+
+proc destroyDict[TK, TV](a : PDict[TK, TV]) =
+    return
+proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] =
+    new(result, destroyDict)
+    
+
+discard newDict("a", "b")    
+
+
diff --git a/tests/accept/compile/tgetstartmilsecs.nim b/tests/accept/compile/tgetstartmilsecs.nim
new file mode 100644
index 000000000..340c78af1
--- /dev/null
+++ b/tests/accept/compile/tgetstartmilsecs.nim
@@ -0,0 +1,7 @@
+# 
+import times, os
+
+var start = getStartMilsecs()
+os.sleep(1000)
+
+echo getStartMilsecs() - start #OUT 1000
diff --git a/tests/accept/run/texplicitgeneric1.nim b/tests/accept/run/texplicitgeneric1.nim
new file mode 100644
index 000000000..54fff5246
--- /dev/null
+++ b/tests/accept/run/texplicitgeneric1.nim
@@ -0,0 +1,32 @@
+# test explicit type instantiation
+
+type
+  TDict*[TKey, TValue] = object 
+    data: seq[tuple[k: TKey, v: TValue]]
+  PDict*[TKey, #with `==`(a, b: TKey): bool
+               #     hash(a: TKey): int, 
+         TValue] = ref TDict[TKey, TValue]
+  
+proc newDict*[TKey, TValue](): PDict[TKey, TValue] = 
+  new(result)
+  result.data = @[]
+  
+proc add*[TKey, TValue](d: PDict[TKey, TValue], k: TKey, v: TValue) = 
+  d.data.add((k, v))
+  
+iterator items*[Tkey, tValue](d: PDict[TKey, TValue]): tuple[k: TKey, 
+               v: TValue] = 
+  for k, v in items(d.data): yield (k, v)
+    
+var d = newDict[int, string]()
+d.add(12, "12")
+d.add(13, "13")
+for k, v in items(d): 
+  stdout.write("Key: ", $k, " value: ", v)
+
+var c = newDict[char, string]()
+c.add('A', "12")
+c.add('B', "13")
+for k, v in items(c): 
+  stdout.write(" Key: ", $k, " value: ", v)
+
diff --git a/tests/accept/run/texplicitgeneric2.nim b/tests/accept/run/texplicitgeneric2.nim
new file mode 100644
index 000000000..9bd2f04c8
--- /dev/null
+++ b/tests/accept/run/texplicitgeneric2.nim
@@ -0,0 +1,30 @@
+# test explicit type instantiation
+
+type
+  TDict*[TKey, TValue] = object 
+    data: seq[tuple[k: TKey, v: TValue]]
+  PDict*[TKey, TValue] = ref TDict[TKey, TValue]
+  
+proc newDict*[TKey, TValue](): PDict[TKey, TValue] = 
+  new(result)
+  result.data = @[]
+  
+proc add*(d: PDict, k: TKey, v: TValue) = 
+  d.data.add((k, v))
+  
+
+#iterator items*(d: PDict): tuple[k: TKey, v: TValue] = 
+#  for k, v in items(d.data): yield (k, v)
+    
+var d = newDict[int, string]()
+d.add(12, "12")
+d.add(13, "13")
+for k, v in items(d): 
+  stdout.write("Key: ", $k, " value: ", v)
+
+var c = newDict[char, string]()
+c.add('A', "12")
+c.add('B', "13")
+for k, v in items(c): 
+  stdout.write(" Key: ", $k, " value: ", v)
+
diff --git a/tests/accept/run/treraise.nim b/tests/accept/run/treraise.nim
new file mode 100644
index 000000000..60b8640c4
--- /dev/null
+++ b/tests/accept/run/treraise.nim
@@ -0,0 +1,17 @@
+type
+  ESomething = object of E_Base
+  ESomeOtherErr = object of E_Base
+
+proc genErrors(s: string) =
+  if s == "error!":
+    raise newException(ESomething, "Test")
+  else:
+    raise newException(EsomeotherErr, "bla")
+
+while True:
+  try:
+    genErrors("errssor!")
+  except ESomething:
+    echo("Error happened")
+  except:
+    raise
diff --git a/tests/accept/run/tvariantasgn.nim b/tests/accept/run/tvariantasgn.nim
new file mode 100644
index 000000000..7d51da845
--- /dev/null
+++ b/tests/accept/run/tvariantasgn.nim
@@ -0,0 +1,24 @@
+#BUG
+type
+  TAnyKind = enum
+    nkInt,
+    nkFloat,
+    nkString
+  TAny = object
+    case kind: TAnyKind
+    of nkInt: intVal: int
+    of nkFloat: floatVal: float
+    of nkString: strVal: string
+
+var s: TAny
+s.kind = nkString
+s.strVal = "test"
+
+var nr: TAny
+nr.kind = nkint
+nr.intVal = 78
+
+
+# s = nr # works
+nr = s # fails!
+
diff --git a/tests/accept/run/tvariantstack.nim b/tests/accept/run/tvariantstack.nim
new file mode 100644
index 000000000..3df8197f2
--- /dev/null
+++ b/tests/accept/run/tvariantstack.nim
@@ -0,0 +1,46 @@
+#BUG
+type
+  TAnyKind = enum
+    nkInt,
+    nkFloat,
+    nkString
+  PAny = ref TAny
+  TAny = object
+    case kind: TAnyKind
+    of nkInt: intVal: int
+    of nkFloat: floatVal: float
+    of nkString: strVal: string
+
+  TStack* = object
+    list*: seq[TAny]
+
+proc newStack(): TStack =
+  result.list = @[]
+
+proc push(Stack: var TStack, item: TAny) =
+  var nSeq: seq[TAny] = @[item]
+  for i in items(Stack.list):
+    nSeq.add(i)
+  Stack.list = nSeq
+
+proc pop(Stack: var TStack): TAny =
+  result = Stack.list[0]
+  Stack.list.delete(0)
+
+var stack = newStack()
+
+var s: TAny
+s.kind = nkString
+s.strVal = "test"
+
+stack.push(s)
+
+var nr: TAny
+nr.kind = nkint
+nr.intVal = 78
+
+stack.push(nr)
+
+var t = stack.pop()
+
+