const std = @import("std");
const t = std.testing;
const zmd = @import("../root.zig");
test "parse markdown and translate to HTML" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\Header
\\Sub-header
\\Sub-sub-header
\\some text in bold and italic
\\a paragraph
\\a link: my link
\\an image: 
\\
\\
\\if (1 < 10) {
\\ std.debug.print("1 is < 10 !");
\\}
\\
\\
\\some more text with a code fragment
\\
\\
\\
\\
;
const md =
\\# Header
\\## Sub-header
\\### Sub-sub-header
\\
\\some text in **bold** and _italic_
\\
\\a paragraph
\\
\\a link: [my link](https://ziglang.org/)
\\
\\an image: 
\\
\\```zig
\\if (1 < 10) {
\\ std.debug.print("1 is < 10 !");
\\}
\\```
\\some more text with a `code` fragment
\\
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse content without trailing linebreak before eof" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\Header
\\
\\
\\
\\
;
const md =
\\# Header
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse paragraph leading with a token" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\Header
\\bold text at the start of a paragraph
\\
\\
\\
\\
;
const md =
\\# Header
\\
\\**bold** text at the start of a paragraph
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse indented list" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\
;
const md =
\\ * foo
\\ * bar
\\ * baz
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse underscores in code element" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\
\\ - foo_bar
\\ - baz_qux
\\ - quux_corge
\\
\\
\\
\\
\\
;
const md =
\\* `foo_bar`
\\* `baz_qux`
\\* `quux_corge`
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse parentheses in paragraph" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\some text (with parentheses) in a paragraph
\\
\\
\\
\\
;
const md =
\\some text (with parentheses) in a paragraph
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse underscore in link" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\a link to here_doc with italics and bold
\\
\\
\\
\\
;
const md =
\\a _link_ to [here_doc](https://en.wikipedia.org/wiki/Here_document) with _italics_ and **bold**
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse underscores in block" {
const html =
\\
\\
\\
\\
\\
\\
\\
\\
\\
\\if (foo_bar_baz) return true;
\\
\\
\\
\\
\\
\\
;
const md =
\\```zig
\\if (foo_bar_baz) return true;
\\```
;
const parsed = try zmd.parseAlloc(t.allocator, md, .{});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}
test "parse repeated whitespace" {
// Used to be really slow
const parsed = try zmd.parseAlloc(t.allocator, " " ** 40_000, .{});
t.allocator.free(parsed);
}
test "custom tag overrides" {
const html =
\\Hello
\\
;
const md = "# Hello";
const parsed = try zmd.parseAlloc(t.allocator, md, .{
.h1 = .{ .opening = "", .closing = "\n" },
.root = .{ .opening = "", .closing = "" },
});
defer t.allocator.free(parsed);
try t.expectEqualStrings(html, parsed);
}