diff options
author | Andreas Rumpf <andreas@andreas-laptop> | 2010-05-28 23:33:29 +0200 |
---|---|---|
committer | Andreas Rumpf <andreas@andreas-laptop> | 2010-05-28 23:33:29 +0200 |
commit | b34b1dbc6c7290a893149aa9f5ea5d54a37c8522 (patch) | |
tree | d61f14d6f56eab37178242b61c83fdbbd87db30d | |
parent | 6c2050912166a4960b40c3825afb1a31cfdde0eb (diff) | |
download | Nim-b34b1dbc6c7290a893149aa9f5ea5d54a37c8522.tar.gz |
added tests
-rw-r--r-- | tests/accept/compile/tdictdestruct.nim | 16 | ||||
-rw-r--r-- | tests/accept/compile/tgetstartmilsecs.nim | 7 | ||||
-rw-r--r-- | tests/accept/run/texplicitgeneric1.nim | 32 | ||||
-rw-r--r-- | tests/accept/run/texplicitgeneric2.nim | 30 | ||||
-rw-r--r-- | tests/accept/run/treraise.nim | 17 | ||||
-rw-r--r-- | tests/accept/run/tvariantasgn.nim | 24 | ||||
-rw-r--r-- | tests/accept/run/tvariantstack.nim | 46 |
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() + + |