make it all work

This commit is contained in:
tristan 2023-12-31 00:24:48 +00:00
parent 74670edee1
commit c10587f0c5
16 changed files with 335 additions and 66 deletions

53
testing/elems.test.nix Normal file
View file

@ -0,0 +1,53 @@
let
elems = import ../nixite/elems.nix;
html = import ../nixite/html.nix;
it = import ./it.nix;
in
with elems; [
(it "makes a p tag" {
expected = html.tag "p" {} "foobar";
actual = p "foobar";
})
(it "makes a main tag" {
expected = html.tag "main" {} ["yeet"];
actual = main ["yeet"];
})
(it "makes an h1 tag" {
expected = html.tag "h1" {} "foobar";
actual = h 1 "foobar";
})
(it "makes an h2 tag" {
expected = html.tag "h2" {} "foobar";
actual = h 2 "foobar";
})
(it "makes a title tag" {
expected = html.tag "title" {} "foobar";
actual = title "foobar";
})
(it "makes an a tag" {
expected = html.tag "a" {href = "https://example.com";} "example";
actual = link "https://example.com" "example";
})
(it "makes a stylesheet link" {
expected = html.tag "link" {
href = "/style";
rel = "stylesheet";
} "";
actual = stylesheet "/style";
})
(it "makes a list" {
expected = html.tag "ul" {} [
(html.tag "li" {} "foo")
(html.tag "li" {} "bar")
(html.tag "li" {} "baz")
];
actual = list ["foo" "bar" "baz"];
})
(it "makes an html doc" {
expected = html.tag "html" {lang = "en";} [
(html.tag "head" {} ["foo"])
(html.tag "body" {} "bar")
];
actual = doc ["foo"] "bar";
})
]

27
testing/html.test.nix Normal file
View file

@ -0,0 +1,27 @@
let
html = import ../nixite/html.nix;
it = import ./it.nix;
in
with html; [
(it "makes a p tag" {
actual = tag "p" {} "Hello";
expected = {
tag = "p";
attrs = {};
child = "Hello";
__toString = toHTML;
};
})
(it "applies style" (let
page = tag "html" {} [(tag "head" {} ["foo"])];
in {
actual = addToHead page ["bar"];
expected = {
tag = "html";
attrs = {};
child = [(tag "head" {} ["foo" "bar"])];
__toString = toHTML;
};
}))
]

5
testing/import.nix Normal file
View file

@ -0,0 +1,5 @@
path:
toString (map (v: ''
echo '${builtins.baseNameOf path} :: ${v}'
'')
(import path))

11
testing/it.nix Normal file
View file

@ -0,0 +1,11 @@
msg: {
actual,
expected,
}:
if actual == expected
then msg
else
throw
(builtins.toJSON {
inherit actual expected msg;
})

27
testing/md.test.nix Normal file
View file

@ -0,0 +1,27 @@
let
md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix;
it = import ./it.nix;
in
with md; [
(assert heading "# heading 1" == ["#" "heading 1"]; "gets heading 1")
(assert heading "## subheading" == ["##" "subheading"]; "gets heading 2")
(assert heading "some paragraph" == null; "paragraph is heading 0")
(assert mdBlock "# heading 1" == elems.h 1 "heading 1"; "makes h1 tag")
(assert mdBlock "## subheading" == elems.h 2 "subheading"; "makes h2 tag")
(assert mdBlock "some paragraph" == elems.p "some paragraph"; "makes p tag")
(it "processes md block" {
actual = readMd ''
# foo bar
lorem ipsum
'';
expected = [
(elems.h 1 "foo bar")
""
(elems.p "lorem ipsum\n")
];
})
]

27
testing/site.test.nix Normal file
View file

@ -0,0 +1,27 @@
let
elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix;
it = import ./it.nix;
in
with site; [
(it "applies a style" {
expected = {
"index.html" = with elems; (doc [(title "foobar") (stylesheet "/style.css")] [(main "something")]);
blog = {
"index.html" = with elems; (doc [(title "foobar") (stylesheet "/style.css")] [(main "blogy blog")]);
};
"style.css" = ''
this is a stylesheet
'';
};
actual =
applyStyle ''
this is a stylesheet
'' {
"index.html" = with elems; (doc [(title "foobar")] [(main "something")]);
blog = {
"index.html" = with elems; (doc [(title "foobar")] [(main "blogy blog")]);
};
};
})
]

11
testing/src/index.md Normal file
View file

@ -0,0 +1,11 @@
# Hello World
Making a website in Nix? That sounds dumb.
## but why?
great question!
### you are dumb.
yes I am.

3
testing/src/style.css Normal file
View file

@ -0,0 +1,3 @@
p {
padding: 1rem;
};