diff options
author | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-01-13 02:10:03 +0100 |
commit | 20b5f31c03fb556ec0aa2428a40adbac004d8987 (patch) | |
tree | 58086941e7d6bb8f480ca1173a95722ada9435b2 /tests/converter | |
parent | 51ee524109cf7e3e86c676bc1676063a01bfd979 (diff) | |
download | Nim-20b5f31c03fb556ec0aa2428a40adbac004d8987.tar.gz |
new tester; all tests categorized
Diffstat (limited to 'tests/converter')
-rw-r--r-- | tests/converter/tconvcolors.nim | 5 | ||||
-rw-r--r-- | tests/converter/tconvert.nim | 46 | ||||
-rw-r--r-- | tests/converter/tgenericconverter.nim | 30 | ||||
-rw-r--r-- | tests/converter/ttypeconverter1.nim | 8 |
4 files changed, 89 insertions, 0 deletions
diff --git a/tests/converter/tconvcolors.nim b/tests/converter/tconvcolors.nim new file mode 100644 index 000000000..07e829550 --- /dev/null +++ b/tests/converter/tconvcolors.nim @@ -0,0 +1,5 @@ + +import colors + +echo int32(colWhite), 'A' + diff --git a/tests/converter/tconvert.nim b/tests/converter/tconvert.nim new file mode 100644 index 000000000..a8ddcf119 --- /dev/null +++ b/tests/converter/tconvert.nim @@ -0,0 +1,46 @@ +import + Cairo + +converter FloatConversion64(x: int): float64 = return toFloat(x) +converter FloatConversion32(x: int): float32 = return toFloat(x) +converter FloatConversionPlain(x: int): float = return toFloat(x) + +const width = 500 +const height = 500 +const outFile = "CairoTest.png" + +var surface = Cairo.ImageSurfaceCreate(CAIRO.FORMAT_RGB24, width, height) +var ç = Cairo.Create(surface) + +ç.SetSourceRGB(1, 1, 1) +ç.Paint() + +ç.SetLineWidth(10) +ç.SetLineCap(CAIRO.LINE_CAP_ROUND) + +const count = 12 +var winc = width / count +var hinc = width / count +for i in 1 .. count-1: + var amount = i / count + ç.SetSourceRGB(0, 1 - amount, amount) + ç.MoveTo(i * winc, hinc) + ç.LineTo(width - i * winc, height - hinc) + ç.Stroke() + + ç.SetSourceRGB(1 - amount, 0, amount) + ç.MoveTo(winc, i * hinc) + ç.LineTo(width - winc, height - i * hinc) + ç.Stroke() + +echo(surface.WriteToPNG(outFile)) +surface.Destroy() + +type TFoo = object + +converter toPtr*(some: var TFoo): ptr TFoo = (addr some) + + +proc zoot(x: ptr TFoo) = nil +var x: Tfoo +zoot(x) diff --git a/tests/converter/tgenericconverter.nim b/tests/converter/tgenericconverter.nim new file mode 100644 index 000000000..e1c9f7c4c --- /dev/null +++ b/tests/converter/tgenericconverter.nim @@ -0,0 +1,30 @@ +discard """ + output: '''666 +666''' +""" + +# test the new generic converters: + +type + TFoo2[T] = object + x: T + + TFoo[T] = object + data: array[0..100, T] + +converter toFoo[T](a: TFoo2[T]): TFoo[T] = + result.data[0] = a.x + +proc p(a: TFoo[int]) = + echo a.data[0] + +proc q[T](a: TFoo[T]) = + echo a.data[0] + + +var + aa: TFoo2[int] +aa.x = 666 + +p aa +q aa diff --git a/tests/converter/ttypeconverter1.nim b/tests/converter/ttypeconverter1.nim new file mode 100644 index 000000000..b9a5e88ae --- /dev/null +++ b/tests/converter/ttypeconverter1.nim @@ -0,0 +1,8 @@ + +converter p(i: int): bool = return i != 0 + +if 1: + echo if 4: "foo" else: "barr" +while 0: + echo "bar" + |