| 1 | const builtin = @import("builtin"); |
| 2 | const Id = @import("export_c_keywords.zig").Id; |
| 3 | const std = @import("std"); |
| 4 | |
| 5 | extern var int: Id; |
| 6 | extern var long: Id; |
| 7 | extern var an_alias_of_int: Id; |
| 8 | |
| 9 | extern var some_non_c_keyword_variable: Id; |
| 10 | extern var @"void": Id; |
| 11 | extern var an_alias_of_some_non_c_keyword_variable: Id; |
| 12 | |
| 13 | extern const @"if": Id; |
| 14 | extern const @"else": Id; |
| 15 | extern const an_alias_of_if: Id; |
| 16 | |
| 17 | extern const some_non_c_keyword_constant: Id; |
| 18 | extern const @"switch": Id; |
| 19 | extern const an_alias_of_some_non_c_keyword_constant: Id; |
| 20 | |
| 21 | extern fn float() Id; |
| 22 | extern fn double() Id; |
| 23 | extern fn an_alias_of_float() Id; |
| 24 | |
| 25 | extern fn some_non_c_keyword_function() Id; |
| 26 | extern fn @"break"() Id; |
| 27 | extern fn an_alias_of_some_non_c_keyword_function() Id; |
| 28 | |
| 29 | test "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 | } |