aboutsummaryrefslogtreecommitdiff
path: root/examples/monorepo/packages/beta/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/monorepo/packages/beta/src')
-rw-r--r--examples/monorepo/packages/beta/src/lib.zig44
1 files changed, 44 insertions, 0 deletions
diff --git a/examples/monorepo/packages/beta/src/lib.zig b/examples/monorepo/packages/beta/src/lib.zig
new file mode 100644
index 0000000..690b38c
--- /dev/null
+++ b/examples/monorepo/packages/beta/src/lib.zig
@@ -0,0 +1,44 @@
+// findNearestZigBuildDir walk-up test:
+//
+// When this file is the active editor in Nova, the "Current Zig File" clean
+// action calls findNearestZigBuildDir starting at packages/beta/src/.
+// It finds packages/beta/build.zig after one walk step and uses that
+// directory as the working directory — NOT the monorepo root build.zig.
+//
+// To verify: open this file, trigger clean, observe the task console shows
+// the beta package directory, not the monorepo root.
+const std = @import("std");
+
+/// Halve a value (integer division, truncated toward zero).
+pub fn halve(x: i32) i32 {
+ return @divTrunc(x, 2);
+}
+
+/// Negate a value.
+pub fn negate(x: i32) i32 {
+ return -x;
+}
+
+/// Absolute value.
+pub fn abs(x: i32) i32 {
+ return if (x < 0) -x else x;
+}
+
+test "beta: halve" {
+ try std.testing.expectEqual(@as(i32, 3), halve(6));
+ try std.testing.expectEqual(@as(i32, 3), halve(7)); // truncated
+ try std.testing.expectEqual(@as(i32, -2), halve(-5));
+ try std.testing.expectEqual(@as(i32, 0), halve(0));
+}
+
+test "beta: negate" {
+ try std.testing.expectEqual(@as(i32, -7), negate(7));
+ try std.testing.expectEqual(@as(i32, 7), negate(-7));
+ try std.testing.expectEqual(@as(i32, 0), negate(0));
+}
+
+test "beta: abs" {
+ try std.testing.expectEqual(@as(i32, 5), abs(5));
+ try std.testing.expectEqual(@as(i32, 5), abs(-5));
+ try std.testing.expectEqual(@as(i32, 0), abs(0));
+}