working on function calls; ci skip
This commit is contained in:
62
test/casts.zig
git.filemode.normal_file
62
test/casts.zig
git.filemode.normal_file
@@ -0,0 +1,62 @@
|
||||
const std = @import("std");
|
||||
const root = @import("root.zig");
|
||||
const compileNzsl = root.compileNzsl;
|
||||
const case = root.case;
|
||||
|
||||
test "Primitives casts" {
|
||||
const allocator = std.testing.allocator;
|
||||
const types = [_][2]type{
|
||||
[2]type{ f32, u32 },
|
||||
[2]type{ f32, i32 },
|
||||
[2]type{ u32, f32 },
|
||||
[2]type{ u32, i32 },
|
||||
[2]type{ i32, f32 },
|
||||
[2]type{ i32, u32 },
|
||||
[2]type{ f32, f64 },
|
||||
[2]type{ f64, f32 },
|
||||
[2]type{ f64, u32 },
|
||||
[2]type{ f64, i32 },
|
||||
[2]type{ u32, f64 },
|
||||
[2]type{ i32, f64 },
|
||||
};
|
||||
|
||||
inline for (types) |T| {
|
||||
const base = case.random(T[0]);
|
||||
const expected = std.math.lossyCast(T[1], base);
|
||||
|
||||
const shader = try std.fmt.allocPrint(
|
||||
allocator,
|
||||
\\ [nzsl_version("1.1")]
|
||||
\\ [feature(float64)]
|
||||
\\ module;
|
||||
\\
|
||||
\\ struct FragOut
|
||||
\\ {{
|
||||
\\ [location(0)] color: vec4[{s}]
|
||||
\\ }}
|
||||
\\
|
||||
\\ [entry(frag)]
|
||||
\\ fn main() -> FragOut
|
||||
\\ {{
|
||||
\\ let base = {s}({d});
|
||||
\\ let color = {s}(base);
|
||||
\\
|
||||
\\ let output: FragOut;
|
||||
\\ output.color = vec4[{s}](color, color, color, color);
|
||||
\\ return output;
|
||||
\\ }}
|
||||
,
|
||||
.{
|
||||
@typeName(T[1]),
|
||||
@typeName(T[0]),
|
||||
base,
|
||||
@typeName(T[1]),
|
||||
@typeName(T[1]),
|
||||
},
|
||||
);
|
||||
defer allocator.free(shader);
|
||||
const code = try compileNzsl(allocator, shader);
|
||||
defer allocator.free(code);
|
||||
try case.expectOutput(T[1], 4, code, "color", &.{ expected, expected, expected, expected });
|
||||
}
|
||||
}
|
||||
@@ -58,5 +58,6 @@ pub const case = struct {
|
||||
test {
|
||||
std.testing.refAllDecls(@import("basics.zig"));
|
||||
std.testing.refAllDecls(@import("branching.zig"));
|
||||
std.testing.refAllDecls(@import("casts.zig"));
|
||||
std.testing.refAllDecls(@import("maths.zig"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user