From 5ac1a9b7b96def762614c0596b2df367b3d45fb0 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Mon, 11 Nov 2024 12:03:37 -0500 Subject: [PATCH] fix example tests --- .envrc | 3 + .gitignore | 5 + build.zig | 4 +- notes.md | 2 + src/examples.zig | 3797 ++++++++++++++++++++++++++++++---------------- src/main.zig | 10 +- 6 files changed, 2511 insertions(+), 1310 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..08f9db7 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +PATH_add zig-out/bin +source .venv/bin/activate + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e73c22a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.zig-cache/ +zig-out/ + +.spec/ + diff --git a/build.zig b/build.zig index 813d69f..271bf91 100644 --- a/build.zig +++ b/build.zig @@ -38,7 +38,9 @@ pub fn build(b: *std.Build) void { .optimize = optimize, }); + const run_example_tests = b.addRunArtifact(example_tests); + const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&run_exe_unit_tests.step); - test_step.dependOn(&example_tests.step); + test_step.dependOn(&run_example_tests.step); } diff --git a/notes.md b/notes.md index 89a6f8a..20bc895 100644 --- a/notes.md +++ b/notes.md @@ -2,6 +2,8 @@ The spec is organized into "content blocks", "leaf blocks", and inline content. So the first task in the parser should be to parse the block structure. + + - Blocks - Leaf - Thematic break diff --git a/src/examples.zig b/src/examples.zig index 9fdfbdf..f097d96 100644 --- a/src/examples.zig +++ b/src/examples.zig @@ -1,24 +1,39 @@ const std = @import("std"); const convert = @import("main.zig").convert; -comptime { - std.testing.refAllDecls(@This()); -} test "Example 1" { - return error.BBBBBBBBBBBBb; + const alloc = std.testing.allocator; + + const md = ( + \\→foo→baz→→bim + +); + const html = ( + \\
foo→baz→→bim
+        \\
+ +); + + const output = try convert(alloc, md); + defer alloc.free(output); + + try std.testing.expectEqualStrings(html, output); } + test "Example 2" { const alloc = std.testing.allocator; const md = ( \\→foo→baz→→bim - ); + +); const html = ( \\
foo→baz→→bim
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -26,17 +41,20 @@ test "Example 2" { try std.testing.expectEqualStrings(html, output); } + test "Example 3" { const alloc = std.testing.allocator; const md = ( \\a→a - ); + +); const html = ( \\
a→a
         \\ὐ→a
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -44,12 +62,13 @@ test "Example 3" { try std.testing.expectEqualStrings(html, output); } + test "Example 4" { const alloc = std.testing.allocator; const md = ( \\- - ); +); const html = ( \\ - ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -65,18 +85,19 @@ test "Example 4" { try std.testing.expectEqualStrings(html, output); } + test "Example 5" { const alloc = std.testing.allocator; const md = ( \\- - ); +); const html = ( \\ \\
foo \\ \\
- ); +); const html = ( \\
\\

foo

\\
\\
- ); +); const html = ( \\

> - ); +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1758,6 +1957,7 @@ test "Example 102" { try std.testing.expectEqualStrings(html, output); } + test "Example 103" { const alloc = std.testing.allocator; @@ -1767,12 +1967,14 @@ test "Example 103" { \\bar \\--- \\baz - ); + +); const html = ( \\

Foo

\\

bar

\\

baz

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1780,6 +1982,7 @@ test "Example 103" { try std.testing.expectEqualStrings(html, output); } + test "Example 104" { const alloc = std.testing.allocator; @@ -1790,12 +1993,13 @@ test "Example 104" { \\--- \\ \\baz - ); + +); const html = ( \\

Foo \\bar

\\
Foo \\bar

\\
Foo \\bar \\--- \\baz

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1845,15 +2053,16 @@ test "Example 106" { try std.testing.expectEqualStrings(html, output); } + test "Example 107" { const alloc = std.testing.allocator; const md = ( \\a - ); +); const html = ( \\
a
-    );
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -1861,12 +2070,13 @@ test "Example 107" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 108" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\-
-    );
+);
     const html = (
         \\
    \\
  • @@ -1874,7 +2084,8 @@ test "Example 108" { \\

    bar

    \\
  • \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1882,12 +2093,13 @@ test "Example 108" { try std.testing.expectEqualStrings(html, output); } + test "Example 109" { const alloc = std.testing.allocator; const md = ( \\1. - ); +); const html = ( \\
    \\
  1. @@ -1897,7 +2109,8 @@ test "Example 109" { \\ \\
  2. \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1905,18 +2118,20 @@ test "Example 109" { try std.testing.expectEqualStrings(html, output); } + test "Example 110" { const alloc = std.testing.allocator; const md = ( \\
- ); + +); const html = ( \\
<a/>
         \\*hi*
         \\
         \\-
-    );
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -1924,13 +2139,15 @@ test "Example 110" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 111" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\chunk1
         \\
-    );
+
+);
     const html = (
         \\
chunk1
         \\
@@ -1940,7 +2157,8 @@ test "Example 111" {
         \\
         \\chunk3
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1948,15 +2166,18 @@ test "Example 111" { try std.testing.expectEqualStrings(html, output); } + test "Example 112" { const alloc = std.testing.allocator; const md = ( \\chunk1 - ); + +); const html = ( \\
chunk1
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -1964,16 +2185,19 @@ test "Example 112" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 113" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\Foo
-    );
+
+);
     const html = (
         \\

Foo \\bar

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -1981,18 +2205,21 @@ test "Example 113" { try std.testing.expectEqualStrings(html, output); } + test "Example 114" { const alloc = std.testing.allocator; const md = ( \\foo \\bar - ); + +); const html = ( \\
foo
         \\
\\

bar

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2000,12 +2227,13 @@ test "Example 114" { try std.testing.expectEqualStrings(html, output); } + test "Example 115" { const alloc = std.testing.allocator; const md = ( \\# - ); +); const html = ( \\

Heading

\\
foo
@@ -2014,7 +2242,7 @@ test "Example 115" {
         \\
foo
         \\
\\
- ); +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2038,16 +2268,19 @@ test "Example 116" { try std.testing.expectEqualStrings(html, output); } + test "Example 117" { const alloc = std.testing.allocator; const md = ( \\ - ); + +); const html = ( \\
foo
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2055,15 +2288,16 @@ test "Example 117" { try std.testing.expectEqualStrings(html, output); } + test "Example 118" { const alloc = std.testing.allocator; const md = ( \\foo - ); +); const html = ( \\
foo
-    );
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2071,16 +2305,19 @@ test "Example 118" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 119" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\```
         \\<
-    );
+
+);
     const html = (
         \\
<
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2088,16 +2325,19 @@ test "Example 119" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 120" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\~~~
         \\<
-    );
+
+);
     const html = (
         \\
<
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2105,6 +2345,7 @@ test "Example 120" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 121" {
     const alloc = std.testing.allocator;
 
@@ -2112,10 +2353,12 @@ test "Example 121" {
         \\``
         \\foo
         \\``
-    );
+
+);
     const html = (
         \\

foo

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2123,6 +2366,7 @@ test "Example 121" { try std.testing.expectEqualStrings(html, output); } + test "Example 122" { const alloc = std.testing.allocator; @@ -2131,12 +2375,14 @@ test "Example 122" { \\aaa \\~~~ \\``` - ); + +); const html = ( \\
aaa
         \\~~~
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2144,6 +2390,7 @@ test "Example 122" { try std.testing.expectEqualStrings(html, output); } + test "Example 123" { const alloc = std.testing.allocator; @@ -2152,12 +2399,14 @@ test "Example 123" { \\aaa \\``` \\~~~ - ); + +); const html = ( \\
aaa
         \\```
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2165,6 +2414,7 @@ test "Example 123" { try std.testing.expectEqualStrings(html, output); } + test "Example 124" { const alloc = std.testing.allocator; @@ -2173,12 +2423,14 @@ test "Example 124" { \\aaa \\``` \\`````` - ); + +); const html = ( \\
aaa
         \\```
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2186,6 +2438,7 @@ test "Example 124" { try std.testing.expectEqualStrings(html, output); } + test "Example 125" { const alloc = std.testing.allocator; @@ -2194,12 +2447,14 @@ test "Example 125" { \\aaa \\~~~ \\~~~~ - ); + +); const html = ( \\
aaa
         \\~~~
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2207,15 +2462,18 @@ test "Example 125" { try std.testing.expectEqualStrings(html, output); } + test "Example 126" { const alloc = std.testing.allocator; const md = ( \\``` - ); + +); const html = ( \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2223,6 +2481,7 @@ test "Example 126" { try std.testing.expectEqualStrings(html, output); } + test "Example 127" { const alloc = std.testing.allocator; @@ -2231,13 +2490,15 @@ test "Example 127" { \\ \\``` \\aaa - ); + +); const html = ( \\

         \\```
         \\aaa
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2245,19 +2506,21 @@ test "Example 127" { try std.testing.expectEqualStrings(html, output); } + test "Example 128" { const alloc = std.testing.allocator; const md = ( \\> - ); +); const html = ( \\
\\
aaa
         \\
\\
\\

bbb

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2265,16 +2528,19 @@ test "Example 128" { try std.testing.expectEqualStrings(html, output); } + test "Example 129" { const alloc = std.testing.allocator; const md = ( \\``` \\ - ); + +); const html = ( \\

-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2282,16 +2548,19 @@ test "Example 129" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 130" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\```
         \\```
-    );
+
+);
     const html = (
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2299,17 +2568,20 @@ test "Example 130" { try std.testing.expectEqualStrings(html, output); } + test "Example 131" { const alloc = std.testing.allocator; const md = ( \\``` - ); + +); const html = ( \\
aaa
         \\aaa
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2317,19 +2589,22 @@ test "Example 131" { try std.testing.expectEqualStrings(html, output); } + test "Example 132" { const alloc = std.testing.allocator; const md = ( \\``` \\aaa - ); + +); const html = ( \\
aaa
         \\aaa
         \\aaa
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2337,15 +2612,18 @@ test "Example 132" { try std.testing.expectEqualStrings(html, output); } + test "Example 133" { const alloc = std.testing.allocator; const md = ( \\``` - ); + +); const html = ( \\
aaa
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2353,18 +2631,21 @@ test "Example 133" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 134" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\```
-    );
+
+);
     const html = (
         \\
```
         \\aaa
         \\```
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2372,17 +2653,20 @@ test "Example 134" { try std.testing.expectEqualStrings(html, output); } + test "Example 135" { const alloc = std.testing.allocator; const md = ( \\``` \\aaa - ); + +); const html = ( \\
aaa
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2390,17 +2674,20 @@ test "Example 135" { try std.testing.expectEqualStrings(html, output); } + test "Example 136" { const alloc = std.testing.allocator; const md = ( \\``` \\aaa - ); + +); const html = ( \\
aaa
         \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2408,16 +2695,19 @@ test "Example 136" { try std.testing.expectEqualStrings(html, output); } + test "Example 137" { const alloc = std.testing.allocator; const md = ( \\``` \\aaa - ); + +); const html = ( \\
aaa
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2425,15 +2715,16 @@ test "Example 137" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 138" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\```
-    );
+);
     const html = (
         \\

- ); +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2441,6 +2732,7 @@ test "Example 138" { try std.testing.expectEqualStrings(html, output); } + test "Example 139" { const alloc = std.testing.allocator; @@ -2448,11 +2740,11 @@ test "Example 139" { \\~~~~~~ \\aaa \\~~~ - ); +); const html = ( \\

aaa
         \\~~~
-    );
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2460,6 +2752,7 @@ test "Example 139" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 140" {
     const alloc = std.testing.allocator;
 
@@ -2469,13 +2762,15 @@ test "Example 140" {
         \\bar
         \\```
         \\baz
-    );
+
+);
     const html = (
         \\

foo

\\
bar
         \\
\\

baz

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2483,6 +2778,7 @@ test "Example 140" { try std.testing.expectEqualStrings(html, output); } + test "Example 141" { const alloc = std.testing.allocator; @@ -2493,13 +2789,14 @@ test "Example 141" { \\bar \\~~~ \\# - ); +); const html = ( \\

foo

\\
bar
         \\
\\

baz

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2507,16 +2804,17 @@ test "Example 141" { try std.testing.expectEqualStrings(html, output); } + test "Example 142" { const alloc = std.testing.allocator; const md = ( \\```ruby \\def - ); +); const html = ( \\
aa
         \\foo

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2574,15 +2877,16 @@ test "Example 145" { try std.testing.expectEqualStrings(html, output); } + test "Example 146" { const alloc = std.testing.allocator; const md = ( \\~~~ - ); +); const html = ( \\
```
-    );
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -2607,6 +2912,7 @@ test "Example 147" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 148" {
     const alloc = std.testing.allocator;
 
@@ -2618,7 +2924,8 @@ test "Example 148" {
         \\_world_.
         \\
\\ - ); + +); const html = ( \\
\\
@@ -2626,7 +2933,8 @@ test "Example 148" {
         \\

world. \\

\\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2634,15 +2942,18 @@ test "Example 148" { try std.testing.expectEqualStrings(html, output); } + test "Example 149" { const alloc = std.testing.allocator; const md = ( \\ - ); + +); const html = ( \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2650,15 +2961,18 @@ test "Example 149" { try std.testing.expectEqualStrings(html, output); } + test "Example 150" { const alloc = std.testing.allocator; const md = ( \\
- ); + +); const html = ( \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2666,17 +2980,20 @@ test "Example 150" { try std.testing.expectEqualStrings(html, output); } + test "Example 151" { const alloc = std.testing.allocator; const md = ( \\
\\*foo* - ); + +); const html = ( \\
\\*foo* - ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2684,15 +3001,16 @@ test "Example 151" { try std.testing.expectEqualStrings(html, output); } + test "Example 152" { const alloc = std.testing.allocator; const md = ( \\
\\*foo* \\

bar

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2753,15 +3076,16 @@ test "Example 155" { try std.testing.expectEqualStrings(html, output); } + test "Example 156" { const alloc = std.testing.allocator; const md = ( \\
\\foo \\
- ); + +); const html = ( \\
\\foo \\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2837,17 +3167,18 @@ test "Example 160" { try std.testing.expectEqualStrings(html, output); } + test "Example 161" { const alloc = std.testing.allocator; const md = ( \\
\\``` - ); +); const html = ( \\
\\``` - ); +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2855,15 +3186,16 @@ test "Example 161" { try std.testing.expectEqualStrings(html, output); } + test "Example 162" { const alloc = std.testing.allocator; const md = ( \\
\\*bar* \\ - ); + +); const html = ( \\ \\*bar* \\ - ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2891,15 +3226,16 @@ test "Example 163" { try std.testing.expectEqualStrings(html, output); } + test "Example 164" { const alloc = std.testing.allocator; const md = ( \\ \\*bar* - ); + +); const html = ( \\ \\*bar* - ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2925,6 +3264,7 @@ test "Example 165" { try std.testing.expectEqualStrings(html, output); } + test "Example 166" { const alloc = std.testing.allocator; @@ -2932,12 +3272,14 @@ test "Example 166" { \\ \\*foo* \\ - ); + +); const html = ( \\ \\*foo* \\ - ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2945,6 +3287,7 @@ test "Example 166" { try std.testing.expectEqualStrings(html, output); } + test "Example 167" { const alloc = std.testing.allocator; @@ -2954,12 +3297,14 @@ test "Example 167" { \\*foo* \\ \\ - ); + +); const html = ( \\ \\

foo

\\
- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2967,15 +3312,18 @@ test "Example 167" { try std.testing.expectEqualStrings(html, output); } + test "Example 168" { const alloc = std.testing.allocator; const md = ( \\*foo* - ); + +); const html = ( \\

foo

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -2983,15 +3331,16 @@ test "Example 168" { try std.testing.expectEqualStrings(html, output); } + test "Example 169" { const alloc = std.testing.allocator; const md = ( \\
-    );
+
+);
     const html = (
         \\
-    );
+
+);
 
     const output = try convert(alloc, md);
     defer alloc.free(output);
@@ -3043,15 +3396,18 @@ test "Example 171" {
     try std.testing.expectEqualStrings(html, output);
 }
 
+
 test "Example 172" {
     const alloc = std.testing.allocator;
 
     const md = (
         \\
         \\*foo*
-    );
+
+);
     const html = (
         \\
         \\

foo

- ); + +); const output = try convert(alloc, md); defer alloc.free(output); @@ -3134,15 +3500,16 @@ test "Example 176" { try std.testing.expectEqualStrings(html, output); } + test "Example 177" { const alloc = std.testing.allocator; const md = ( \\