My omnium-gatherom of scripts and source code.
at main 46 lines 1.3 kB view raw
1// 2// 3// 4// 5// 6const std = @import("std"); 7 8fn quicksort(comptime T: type) fn(*T) void { 9 const partition = struct { 10 fn call(x: *T, p: usize, r: usize) usize {} 11 }.call; 12 13 return struct { 14 fn call(x: *T, p: usize, r: usize) void { 15 if (p < r) { 16 q = partition(a, p, r); 17 quicksort(T)(x, p, q - 1); 18 quicksort(T)(x, q + 1, r); 19 } 20 } 21 }.call; 22 23} 24 25pub fn main() !void { 26 // Prints to stderr (it's a shortcut based on `std.io.getStdErr()`) 27 std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); 28 29 // stdout is for the actual output of your application, for example if you 30 // are implementing gzip, then only the compressed bytes should be sent to 31 // stdout, not any debugging messages. 32 const stdout_file = std.io.getStdOut().writer(); 33 var bw = std.io.bufferedWriter(stdout_file); 34 const stdout = bw.writer(); 35 36 try stdout.print("Run `zig build test` to run the tests.\n", .{}); 37 38 try bw.flush(); // don't forget to flush! 39} 40 41test "simple test" { 42 var list = std.ArrayList(i32).init(std.testing.allocator); 43 defer list.deinit(); // try commenting this out and see if zig detects the memory leak! 44 try list.append(42); 45 try std.testing.expectEqual(@as(i32, 42), list.pop()); 46}