nixite/testing/md.test.nix

180 lines
4.2 KiB
Nix
Raw Normal View History

2024-01-03 07:52:35 +00:00
{
describe,
it,
...
}: let
2023-12-31 00:24:48 +00:00
md = import ../nixite/md.nix;
2024-01-03 14:56:48 +00:00
html = import ../nixite/html.nix;
2023-12-31 00:24:48 +00:00
elems = import ../nixite/elems.nix;
2024-01-02 10:53:45 +00:00
in
2024-01-03 13:19:41 +00:00
with md; [
(
describe "list" [
(it "matches a list of one element" {
actual = list [
''
- something
''
];
expected = [(elems.List ["something"])];
2024-01-03 14:56:48 +00:00
asJSON = true;
2024-01-03 13:19:41 +00:00
})
2024-01-02 08:50:33 +00:00
2024-01-03 13:19:41 +00:00
(it "makes a list of many elements" {
actual = list [
''
- something
- something else
''
];
expected = [(elems.List ["something" "something else"])];
2024-01-03 14:56:48 +00:00
asJSON = true;
2024-01-03 13:19:41 +00:00
})
2023-12-31 10:33:05 +00:00
2024-01-03 13:19:41 +00:00
(it "makes a list of many checkboxes" {
actual = list [
''
- [ ] something
- [X] something else
''
];
expected = [
(elems.List [
[
(elems.input {
type = "checkbox";
disabled = true;
checked = false;
} "")
"something"
]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = true;
} "")
"something else"
]
])
];
2024-01-03 14:56:48 +00:00
asJSON = true;
2024-01-03 13:19:41 +00:00
})
2024-01-01 06:33:57 +00:00
2024-01-03 13:19:41 +00:00
(it "doesnt match not a list" (let
str = "blah blah";
in {
actual = list [str];
expected = [str];
}))
]
)
(
describe "process string" [
(it "processes whole string with all rules" {
actual = processStr ''
this text **may** *or may not* contain **bold** words *inside* it.
'';
expected = [
(elems.p [
"this text "
(elems.strong "may")
" "
(elems.em "or may not")
" contain "
(elems.strong "bold")
" words "
(elems.em "inside")
" it."
])
];
2024-01-03 13:19:41 +00:00
asString = true;
})
2023-12-31 10:33:05 +00:00
2024-01-03 13:19:41 +00:00
(it "makes paragraphs" {
actual = processStr ''
lorem ipsum
dolor sit
2023-12-31 10:33:05 +00:00
2024-01-03 13:19:41 +00:00
foo bar
'';
expected = ''
<p >lorem ipsum
dolor sit
</p><p >foo bar</p>'';
asString = true;
})
]
)
(
describe "fix appendix" [
(it "can fix file appendixes" {
actual = fixAppendix "index.md";
expected = "index.html";
})
]
)
(
describe "mdToPage" [
(it "converts markdown to a page" {
asString = true;
2024-01-03 14:56:48 +00:00
actual = mdToPage ''
# Markdown
This is *markdown*!
'';
expected = html.document {
head = [];
body = [
(elems.main (elems.article [
(elems.h1 "Markdown")
(elems.p [
"This is"
(elems.em "markdown")
"!"
])
]))
];
};
2024-01-03 13:19:41 +00:00
})
]
)
(
describe "recReadMd" [
(it "recursively reads dir" {
actual = recReadMd ./blog;
expected = {
"index.md" = mdToPage ./blog/index.md;
"dir" = {"index.md" = mdToPage ./blog/dir/index.md;};
};
asJSON = true;
})
]
)
(
describe "recFixAppendix" [
(it "recursively fixes filename" {
actual = recFixAppendix {
"index.md" = "something";
dir = {"index.md" = "something else";};
};
expected = {
"index.html" = "something";
dir = {"index.html" = "something else";};
};
})
]
)
(
describe "readDir" [
(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;};
};
})
]
)
]