ye
All checks were successful
Build / build (push) Successful in 1m36s
Test / build (push) Successful in 5m51s

This commit is contained in:
2026-01-18 23:17:26 +01:00
parent 9868b34f92
commit 0f35c35fd1
9 changed files with 187 additions and 143 deletions

30
test/arrays.zig git.filemode.normal_file
View File

@@ -0,0 +1,30 @@
const std = @import("std");
const root = @import("root.zig");
const compileNzsl = root.compileNzsl;
const case = root.case;
test "Simple array" {
const allocator = std.testing.allocator;
const shader =
\\ [nzsl_version("1.1")]
\\ module;
\\
\\ struct FragOut
\\ {
\\ [location(0)] color: vec4[f32]
\\ }
\\
\\ [entry(frag)]
\\ fn main() -> FragOut
\\ {
\\ let value = array[f32](4.0, 3.0, 2.0, 1.0);
\\ let output: FragOut;
\\ output.color = vec4[f32](value[0], value[1], value[2], value[3]);
\\ return output;
\\ }
;
const code = try compileNzsl(allocator, shader);
defer allocator.free(code);
try case.expectOutput(f32, 4, code, "color", &.{ 4, 3, 2, 1 });
}

View File

@@ -3,51 +3,6 @@ const root = @import("root.zig");
const compileNzsl = root.compileNzsl;
const case = root.case;
test "Simple for loop" {
const allocator = std.testing.allocator;
const base = @mod(case.random(f32), 5.0);
const iterations = 5;
var expected = base;
for (1..iterations) |i| {
expected *= @floatFromInt(i);
}
const shader = try std.fmt.allocPrint(
allocator,
\\ [nzsl_version("1.1")]
\\ [feature(float64)]
\\ module;
\\
\\ struct FragOut
\\ {{
\\ [location(0)] color: vec4[f32]
\\ }}
\\
\\ [entry(frag)]
\\ fn main() -> FragOut
\\ {{
\\ let value = f32({d});
\\ for i in 1 -> {d}
\\ {{
\\ value *= f32(i);
\\ }}
\\ let output: FragOut;
\\ output.color = vec4[f32](value, value, value, value);
\\ return output;
\\ }}
,
.{
base,
iterations,
},
);
defer allocator.free(shader);
const code = try compileNzsl(allocator, shader);
defer allocator.free(code);
try case.expectOutput(f32, 4, code, "color", &.{ expected, expected, expected, expected });
}
test "Simple while loop" {
const allocator = std.testing.allocator;
const base = @mod(case.random(f32), 5.0);

View File

@@ -56,6 +56,7 @@ pub const case = struct {
};
test {
std.testing.refAllDecls(@import("arrays.zig"));
std.testing.refAllDecls(@import("basics.zig"));
std.testing.refAllDecls(@import("branching.zig"));
std.testing.refAllDecls(@import("casts.zig"));