Skip to content

Commit 4baa6cd

Browse files
authored
tests: add more tests for importing @Keyword as function names, and for V enums with c++ keyword field names (#23696)
1 parent 6ed56ee commit 4baa6cd

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
enum MyEnum {
2+
catch
3+
class
4+
dynamic_cast
5+
static_cast
6+
operator
7+
virtual
8+
}
9+
10+
fn test_cpp_keywords_used_as_enum_values() {
11+
e := MyEnum.class
12+
assert e.str() == 'class'
13+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import mymod { @as, @asm, @assert, @atomic, @break, @const, @continue, @defer, @else, @enum, @false, @fn, @for, @go, @goto, @if, @implements, @import, @in, @interface, @is, @isreftype, @lock, @match, @module, @mut, @or, @pub, @return, @rlock, @select, @shared, @sizeof, @spawn, @static, @struct, @true, @type, @typeof, @union, @unsafe, @volatile }
2+
3+
fn call_keywords() {
4+
@as()
5+
@asm()
6+
@assert()
7+
@atomic()
8+
@break()
9+
@const()
10+
@continue()
11+
@defer()
12+
@else()
13+
@enum()
14+
@false()
15+
@fn()
16+
@for()
17+
@go()
18+
@goto()
19+
@if()
20+
@implements()
21+
@import()
22+
@in()
23+
@interface()
24+
@is()
25+
@isreftype()
26+
@lock()
27+
@match()
28+
@module()
29+
@mut()
30+
@or()
31+
@pub()
32+
@return()
33+
@rlock()
34+
@select()
35+
@shared()
36+
@sizeof()
37+
@spawn()
38+
@static()
39+
@struct()
40+
@true()
41+
@type()
42+
@typeof()
43+
@union()
44+
@unsafe()
45+
@volatile()
46+
}
47+
48+
fn test_main() {
49+
call_keywords()
50+
assert true
51+
}
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
module mymod
2+
3+
pub fn @as() {
4+
println(@LOCATION)
5+
}
6+
7+
pub fn @asm() {
8+
println(@LOCATION)
9+
}
10+
11+
pub fn @assert() {
12+
println(@LOCATION)
13+
}
14+
15+
pub fn @atomic() {
16+
println(@LOCATION)
17+
}
18+
19+
pub fn @break() {
20+
println(@LOCATION)
21+
}
22+
23+
pub fn @const() {
24+
println(@LOCATION)
25+
}
26+
27+
pub fn @continue() {
28+
println(@LOCATION)
29+
}
30+
31+
pub fn @defer() {
32+
println(@LOCATION)
33+
}
34+
35+
pub fn @else() {
36+
println(@LOCATION)
37+
}
38+
39+
pub fn @enum() {
40+
println(@LOCATION)
41+
}
42+
43+
pub fn @false() {
44+
println(@LOCATION)
45+
}
46+
47+
pub fn @fn() {
48+
println(@LOCATION)
49+
}
50+
51+
pub fn @for() {
52+
println(@LOCATION)
53+
}
54+
55+
pub fn @go() {
56+
println(@LOCATION)
57+
}
58+
59+
pub fn @goto() {
60+
println(@LOCATION)
61+
}
62+
63+
pub fn @if() {
64+
println(@LOCATION)
65+
}
66+
67+
pub fn @implements() {
68+
println(@LOCATION)
69+
}
70+
71+
pub fn @import() {
72+
println(@LOCATION)
73+
}
74+
75+
pub fn @in() {
76+
println(@LOCATION)
77+
}
78+
79+
pub fn @interface() {
80+
println(@LOCATION)
81+
}
82+
83+
pub fn @is() {
84+
println(@LOCATION)
85+
}
86+
87+
pub fn @isreftype() {
88+
println(@LOCATION)
89+
}
90+
91+
pub fn @lock() {
92+
println(@LOCATION)
93+
}
94+
95+
pub fn @match() {
96+
println(@LOCATION)
97+
}
98+
99+
pub fn @module() {
100+
println(@LOCATION)
101+
}
102+
103+
pub fn @mut() {
104+
println(@LOCATION)
105+
}
106+
107+
pub fn @none() {
108+
println(@LOCATION)
109+
}
110+
111+
pub fn @or() {
112+
println(@LOCATION)
113+
}
114+
115+
pub fn @pub() {
116+
println(@LOCATION)
117+
}
118+
119+
pub fn @return() {
120+
println(@LOCATION)
121+
}
122+
123+
pub fn @rlock() {
124+
println(@LOCATION)
125+
}
126+
127+
pub fn @select() {
128+
println(@LOCATION)
129+
}
130+
131+
pub fn @shared() {
132+
println(@LOCATION)
133+
}
134+
135+
pub fn @sizeof() {
136+
println(@LOCATION)
137+
}
138+
139+
pub fn @spawn() {
140+
println(@LOCATION)
141+
}
142+
143+
pub fn @static() {
144+
println(@LOCATION)
145+
}
146+
147+
pub fn @struct() {
148+
println(@LOCATION)
149+
}
150+
151+
pub fn @true() {
152+
println(@LOCATION)
153+
}
154+
155+
pub fn @type() {
156+
println(@LOCATION)
157+
}
158+
159+
pub fn @typeof() {
160+
println(@LOCATION)
161+
}
162+
163+
pub fn @union() {
164+
println(@LOCATION)
165+
}
166+
167+
pub fn @unsafe() {
168+
println(@LOCATION)
169+
}
170+
171+
pub fn @volatile() {
172+
println(@LOCATION)
173+
}

vlib/v/tests/project_importing_v_keywords/v.mod

Whitespace-only changes.

0 commit comments

Comments
 (0)