nixite/testing/md.test.nix

72 lines
2 KiB
Nix
Raw Normal View History

2023-12-31 00:24:48 +00:00
let
md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix;
it = import ./it.nix;
in with md; [
(assert heading "# heading 1" == [ "#" "heading 1" ]; "echo gets heading 1")
(assert heading "## subheading" == [ "##" "subheading" ];
"echo gets heading 2")
(assert heading "some paragraph" == null; "echo paragraph is heading 0")
2023-12-31 00:24:48 +00:00
#(assert mdBlock "# heading 1" == elems.h 1 "heading 1"; "echo makes h1 tag")
#(assert mdBlock "## subheading" == elems.h 2 "subheading"; "echo makes h2 tag")
#(assert mdBlock "some paragraph" == elems.p {} "some paragraph"; "echo makes p tag")
2023-12-31 00:24:48 +00:00
(it "processes md block" {
actual = readMd ''
# foo bar
2023-12-31 00:24:48 +00:00
lorem ipsum
'';
expected = [
2024-01-01 06:33:57 +00:00
(elems.h1 { } "foo bar")
""
(elems.p { } ''
2023-12-31 00:24:48 +00:00
lorem ipsum
'')
];
asString = true;
})
2023-12-31 10:33:05 +00:00
(it "can fix file appendixes" {
actual = fixAppendix "index.md";
expected = "index.html";
})
2023-12-31 10:33:05 +00:00
2024-01-01 06:33:57 +00:00
(it "converts markdown to a page" {
actual = mdToPage ./blog/index.md;
expected = ''
<html lang="en"><head ><title >markdown file</title></head> <body ><h1 >yeee</h1> <p >ye</p> <p >&amp;</p> <p ><a href="dir">dir</a>
<a href="/">home</a></p> <p ></p></body></html>'';
asString = true;
})
(it "recursively reads dir" {
actual = recReadMd ./blog;
expected = {
"index.md" = mdToPage ./blog/index.md;
"dir" = { "index.md" = mdToPage ./blog/dir/index.md; };
};
asJSON = true;
})
2023-12-31 10:33:05 +00:00
(it "recursively fixes filename" {
actual = recFixAppendix {
"index.md" = "something";
dir = { "index.md" = "something else"; };
};
expected = {
"index.html" = "something";
dir = { "index.html" = "something else"; };
};
})
2023-12-31 10:33:05 +00:00
(it "recursively translates md to html" {
actual = builtins.toJSON (readDir ./blog);
expected = builtins.toJSON {
"index.html" = mdToPage ./blog/index.md;
"dir" = { "index.html" = mdToPage ./blog/dir/index.md; };
};
})
]