aboutsummaryrefslogtreecommitdiff
path: root/examples/hello-zig
diff options
context:
space:
mode:
authorDavid Czihak <git@dcz.at>2026-05-09 13:01:50 +0200
committerDavid Czihak <git@dcz.at>2026-05-09 13:01:50 +0200
commit4b6f66fd512c254b5a82220dc77411fe391dd258 (patch)
tree7d77d7966e9ad2e296986ea8cfeb607088028195 /examples/hello-zig
parent64e9c56fc665972fdde5234c4fb2f2a882e237dc (diff)
Chore: Rework examples for thorough extension testing
Diffstat (limited to 'examples/hello-zig')
-rw-r--r--examples/hello-zig/.editorconfig6
-rw-r--r--examples/hello-zig/.gitignore2
-rw-r--r--examples/hello-zig/.nova/Configuration.json8
-rw-r--r--examples/hello-zig/.nova/Tasks/Zig Debug.json12
-rw-r--r--examples/hello-zig/.nova/Tasks/Zig Package (macOS Terminal).json7
-rw-r--r--examples/hello-zig/.nova/Tasks/Zig Package.json8
-rw-r--r--examples/hello-zig/build.zig47
-rw-r--r--examples/hello-zig/build.zig.zon12
-rw-r--r--examples/hello-zig/src/main.zig32
-rw-r--r--examples/hello-zig/src/root.zig83
10 files changed, 0 insertions, 217 deletions
diff --git a/examples/hello-zig/.editorconfig b/examples/hello-zig/.editorconfig
deleted file mode 100644
index d5f8c65..0000000
--- a/examples/hello-zig/.editorconfig
+++ /dev/null
@@ -1,6 +0,0 @@
-root = true
-
-[*]
-indent_style = space
-indent_size = 4
-insert_final_newline = true
diff --git a/examples/hello-zig/.gitignore b/examples/hello-zig/.gitignore
deleted file mode 100644
index 3389c86..0000000
--- a/examples/hello-zig/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-.zig-cache/
-zig-out/
diff --git a/examples/hello-zig/.nova/Configuration.json b/examples/hello-zig/.nova/Configuration.json
deleted file mode 100644
index 47e341a..0000000
--- a/examples/hello-zig/.nova/Configuration.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "at.dcz.nova-zig.toolchain.lldb-dap-path" : "\/Library\/Developer\/CommandLineTools\/usr\/bin\/lldb-dap",
- "at.dcz.nova-zig.toolchain.zig-path" : "\/opt\/homebrew\/bin\/zig",
- "at.dcz.nova-zig.zls.build-on-save" : true,
- "at.dcz.nova-zig.zls.enabled" : true,
- "zls.enable_build_on_save" : true,
- "zls.zig_exe_path" : "\/opt\/homebrew\/bin\/zig"
-}
diff --git a/examples/hello-zig/.nova/Tasks/Zig Debug.json b/examples/hello-zig/.nova/Tasks/Zig Debug.json
deleted file mode 100644
index 53b7f13..0000000
--- a/examples/hello-zig/.nova/Tasks/Zig Debug.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "extension" : {
- "identifier" : "at.dcz.nova-zig",
- "name" : "Zig"
- },
- "extensionTemplate" : "zigDebug",
- "extensionValues" : {
- "console" : "internalConsole",
- "programPath" : "zig-out\/bin\/hello-zig"
- },
- "openLogOnRun" : "start"
-}
diff --git a/examples/hello-zig/.nova/Tasks/Zig Package (macOS Terminal).json b/examples/hello-zig/.nova/Tasks/Zig Package (macOS Terminal).json
deleted file mode 100644
index d1fa04d..0000000
--- a/examples/hello-zig/.nova/Tasks/Zig Package (macOS Terminal).json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "extension" : {
- "identifier" : "at.dcz.nova-zig",
- "name" : "Zig"
- },
- "extensionTemplate" : "zigBuildRunTerminal"
-}
diff --git a/examples/hello-zig/.nova/Tasks/Zig Package.json b/examples/hello-zig/.nova/Tasks/Zig Package.json
deleted file mode 100644
index 10830e6..0000000
--- a/examples/hello-zig/.nova/Tasks/Zig Package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "buildBeforeRunning" : true,
- "extension" : {
- "identifier" : "at.dcz.nova-zig",
- "name" : "Zig"
- },
- "extensionTemplate" : "zigBuildRun"
-}
diff --git a/examples/hello-zig/build.zig b/examples/hello-zig/build.zig
deleted file mode 100644
index 5c56fb0..0000000
--- a/examples/hello-zig/build.zig
+++ /dev/null
@@ -1,47 +0,0 @@
-const std = @import("std");
-
-pub fn build(b: *std.Build) void {
- const target = b.standardTargetOptions(.{});
- const optimize = b.standardOptimizeOption(.{});
-
- const lib_mod = b.addModule("hello_zig", .{
- .root_source_file = b.path("src/root.zig"),
- .target = target,
- });
-
- const exe = b.addExecutable(.{
- .name = "hello-zig",
- .root_module = b.createModule(.{
- .root_source_file = b.path("src/main.zig"),
- .target = target,
- .optimize = optimize,
- .imports = &.{
- .{ .name = "hello_zig", .module = lib_mod },
- },
- }),
- });
-
- b.installArtifact(exe);
-
- const run_step = b.step("run", "Run the sample app");
- const run_cmd = b.addRunArtifact(exe);
- run_step.dependOn(&run_cmd.step);
-
- if (b.args) |args| {
- run_cmd.addArgs(args);
- }
-
- const lib_tests = b.addTest(.{
- .root_module = lib_mod,
- });
- const exe_tests = b.addTest(.{
- .root_module = exe.root_module,
- });
-
- const run_lib_tests = b.addRunArtifact(lib_tests);
- const run_exe_tests = b.addRunArtifact(exe_tests);
-
- const test_step = b.step("test", "Run the sample tests");
- test_step.dependOn(&run_lib_tests.step);
- test_step.dependOn(&run_exe_tests.step);
-}
diff --git a/examples/hello-zig/build.zig.zon b/examples/hello-zig/build.zig.zon
deleted file mode 100644
index 09f7da2..0000000
--- a/examples/hello-zig/build.zig.zon
+++ /dev/null
@@ -1,12 +0,0 @@
-.{
- .name = .hello_zig,
- .version = "0.1.0",
- .fingerprint = 0x1c1a468675f426fe, // Changing this has security and trust implications.
- .minimum_zig_version = "0.15.2",
- .dependencies = .{},
- .paths = .{
- "build.zig",
- "build.zig.zon",
- "src",
- },
-}
diff --git a/examples/hello-zig/src/main.zig b/examples/hello-zig/src/main.zig
deleted file mode 100644
index 74eb590..0000000
--- a/examples/hello-zig/src/main.zig
+++ /dev/null
@@ -1,32 +0,0 @@
-const std = @import("std");
-const hello_zig = @import("hello_zig");
-
-pub fn main() !void {
- var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
- defer arena.deinit();
-
- const allocator = arena.allocator();
- const args = try std.process.argsAlloc(allocator);
- const name = if (args.len > 1) args[1] else "Nova";
-
- var greeter = hello_zig.Greeter{
- .name = name,
- .punctuation = '!',
- };
-
- const stdout = std.fs.File.stdout().deprecatedWriter();
- try greeter.write(stdout, .verbose);
-
- const sample_values = [_]i32{ -3, -2, 0, 1, 2, 3, 4 };
- var squares = try hello_zig.collectEvenSquares(allocator, &sample_values);
- defer squares.deinit(allocator);
-
- std.debug.print("even squares: {any}\n", .{squares.items});
-}
-
-test "main module can compute a summary" {
- const greeting = try hello_zig.describeNumber(std.testing.allocator, 42);
- defer std.testing.allocator.free(greeting);
-
- try std.testing.expect(std.mem.startsWith(u8, greeting, "positive"));
-}
diff --git a/examples/hello-zig/src/root.zig b/examples/hello-zig/src/root.zig
deleted file mode 100644
index f6600ac..0000000
--- a/examples/hello-zig/src/root.zig
+++ /dev/null
@@ -1,83 +0,0 @@
-const std = @import("std");
-
-pub const OutputStyle = enum {
- compact,
- verbose,
-};
-
-pub const NumberKind = union(enum) {
- negative: i64,
- zero,
- positive: u64,
-};
-
-pub const Greeter = struct {
- name: []const u8,
- punctuation: u8 = '!',
-
- pub fn write(self: Greeter, writer: anytype, style: OutputStyle) !void {
- switch (style) {
- .compact => try writer.print("hello, {s}{c}\n", .{ self.name, self.punctuation }),
- .verbose => {
- try writer.print(
- \\hello, {s}{c}
- \\this sample is here to exercise Zig syntax support in Nova.
- \\
- , .{ self.name, self.punctuation });
- },
- }
- }
-};
-
-pub fn classifyNumber(value: i64) NumberKind {
- if (value == 0) return .zero;
- if (value < 0) return .{ .negative = value };
- return .{ .positive = @intCast(value) };
-}
-
-pub fn describeNumber(allocator: std.mem.Allocator, value: i64) ![]u8 {
- return switch (classifyNumber(value)) {
- .zero => std.fmt.allocPrint(allocator, "zero", .{}),
- .negative => |negative| std.fmt.allocPrint(allocator, "negative({d})", .{negative}),
- .positive => |positive| std.fmt.allocPrint(allocator, "positive({d})", .{positive}),
- };
-}
-
-pub fn collectEvenSquares(
- allocator: std.mem.Allocator,
- values: []const i32,
-) !std.ArrayList(i32) {
- var result: std.ArrayList(i32) = .empty;
- errdefer result.deinit(allocator);
-
- for (values) |value| {
- if (@mod(value, 2) != 0) continue;
- try result.append(allocator, value * value);
- }
-
- return result;
-}
-
-test "classifyNumber covers the main branches" {
- try std.testing.expectEqual(NumberKind{ .negative = -5 }, classifyNumber(-5));
- try std.testing.expectEqual(NumberKind.zero, classifyNumber(0));
- try std.testing.expectEqual(NumberKind{ .positive = 9 }, classifyNumber(9));
-}
-
-test "collectEvenSquares keeps only even numbers" {
- const values = [_]i32{ -4, -3, 0, 1, 2, 7 };
- var result = try collectEvenSquares(std.testing.allocator, &values);
- defer result.deinit(std.testing.allocator);
-
- try std.testing.expectEqualSlices(i32, &.{ 16, 0, 4 }, result.items);
-}
-
-test "Greeter.write renders verbose output" {
- var list: std.ArrayList(u8) = .empty;
- defer list.deinit(std.testing.allocator);
-
- const writer = list.writer(std.testing.allocator);
- try (Greeter{ .name = "Zig" }).write(writer, .verbose);
-
- try std.testing.expect(std.mem.indexOf(u8, list.items, "exercise Zig syntax support") != null);
-}