diff options
author | dom96 <dominikpicheta@googlemail.com> | 2011-01-03 20:29:00 +0000 |
---|---|---|
committer | dom96 <dominikpicheta@googlemail.com> | 2011-01-03 20:29:00 +0000 |
commit | 958b1cb9769ec3176e40a8cd4ef33b2060b7074d (patch) | |
tree | 1136ce6ea0ba5d93e7c0af79f9664659822c0112 /tests/accept/compile | |
parent | 8ee63f98364259b2d1b6c02d050e0efccecbcf9b (diff) | |
download | Nim-958b1cb9769ec3176e40a8cd4ef33b2060b7074d.tar.gz |
Added a generics test case.
Diffstat (limited to 'tests/accept/compile')
-rw-r--r-- | tests/accept/compile/tgenericvariant.nim | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/accept/compile/tgenericvariant.nim b/tests/accept/compile/tgenericvariant.nim new file mode 100644 index 000000000..51d01355a --- /dev/null +++ b/tests/accept/compile/tgenericvariant.nim @@ -0,0 +1,23 @@ +type + TMaybe[T] = object + case empty: Bool + of False: value: T + else: nil + +proc Just*[T](val: T): TMaybe[T] = + result.empty = False + result.value = val + +proc Nothing[T](): TMaybe[T] = + result.empty = True + +proc safeReadLine(): TMaybe[string] = + var r = stdin.readLine() + if r == "": return Nothing[string]() + else: return Just(r) + +when isMainModule: + var Test = Just("Test") + echo(Test.value) + var mSomething = safeReadLine() + echo(mSomething.value) |