nixite/testing/md.test.nix

145 lines
3.1 KiB
Nix
Raw Normal View History

2024-01-02 09:18:30 +00:00
{it,...}: let
2023-12-31 00:24:48 +00:00
md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix;
in with md; [
2023-12-31 00:24:48 +00:00
2024-01-01 17:31:04 +00:00
(it "matches a list of one element" ({
2024-01-01 14:51:59 +00:00
actual = list ''
2024-01-01 17:31:04 +00:00
- something
2024-01-01 14:51:59 +00:00
'';
2024-01-01 17:31:04 +00:00
expected = {
matched = true;
2024-01-02 04:01:19 +00:00
block = elems.List [ "something" ];
2024-01-01 17:31:04 +00:00
};
2024-01-01 20:27:05 +00:00
asJSON = true;
2024-01-01 14:51:59 +00:00
}))
2024-01-01 20:27:05 +00:00
(it "makes a list of many elements" ({
2024-01-01 14:51:59 +00:00
actual = list ''
2024-01-01 17:31:04 +00:00
- something
- something else
2024-01-01 14:51:59 +00:00
'';
2024-01-01 17:31:04 +00:00
expected = {
matched = true;
2024-01-02 04:01:19 +00:00
block = elems.List [ "something" "something else" ];
2024-01-01 17:31:04 +00:00
};
2024-01-01 20:27:05 +00:00
asJSON = true;
}))
(it "makes a list of many checkboxes" ({
actual = list ''
- [ ] something
- [X] something else
'';
expected = {
matched = true;
block = elems.List [
2024-01-02 04:01:19 +00:00
[
(elems.input {
type = "checkbox";
disabled = true;
checked = false;
} "")
"something"
]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = true;
} "")
"something else"
]
2024-01-01 20:27:05 +00:00
];
};
asJSON = true;
2024-01-01 14:51:59 +00:00
}))
2024-01-01 17:31:04 +00:00
(it "matches a list with no whitespace around" ({
actual = list ''
- something
- something else'';
expected = {
matched = true;
2024-01-02 04:01:19 +00:00
block = elems.List [ "something" "something else" ];
2024-01-01 17:31:04 +00:00
};
2024-01-01 20:27:05 +00:00
asJSON = true;
2024-01-01 14:51:59 +00:00
}))
2024-01-01 17:31:04 +00:00
(it "doesnt match not a list" (let str = "blah blah";
in {
2024-01-01 14:51:59 +00:00
actual = list str;
2024-01-01 17:31:04 +00:00
expected = {
matched = false;
block = str;
};
2024-01-01 14:51:59 +00:00
}))
2024-01-01 17:31:04 +00:00
(it "processes whole string with all rules" ({
actual = processStr ''
this text **may** *or may not* contain **bold** words *inside* it.
'';
2024-01-02 08:50:33 +00:00
expected = (elems.p [
2024-01-01 17:31:04 +00:00
"this text"
(elems.strong "may")
(elems.em "or may not")
"contain"
(elems.strong "bold")
"words"
(elems.em "inside")
2024-01-02 08:50:33 +00:00
"it."
]);
2024-01-01 17:31:04 +00:00
asString = true;
2024-01-01 14:51:59 +00:00
}))
2024-01-02 08:50:33 +00:00
(it "makes paragraphs" {
actual = readMd ''
lorem ipsum
2024-01-02 08:50:33 +00:00
dolor sit
foo bar
'';
2024-01-02 08:50:33 +00:00
expected = "<p >lorem ipsum\ndolor sit\n</p><p >foo bar</p>";
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" {
2024-01-01 17:31:04 +00:00
actual = toString (mdToPage ./blog/index.md) + "\n";
expected = builtins.readFile ./out/index.html;
2024-01-01 06:33:57 +00:00
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; };
};
})
]