From 20b5f31c03fb556ec0aa2428a40adbac004d8987 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 13 Jan 2014 02:10:03 +0100 Subject: new tester; all tests categorized --- tests/generics/tgenericshardcases.nim | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/generics/tgenericshardcases.nim (limited to 'tests/generics/tgenericshardcases.nim') diff --git a/tests/generics/tgenericshardcases.nim b/tests/generics/tgenericshardcases.nim new file mode 100644 index 000000000..2ef63bc20 --- /dev/null +++ b/tests/generics/tgenericshardcases.nim @@ -0,0 +1,36 @@ +discard """ + file: "tgenericshardcases.nim" + output: "2\n5\n126\n3" +""" + +import typetraits + +proc typeNameLen(x: typedesc): int {.compileTime.} = + result = x.name.len + +macro selectType(a, b: typedesc): typedesc = + result = a + +type + Foo[T] = object + data1: array[T.high, int] + data2: array[typeNameLen(T), float] # data3: array[0..T.typeNameLen, selectType(float, int)] + + MyEnum = enum A, B, C, D + +var f1: Foo[MyEnum] +var f2: Foo[int8] + +echo high(f1.data1) # (D = 3) - 1 == 2 +echo high(f1.data2) # (MyEnum.len = 6) - 1 == 5 + +echo high(f2.data1) # 127 - 1 == 126 +echo high(f2.data2) # int8.len - 1 == 3 + +#static: +# assert high(f1.data1) == ord(D) +# assert high(f1.data2) == 6 # length of MyEnum + +# assert high(f2.data1) == 127 +# assert high(f2.data2) == 4 # length of int8 + -- cgit 1.4.1-2-gfad0 .nim?h=devel&id=1c0c80ef2dba09bb50c470a013f3bdb9391620a7'>blame commit diff stats
path: root/examples/htmltitle.nim
blob: f3c67238292dc81eab55209fef527c039b7682b7 (plain) (tree)
1
2
3
4
5
6
7
8
9