Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Sep 7, 2022
1 parent fb3e40e commit 1d04557
Show file tree
Hide file tree
Showing 22 changed files with 398 additions and 3 deletions.
13 changes: 13 additions & 0 deletions tests/expectations/opaque.zig
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion tests/expectations/pin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions tests/expectations/pragma_once.zig
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
const std = @import("std");

pub extern fn root() anyopaque;
19 changes: 19 additions & 0 deletions tests/expectations/prefixed_struct_literal_deep.zig
Original file line number Diff line number Diff line change
@@ -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),
}),
});
20 changes: 20 additions & 0 deletions tests/expectations/rename_crate.zig
Original file line number Diff line number Diff line change
@@ -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;
1 change: 0 additions & 1 deletion tests/expectations/rename_crates.zig

This file was deleted.

11 changes: 11 additions & 0 deletions tests/expectations/renaming_overrides_prefixing.zig
Original file line number Diff line number Diff line change
@@ -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;
36 changes: 36 additions & 0 deletions tests/expectations/sentinel.zig
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions tests/expectations/simplify_option_ptr.zig
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions tests/expectations/size_types.zig
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions tests/expectations/static.zig
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 8 additions & 0 deletions tests/expectations/std_lib.zig
Original file line number Diff line number Diff line change
@@ -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;
30 changes: 30 additions & 0 deletions tests/expectations/struct.zig
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 24 additions & 1 deletion tests/expectations/struct_literal.zig
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 12 additions & 0 deletions tests/expectations/struct_self.zig
Original file line number Diff line number Diff line change
@@ -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;
48 changes: 48 additions & 0 deletions tests/expectations/swift_name.zig
Original file line number Diff line number Diff line change
@@ -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;
92 changes: 92 additions & 0 deletions tests/expectations/transform_op.zig
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 1d04557

Please sign in to comment.