uf @ 40a544bac1f8799d40df377a90fb89d24fc2803c

test: Add testing

Also add blank space between line being merged together.
 1diff --git a/src/main.zig b/src/main.zig
 2index 14eb65c02af62dcd3f90b6228567a2fd7bc5e6e2..21103fff4a11308d5167d9b708f5ff80fc668808 100644
 3--- a/src/main.zig
 4+++ b/src/main.zig
 5@@ -1,11 +1,12 @@
 6 const std = @import("std");
 7 const File = std.fs.File;
 8+const Reader = std.fs.File.Reader;
 9 const Writer = std.fs.File.Writer;
10 
11 pub fn main() !void {
12     const in = std.io.getStdIn();
13     const out = std.io.getStdOut();
14-    Uf.init().streamCopy(in, out) catch |err| {
15+    Uf.init().streamCopy(in.reader(), out.writer()) catch |err| {
16         try std.io.getStdErr().writer().print("Error {}", .{err});
17     };
18 }
19@@ -22,12 +23,12 @@     fn init() Self {
20         return Self{};
21     }
22 
23-    fn flush(_: Self, out: Writer) !void {
24+    fn flush(_: Self, out: anytype) !void {
25         _ = try out.write(out_buf[0..out_index]);
26         out_index = 0;
27     }
28 
29-    fn writeChar(self: Self, out: Writer, c: u8) !void {
30+    fn writeChar(self: Self, out: anytype, c: u8) !void {
31         if (out_index >= buf_size) {
32             try self.flush(out);
33         }
34@@ -35,10 +36,7 @@         out_buf[out_index] = c;
35         out_index += 1;
36     }
37 
38-    fn streamCopy(self: Self, in: File, out: File) !void {
39-        const reader = in.reader();
40-        const writer = out.writer();
41-
42+    fn streamCopy(self: Self, reader: anytype, writer: anytype) !void {
43         var hit = false;
44         var second = false;
45         var in_buf: [buf_size]u8 = undefined;
46@@ -55,6 +53,8 @@                     }
47                 } else if (hit and c != '\n') {
48                     if (second) {
49                         try self.writeChar(writer, '\n');
50+                    } else {
51+                        try self.writeChar(writer, ' ');
52                     }
53                     hit = false;
54                     second = false;
55@@ -73,3 +73,32 @@             }
56         }
57     }
58 };
59+
60+test "Test format" {
61+    const text_in =
62+        \\# This is a markdown
63+        \\
64+        \\Lorem ipsum dolor sit amet,
65+        \\consectetur adipiscing elit.
66+        \\
67+        \\
68+        \\
69+        \\Praesent pharetra sit amet ante sit amet consequat.
70+    ;
71+
72+    const text_out =
73+        \\# This is a markdown
74+        \\
75+        \\Lorem ipsum dolor sit amet, consectetur adipiscing elit.
76+        \\
77+        \\Praesent pharetra sit amet ante sit amet consequat.
78+    ;
79+
80+    var stream = std.io.fixedBufferStream(text_in);
81+
82+    var list = std.ArrayList(u8).init(std.testing.allocator);
83+    defer list.deinit();
84+
85+    try Uf.init().streamCopy(stream.reader(), list.writer());
86+    try std.testing.expect(std.mem.eql(u8, text_out, list.items));
87+}