v2 / vlib / v / tests / comptime / comptime_attr_test.v
78 lines · 66 sloc · 878 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1@[bar; foo]
2fn abc() {
3}
4
5@[foo]
6struct Foo {
7}
8
9@[bar]
10fn Foo.bar() {
11}
12
13@[baz]
14enum EnumFoo {
15 a
16 b
17}
18
19@[iface]
20interface IFoo {
21}
22
23@[custom]
24type CustomType = EnumFoo | Foo
25
26fn test_main() {
27 mut c := 0
28 $for f in abc.attributes {
29 dump(f)
30 assert f.name in ['foo', 'bar']
31 c++
32 }
33 assert c == 2
34
35 $for f in Foo.attributes {
36 dump(f)
37 assert f.name == 'foo'
38 c++
39 }
40 assert c == 3
41
42 a := Foo.bar
43 $for f in a.attributes {
44 dump(f)
45 assert f.name == 'bar'
46 c++
47 }
48 assert c == 4
49
50 b := abc
51 $for f in b.attributes {
52 dump(f)
53 assert f.name in ['foo', 'bar']
54 c++
55 }
56 assert c == 6
57
58 $for f in EnumFoo.attributes {
59 dump(f)
60 assert f.name == 'baz'
61 c++
62 }
63 assert c == 7
64
65 $for f in IFoo.attributes {
66 dump(f)
67 assert f.name == 'iface'
68 c++
69 }
70 assert c == 8
71
72 $for f in CustomType.attributes {
73 dump(f)
74 assert f.name == 'custom'
75 c++
76 }
77 assert c == 9
78}
79