authorgravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-07 20:08:28+01:00
committergravatar for r00ster91@proton.meWooster <r00ster91@proton.me> 2022-12-10 12:34:42+01:00
log7a8f7dcb8c25d4c78ac8f1190ab8e163ff1cb80d
treeeaffd7ce54c9db895afd56170769ec21c9f55cdc
parent01947bfe9205a1ab49137c5c30e134ba81365092

behavior: add test coverage for corrupted slice in release

Closes #7325

2 files changed, 114 insertions(+), 0 deletions(-)

test/behavior.zig+1
...@@ -68,6 +68,7 @@ test {...@@ -68,6 +68,7 @@ test {
68 _ = @import("behavior/bugs/7003.zig");68 _ = @import("behavior/bugs/7003.zig");
69 _ = @import("behavior/bugs/7047.zig");69 _ = @import("behavior/bugs/7047.zig");
70 _ = @import("behavior/bugs/7187.zig");70 _ = @import("behavior/bugs/7187.zig");
71 _ = @import("behavior/bugs/7325.zig");
71 _ = @import("behavior/bugs/9584.zig");72 _ = @import("behavior/bugs/9584.zig");
72 _ = @import("behavior/bugs/10138.zig");73 _ = @import("behavior/bugs/10138.zig");
73 _ = @import("behavior/bugs/10147.zig");74 _ = @import("behavior/bugs/10147.zig");
test/behavior/bugs/7325.zig created+113
...@@ -0,0 +1,113 @@
1const std = @import("std");
2const builtin = @import("builtin");
3const testing = std.testing;
4
5const string = "hello world";
6
7const TempRef = struct {
8 index: usize,
9 is_weak: bool,
10};
11
12const BuiltinEnum = struct {
13 name: []const u8,
14};
15
16const ParamType = union(enum) {
17 boolean,
18 buffer,
19 one_of: BuiltinEnum,
20};
21
22const CallArg = struct {
23 value: Expression,
24};
25
26const Expression = union(enum) {
27 literal_boolean: bool,
28 literal_enum_value: EnumLiteral,
29};
30
31const EnumLiteral = struct {
32 label: []const u8,
33};
34
35const ExpressionResult = union(enum) {
36 temp_buffer: TempRef,
37 literal_boolean: bool,
38 literal_enum_value: []const u8,
39};
40
41fn commitCalleeParam(result: ExpressionResult, callee_param_type: ParamType) ExpressionResult {
42 switch (callee_param_type) {
43 .boolean => {
44 return result;
45 },
46 .buffer => {
47 return ExpressionResult{
48 .temp_buffer = .{ .index = 0, .is_weak = false },
49 };
50 },
51 .one_of => {
52 return result;
53 },
54 }
55}
56
57fn genExpression(expr: Expression) !ExpressionResult {
58 switch (expr) {
59 .literal_boolean => |value| {
60 return ExpressionResult{
61 .literal_boolean = value,
62 };
63 },
64 .literal_enum_value => |v| {
65 try testing.expectEqualStrings(string, v.label);
66 const result: ExpressionResult = .{
67 .literal_enum_value = v.label,
68 };
69 switch (result) {
70 .literal_enum_value => |w| {
71 try testing.expectEqualStrings(string, w);
72 },
73 else => {},
74 }
75 return result;
76 },
77 }
78}
79
80test {
81 if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
82 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
83 if (builtin.zig_backend == .stage2_x86) return error.SkipZigTest; // TODO
84 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
85 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
86
87 var param: ParamType = .{
88 .one_of = .{ .name = "name" },
89 };
90 var arg: CallArg = .{
91 .value = .{
92 .literal_enum_value = .{
93 .label = string,
94 },
95 },
96 };
97
98 const result = try genExpression(arg.value);
99 switch (result) {
100 .literal_enum_value => |w| {
101 try testing.expectEqualStrings(string, w);
102 },
103 else => {},
104 }
105
106 const derp = commitCalleeParam(result, param);
107 switch (derp) {
108 .literal_enum_value => |w| {
109 try testing.expectEqualStrings(string, w);
110 },
111 else => {},
112 }
113}