diff options
author | metagn <metagngn@gmail.com> | 2023-06-06 07:54:07 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-06 06:54:07 +0200 |
commit | b97d603cd00a210547bda1a2a1c3e09f97fcc49e (patch) | |
tree | 080b4ad7b5826b88a9483c6a0e4d697096f12cc1 /tests/system/tfields.nim | |
parent | 2ab948ce53e3d9b80bf9b02644c8ec8991f34d0a (diff) | |
download | Nim-b97d603cd00a210547bda1a2a1c3e09f97fcc49e.tar.gz |
some test cleanups & category reorganization (#22010)
* clean up some test categories * mention exact slice issue * magics into system * move trangechecks into overflow * move tmemory to system * try fix CI * try fix CI * final CI fix
Diffstat (limited to 'tests/system/tfields.nim')
-rw-r--r-- | tests/system/tfields.nim | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/system/tfields.nim b/tests/system/tfields.nim new file mode 100644 index 000000000..0bf3a4e1a --- /dev/null +++ b/tests/system/tfields.nim @@ -0,0 +1,108 @@ +discard """ + output: ''' +n +n +(one: 1, two: 2, three: 3) +1 +2 +3 +(one: 4, two: 5, three: 6) +4 +(one: 7, two: 8, three: 9) +7 +8 +9 +(foo: 38, other: "string here") +43 +100 +90 +''' +""" + + +block tindex: + type + TMyTuple = tuple[a, b: int] + + proc indexOf(t: typedesc, name: string): int = + ## takes a tuple and looks for the field by name. + ## returs index of that field. + var + d: t + i = 0 + for n, x in fieldPairs(d): + if n == name: return i + i.inc + raise newException(ValueError, "No field " & name & " in type " & + astToStr(t)) + + doAssert TMyTuple.indexOf("b") == 1 + + + +block ttemplate: + # bug #1902 + # This works. + for name, value in (n: "v").fieldPairs: + echo name + + template wrapper(): void = + for name, value in (n: "v").fieldPairs: + echo name + wrapper() + + + +block tbreak: + # bug #2134 + type + TestType = object + one: int + two: int + three: int + + var + ab = TestType(one:1, two:2, three:3) + ac = TestType(one:4, two:5, three:6) + ad = TestType(one:7, two:8, three:9) + tstSeq = [ab, ac, ad] + + for tstElement in mitems(tstSeq): + echo tstElement + for tstField in fields(tstElement): + #for tstField in [1,2,4,6]: + echo tstField + if tstField == 4: + break + + + +block timplicit_with_partial: + type + Base = ref object of RootObj + Foo {.partial.} = ref object of Base + + proc my(f: Foo) = + #var f.next = f + let f.foo = 38 + let f.other = "string here" + echo f[] + echo f.foo + 5 + + var g: Foo + new(g) + my(g) + + type + FooTask {.partial.} = ref object of RootObj + + proc foo(t: FooTask) {.liftLocals: t.} = + var x = 90 + if true: + var x = 10 + while x < 100: + inc x + echo x + echo x + + foo(FooTask()) \ No newline at end of file |