master
1const builtin = @import("builtin");
2const Id = @import("export_c_keywords.zig").Id;
3const std = @import("std");
4
5extern var int: Id;
6extern var long: Id;
7extern var an_alias_of_int: Id;
8
9extern var some_non_c_keyword_variable: Id;
10extern var @"void": Id;
11extern var an_alias_of_some_non_c_keyword_variable: Id;
12
13extern const @"if": Id;
14extern const @"else": Id;
15extern const an_alias_of_if: Id;
16
17extern const some_non_c_keyword_constant: Id;
18extern const @"switch": Id;
19extern const an_alias_of_some_non_c_keyword_constant: Id;
20
21extern fn float() Id;
22extern fn double() Id;
23extern fn an_alias_of_float() Id;
24
25extern fn some_non_c_keyword_function() Id;
26extern fn @"break"() Id;
27extern fn an_alias_of_some_non_c_keyword_function() Id;
28
29test "import c keywords" {
30 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
31 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
32 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest;
33 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
34 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
35
36 try std.testing.expect(int == .c_keyword_variable);
37 try std.testing.expect(long == .c_keyword_variable);
38 try std.testing.expect(an_alias_of_int == .c_keyword_variable);
39
40 try std.testing.expect(some_non_c_keyword_variable == .non_c_keyword_variable);
41 try std.testing.expect(@"void" == .non_c_keyword_variable);
42 try std.testing.expect(an_alias_of_some_non_c_keyword_variable == .non_c_keyword_variable);
43
44 try std.testing.expect(@"if" == .c_keyword_constant);
45 try std.testing.expect(@"else" == .c_keyword_constant);
46 try std.testing.expect(an_alias_of_if == .c_keyword_constant);
47
48 try std.testing.expect(some_non_c_keyword_constant == .non_c_keyword_constant);
49 try std.testing.expect(@"switch" == .non_c_keyword_constant);
50 try std.testing.expect(an_alias_of_some_non_c_keyword_constant == .non_c_keyword_constant);
51
52 try std.testing.expect(float() == .c_keyword_function);
53 try std.testing.expect(double() == .c_keyword_function);
54 try std.testing.expect(an_alias_of_float() == .c_keyword_function);
55
56 try std.testing.expect(some_non_c_keyword_function() == .non_c_keyword_function);
57 try std.testing.expect(@"break"() == .non_c_keyword_function);
58 try std.testing.expect(an_alias_of_some_non_c_keyword_function() == .non_c_keyword_function);
59
60 var ptr_id: *const Id = &long;
61 try std.testing.expect(ptr_id == &int);
62 ptr_id = &an_alias_of_int;
63 try std.testing.expect(ptr_id == &int);
64
65 ptr_id = &@"void";
66 try std.testing.expect(ptr_id == &some_non_c_keyword_variable);
67 ptr_id = &an_alias_of_some_non_c_keyword_variable;
68 try std.testing.expect(ptr_id == &some_non_c_keyword_variable);
69
70 ptr_id = &@"else";
71 try std.testing.expect(ptr_id == &@"if");
72 ptr_id = &an_alias_of_if;
73 try std.testing.expect(ptr_id == &@"if");
74
75 ptr_id = &@"switch";
76 try std.testing.expect(ptr_id == &some_non_c_keyword_constant);
77 ptr_id = &an_alias_of_some_non_c_keyword_constant;
78 try std.testing.expect(ptr_id == &some_non_c_keyword_constant);
79
80 if (builtin.target.ofmt != .coff and builtin.target.os.tag != .windows) {
81 var ptr_fn: *const fn () callconv(.c) Id = &double;
82 try std.testing.expect(ptr_fn == &float);
83 ptr_fn = &an_alias_of_float;
84 try std.testing.expect(ptr_fn == &float);
85
86 ptr_fn = &@"break";
87 try std.testing.expect(ptr_fn == &some_non_c_keyword_function);
88 ptr_fn = &an_alias_of_some_non_c_keyword_function;
89 try std.testing.expect(ptr_fn == &some_non_c_keyword_function);
90 }
91}