diff --git a/tests/expectations/opaque.zig b/tests/expectations/opaque.zig index 95a0b682a..7aa8c07f3 100644 --- a/tests/expectations/opaque.zig +++ b/tests/expectations/opaque.zig @@ -1 +1,14 @@ const std = @import("std"); + +const HashMap_i32__i32__BuildHasherDefault_DefaultHasher = opaque {}; + +const Result_Foo = opaque {}; + +/// Fast hash map used internally. +pub const FastHashMap_i32__i32 = HashMap_i32__i32__BuildHasherDefault_DefaultHasher; + +pub const Foo = FastHashMap_i32__i32; + +pub const Bar = Result_Foo; + +pub extern fn root(a: ?*Foo, b: ?*Bar) anyopaque; diff --git a/tests/expectations/pin.zig b/tests/expectations/pin.zig index 7e0594944..161d81bfa 100644 --- a/tests/expectations/pin.zig +++ b/tests/expectations/pin.zig @@ -5,4 +5,4 @@ pub const PinTest = extern struct { _pinned_ref: ?*i32, }; -extern fn root(_s: ?*i32, p: PinTest) anyopaque; +pub extern fn root(_s: ?*i32, p: PinTest) anyopaque; diff --git a/tests/expectations/pragma_once.zig b/tests/expectations/pragma_once.zig index 95a0b682a..d4c2e15c7 100644 --- a/tests/expectations/pragma_once.zig +++ b/tests/expectations/pragma_once.zig @@ -1 +1,3 @@ const std = @import("std"); + +pub extern fn root() anyopaque; diff --git a/tests/expectations/prefixed_struct_literal_deep.zig b/tests/expectations/prefixed_struct_literal_deep.zig index 95a0b682a..8bdf63994 100644 --- a/tests/expectations/prefixed_struct_literal_deep.zig +++ b/tests/expectations/prefixed_struct_literal_deep.zig @@ -1 +1,20 @@ const std = @import("std"); + +pub const PREFIXBar = extern struct { + a: i32, +}; +pub const PREFIXFoo = extern struct { + a: i32, + b: u32, + bar: PREFIXBar, +}; + +pub extern fn root(x: PREFIXFoo) anyopaque; + +pub const PREFIXVAL = @import("std").mem.zeroInit(PREFIXFoo, .{ + .a = @as(c_int, 42), + .b = @as(c_int, 1337), + .bar = @import("std").mem.zeroInit(PREFIXBar, .{ + .a = @as(c_int, 323), + }), +}); diff --git a/tests/expectations/rename_crate.zig b/tests/expectations/rename_crate.zig new file mode 100644 index 000000000..ba040f389 --- /dev/null +++ b/tests/expectations/rename_crate.zig @@ -0,0 +1,20 @@ +const std = @import("std"); + +pub const Foo = extern struct { + x: i32, +}; +pub const RenamedTy = extern struct { + y: u64, +}; +pub const NoExternTy = extern struct { + field: u8, +}; +pub const ContainsNoExternTy = extern struct { + field: NoExternTy, +}; + +pub extern fn root(a: Foo) anyopaque; + +pub extern fn renamed_func(a: RenamedTy) anyopaque; + +pub extern fn no_extern_func(a: ContainsNoExternTy) anyopaque; diff --git a/tests/expectations/rename_crates.zig b/tests/expectations/rename_crates.zig deleted file mode 100644 index 95a0b682a..000000000 --- a/tests/expectations/rename_crates.zig +++ /dev/null @@ -1 +0,0 @@ -const std = @import("std"); diff --git a/tests/expectations/renaming_overrides_prefixing.zig b/tests/expectations/renaming_overrides_prefixing.zig index 95a0b682a..72dace5fc 100644 --- a/tests/expectations/renaming_overrides_prefixing.zig +++ b/tests/expectations/renaming_overrides_prefixing.zig @@ -1 +1,12 @@ const std = @import("std"); + +const A = opaque { + +}; + +pub const B = extern struct { + x: i32, + y: f32, +}; + +pub extern fn root( a: ?*A, b: B) anyopaque; diff --git a/tests/expectations/sentinel.zig b/tests/expectations/sentinel.zig index 95a0b682a..409ea7932 100644 --- a/tests/expectations/sentinel.zig +++ b/tests/expectations/sentinel.zig @@ -1 +1,37 @@ const std = @import("std"); + +pub const A = enum { + A1, + A2, + A3, +}; + +pub const B = enum { + B1, + B2, + B3, +}; + +pub const C_Tag = enum { + C1, + C2, + C3, +}; + +pub const C1_Body = extern struct { + tag: C_Tag, + a: u32, +}; + +pub const C2_Body = extern struct { + tag: C_Tag, + b: u32, +}; + +pub const C = extern union { + tag: C_Tag, + c1: C1_Body, + c2: C2_Body, +}; + +pub extern fn root(a: A, b: B, c: C) anyopaque; diff --git a/tests/expectations/simplify_option_ptr.zig b/tests/expectations/simplify_option_ptr.zig index 95a0b682a..1f9e5c82b 100644 --- a/tests/expectations/simplify_option_ptr.zig +++ b/tests/expectations/simplify_option_ptr.zig @@ -1 +1,20 @@ const std = @import("std"); + +pub const Opaque = opaque {}; +pub const Option_____Opaque = opaque {}; + +pub const Foo = extern struct { + x: ?*const Opaque, + y: ?*Opaque, + z: ?*const fn () anyopaque, + zz: [*]?*const fn () anyopaque, +}; + +pub const Bar = extern union { + x: ?*const Opaque, + y: ?*Opaque, + z: ?*const fn () anyopaque, + zz: [*]?*const fn () anyopaque, +}; + +pub extern fn root(a: ?*const Opaque, b: ?*Opaque, c: Foo, d: Bar, e: ?*Option_____Opaque, f: ?*const fn (?*const Opaque) anyopaque) anyopaque; diff --git a/tests/expectations/size_types.zig b/tests/expectations/size_types.zig index 95a0b682a..e0cd28725 100644 --- a/tests/expectations/size_types.zig +++ b/tests/expectations/size_types.zig @@ -1 +1,15 @@ const std = @import("std"); + +pub const IE = enum { + IV, +}; + +pub const UE = enum { + UV, +}; + +pub const Usize = usize; + +pub const Isize = isize; + +pub extern fn root(Usize, Isize, UE, IE) anyopaque; diff --git a/tests/expectations/static.zig b/tests/expectations/static.zig index 95a0b682a..1b2ebcccb 100644 --- a/tests/expectations/static.zig +++ b/tests/expectations/static.zig @@ -1 +1,13 @@ const std = @import("std"); + +const Bar = opaque {}; + +pub const Foo = extern struct {}; + +pub extern const NUMBER: i32; + +pub extern const FOO: Foo; + +pub extern const BAR: Bar; + +pub extern fn root() anyopaque; diff --git a/tests/expectations/std_lib.zig b/tests/expectations/std_lib.zig index 95a0b682a..5af07d1ff 100644 --- a/tests/expectations/std_lib.zig +++ b/tests/expectations/std_lib.zig @@ -1 +1,9 @@ const std = @import("std"); + +const Option_i32 = opaque {}; + +const Result_i32__String = opaque {}; + +const Vec_String = opaque {}; + +pub extern fn root(a: ?*Vec_String, b: ?*Option_i32, c: ?*Result_i32__String) anyopaque; diff --git a/tests/expectations/struct.zig b/tests/expectations/struct.zig index 95a0b682a..b14ced846 100644 --- a/tests/expectations/struct.zig +++ b/tests/expectations/struct.zig @@ -1 +1,31 @@ const std = @import("std"); + +const Opaque = opaque { + +}; + +pub const Normal = extern struct { + x: i32, + y: f32, +}; + +pub const NormalWithZST = extern struct { + x: i32, + y: f32, +}; + +pub const TupleRenamed = extern struct { + m0: i32, + m1: f32, +}; + +pub const TupleNamed = extern struct { + x: i32, + y: f32, +}; + +pub extern fn root( a: ?*Opaque, + b: Normal, + c: NormalWithZST, + d: TupleRenamed, + e: TupleNamed) anyopaque; diff --git a/tests/expectations/struct_literal.zig b/tests/expectations/struct_literal.zig index 95a0b682a..2cb5b0308 100644 --- a/tests/expectations/struct_literal.zig +++ b/tests/expectations/struct_literal.zig @@ -1 +1,24 @@ -const std = @import("std"); +pub const Bar = opaque {}; +pub const Foo = extern struct { + a: i32, + b: u32, +}; + +pub const Foo_FOO = @import("std").mem.zeroInit(Foo, .{ + .a = @as(c_int, 42), + .b = @as(c_int, 47), +}); +pub const Foo_FOO2 = @import("std").mem.zeroInit(Foo, .{ + .a = @as(c_int, 42), + .b = @as(c_int, 47), +}); +pub const Foo_FOO3 = @import("std").mem.zeroInit(Foo, .{ + .a = @as(c_int, 42), + .b = @as(c_int, 47), +}); +pub const BAR = @import("std").mem.zeroInit(Foo, .{ + .a = @as(c_int, 42), + .b = @as(c_int, 1337), +}); + +pub extern fn root(x: Foo, bar: Bar) void; diff --git a/tests/expectations/struct_self.zig b/tests/expectations/struct_self.zig new file mode 100644 index 000000000..e9e179f30 --- /dev/null +++ b/tests/expectations/struct_self.zig @@ -0,0 +1,12 @@ +const std = @import("std"); + +pub const Foo_Bar = extern struct { + something: ?*i32, +}; + +pub const Bar = extern struct { + something: i32, + subexpressions: Foo_Bar, +}; + +pub extern fn root(b: Bar) anyopaque; diff --git a/tests/expectations/swift_name.zig b/tests/expectations/swift_name.zig index 95a0b682a..24351d4f6 100644 --- a/tests/expectations/swift_name.zig +++ b/tests/expectations/swift_name.zig @@ -1 +1,49 @@ const std = @import("std"); + +pub const Opaque = opaque {}; + +pub const SelfTypeTestStruct = extern struct { + times: u8, +}; + +pub const PointerToOpaque = extern struct { + ptr: ?*Opaque, +}; + +pub extern fn rust_print_hello_world() anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_ref(self: [*]const SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_ref_mut(self: [*]SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_not_exist_box(self: [*]SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_not_exist_return_box() [*]SelfTypeTestStruct; + +pub extern fn SelfTypeTestStruct_should_exist_annotated_self(self: SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_annotated_mut_self(self: SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_annotated_by_name(self: SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_annotated_mut_by_name(self: SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_unannotated(self: SelfTypeTestStruct) anyopaque; + +pub extern fn SelfTypeTestStruct_should_exist_mut_unannotated(self: SelfTypeTestStruct) anyopaque; + +pub extern fn free_function_should_exist_ref(test_struct: [*]const SelfTypeTestStruct) anyopaque; + +pub extern fn free_function_should_exist_ref_mut(test_struct: [*]SelfTypeTestStruct) anyopaque; + +pub extern fn unnamed_argument([*]SelfTypeTestStruct) anyopaque; + +pub extern fn free_function_should_not_exist_box(boxed: [*]SelfTypeTestStruct) anyopaque; + +pub extern fn free_function_should_exist_annotated_by_name(test_struct: SelfTypeTestStruct) anyopaque; + +pub extern fn free_function_should_exist_annotated_mut_by_name(test_struct: SelfTypeTestStruct) anyopaque; + +pub extern fn PointerToOpaque_create(times: u8) PointerToOpaque; + +pub extern fn PointerToOpaque_sayHello(self: PointerToOpaque) anyopaque; diff --git a/tests/expectations/transform_op.zig b/tests/expectations/transform_op.zig index 95a0b682a..c99bd318a 100644 --- a/tests/expectations/transform_op.zig +++ b/tests/expectations/transform_op.zig @@ -1 +1,93 @@ const std = @import("std"); + +pub const Point_i32 = extern struct { + x: i32, + y: i32, +}; + +pub const Point_f32 = extern struct { + x: f32, + y: f32, +}; + +pub const Foo_i32_Tag = enum { + Foo_i32, + Bar_i32, + Baz_i32, + Bazz_i32, +}; + +pub const Foo_Body_i32 = extern struct { + tag: Foo_i32_Tag, + x: i32, + y: Point_i32, + z: Point_f32, +}; + +pub const Foo_i32 = extern union { + tag: Foo_i32_Tag, + foo: Foo_Body_i32, +}; + +pub const Bar_i32_Tag = enum { + Bar1_i32, + Bar2_i32, + Bar3_i32, + Bar4_i32, +}; + +pub const Bar1_Body_i32 = extern struct { + x: i32, + y: Point_i32, + z: Point_f32, + u: ?fn () i32, +}; + +pub const Bar_i32 = extern struct { + tag: Bar_i32_Tag, +}; + +pub const Point_u32 = extern struct { + x: u32, + y: u32, +}; + +pub const Bar_u32_Tag = enum { + Bar1_u32, + Bar2_u32, + Bar3_u32, + Bar4_u32, +}; + +pub const Bar1_Body_u32 = extern struct { + x: i32, + y: Point_u32, + z: Point_f32, + u: ?fn () i32, +}; + +pub const Bar_u32 = extern struct { + tag: Bar_u32_Tag, +}; + +pub const Baz_Tag = enum { + Baz1, + Baz2, + Baz3, +}; + +pub const Baz = extern union { + tag: Baz_Tag, +}; + +pub const Taz_Tag = enum { + Taz1, + Taz2, + Taz3, +}; + +pub const Taz = extern struct { + tag: Taz_Tag, +}; + +pub extern fn foo(foo: ?*Foo_i32, bar: ?*Bar_i32, baz: ?*Baz, taz: ?*Taz) anyopaque; diff --git a/tests/expectations/union.zig b/tests/expectations/union.zig index 95a0b682a..4f251c11e 100644 --- a/tests/expectations/union.zig +++ b/tests/expectations/union.zig @@ -1 +1,15 @@ const std = @import("std"); + +const Opaque = opaque {}; + +pub const Normal = extern union { + x: i32, + y: f32, +}; + +pub const NormalWithZST = extern union { + x: i32, + y: f32, +}; + +pub extern fn root(a: ?*Opaque, b: Normal, c: NormalWithZST) anyopaque; diff --git a/tests/expectations/union_self.zig b/tests/expectations/union_self.zig new file mode 100644 index 000000000..8b85870b7 --- /dev/null +++ b/tests/expectations/union_self.zig @@ -0,0 +1,12 @@ +const std = @import("std"); + +pub const Foo_Bar = extern struct { + something: ?*i32, +}; + +pub const Bar = extern union { + something: i32, + subexpressions: Foo_Bar, +}; + +pub extern fn root(b: Bar) anyopaque; diff --git a/tests/expectations/using_namespaces.zig b/tests/expectations/using_namespaces.zig new file mode 100644 index 000000000..d4c2e15c7 --- /dev/null +++ b/tests/expectations/using_namespaces.zig @@ -0,0 +1,3 @@ +const std = @import("std"); + +pub extern fn root() anyopaque; diff --git a/tests/expectations/va_list.zig b/tests/expectations/va_list.zig index 95a0b682a..9e7a71bf8 100644 --- a/tests/expectations/va_list.zig +++ b/tests/expectations/va_list.zig @@ -1 +1,3 @@ const std = @import("std"); + +pub extern fn va_list_test(ap: ...) i32; diff --git a/tests/expectations/workspace.zig b/tests/expectations/workspace.zig index 95a0b682a..72f50096d 100644 --- a/tests/expectations/workspace.zig +++ b/tests/expectations/workspace.zig @@ -1 +1,7 @@ const std = @import("std"); + +pub const ExtType = extern struct { + data: u32, +}; + +pub extern fn consume_ext(_ext: ExtType) anyopaque;