use describe, apply alejandra

This commit is contained in:
tristan 2024-01-03 07:52:35 +00:00
parent 3f16ae203a
commit 819efaddf9
7 changed files with 791 additions and 759 deletions

View file

@ -37,11 +37,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1704192724, "lastModified": 1704202884,
"narHash": "sha256-Cx9os5FQU4UTjxt/uE1trPHxegXyhvV/wSiIiBWTDt0=", "narHash": "sha256-+Zbr66+jP5Rdn95JAtKw25eyUnhNxS3eUOyIv01MLB8=",
"ref": "refs/heads/master", "ref": "refs/heads/master",
"rev": "b800bb46955d69cf7693d7c788a4d624eff2717f", "rev": "32a3950d16e8a1c9413940d940732115cbe13bbd",
"revCount": 3, "revCount": 7,
"type": "git", "type": "git",
"url": "https://git.tristans.cloud/tristan/tix" "url": "https://git.tristans.cloud/tristan/tix"
}, },

View file

@ -1,12 +1,10 @@
let let
elems = import ./elems.nix; elems = import ./elems.nix;
in rec { in rec {
readMd = md: processMd = md:
if builtins.isPath md if builtins.isPath md
then processMd (builtins.readFile md) then processStr (builtins.readFile md)
else processMd md; else processStr md;
processMd = processStr;
recReadMd = root: recReadMd = root:
assert builtins.isPath root; assert builtins.isPath root;
@ -32,11 +30,7 @@ in rec {
readDir = root: recFixAppendix (recReadMd root); readDir = root: recFixAppendix (recReadMd root);
mdToPage = md: mdToPage = md:
elems.Doc {} [[(elems.title {} "markdown file")] (readMd md)]; elems.Doc {} [[(elems.title {} "markdown file")] (processMd md)];
list = block:
matchThen "(- .+\n)*(- .+\n?)"
block (m: elems.List (splitList block));
splitList = block: splitList = block:
map listItem (builtins.filter (s: builtins.isString s && s != "") map listItem (builtins.filter (s: builtins.isString s && s != "")
@ -111,15 +105,7 @@ in rec {
href = builtins.elemAt m 2; href = builtins.elemAt m 2;
text = builtins.elemAt m 1; text = builtins.elemAt m 1;
in (elems.a href text))) in (elems.a href text)))
(rule "(.*\n)([^-][^\n]+\n)((- [^\n]+\n)+)(.*)" ( list
l: (elems.ul (basicRule "(.*\n)?- ([^\n]+)\n(.*)" (m:
elems.li (basicRule "()\\[(.)](.*)" (check:
elems.input {
type = "checkbox";
checked = check != " ";
disabled = true;
}) [m])) [(builtins.elemAt l 2)]))
))
(basicRule "(.*\n\n)?(.+)\n(.*)?" elems.p) (basicRule "(.*\n\n)?(.+)\n(.*)?" elems.p)
(basicRule "(.*\n\n)?```(.*)```(.*)?" (elems.textarea {readonly = true;})) (basicRule "(.*\n\n)?```(.*)```(.*)?" (elems.textarea {readonly = true;}))
(basicRule (containsBreak "###### ([^\n]+)") (elems.h6)) (basicRule (containsBreak "###### ([^\n]+)") (elems.h6))
@ -131,6 +117,16 @@ in rec {
(basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m)) (basicRule (containsBreak "<(${linkmatcher})>") (m: elems.a m m))
]; ];
list = rule "(.*\n)([^-][^\n]+\n)((- [^\n]+\n)+)(.*)" (
l: (elems.ul (basicRule "(.*\n)?- ([^\n]+)\n(.*)" (m:
elems.li (basicRule "()\\[(.)](.*)" (check:
elems.input {
type = "checkbox";
checked = check != " ";
disabled = true;
}) [m])) [(builtins.elemAt l 2)]))
);
linkmatcher = "[-[:alnum:].%?&#=:/]+"; linkmatcher = "[-[:alnum:].%?&#=:/]+";
contains = matcher: "(.*)?${matcher}(.*)"; contains = matcher: "(.*)?${matcher}(.*)";
wrap = matcher: contains "${matcher}([^${matcher}]+)${matcher}"; wrap = matcher: contains "${matcher}([^${matcher}]+)${matcher}";

View file

@ -1,86 +1,91 @@
{it, ...}: let {
describe,
it,
...
}: let
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
style = import ../nixite/style.nix;
html = import ../nixite/html.nix; html = import ../nixite/html.nix;
in in
with elems; [ with elems;
(it "makes a p tag" { describe "html tag" [
expected = html.tag "p" {} "foobar"; (it "makes a p tag" {
actual = p {} "foobar"; expected = html.tag "p" {} "foobar";
asString = true; actual = p {} "foobar";
}) asString = true;
(it "makes a div tag" { })
expected = html.tag "div" {} "foobar"; (it "makes a div tag" {
actual = div {} "foobar"; expected = html.tag "div" {} "foobar";
asString = true; actual = div {} "foobar";
}) asString = true;
(it "makes a section tag" { })
expected = html.tag "section" {} "foobar"; (it "makes a section tag" {
actual = section {} "foobar"; expected = html.tag "section" {} "foobar";
asString = true; actual = section {} "foobar";
}) asString = true;
(it "makes a span tag" { })
expected = html.tag "span" {} "foobar"; (it "makes a span tag" {
actual = span {} "foobar"; expected = html.tag "span" {} "foobar";
asString = true; actual = span {} "foobar";
}) asString = true;
(it "makes a main tag" { })
expected = html.tag "main" {} ["yeet"]; (it "makes a main tag" {
actual = main {} ["yeet"]; expected = html.tag "main" {} ["yeet"];
asString = true; actual = main {} ["yeet"];
}) asString = true;
(it "makes a title tag" { })
expected = html.tag "title" {} "foobar"; (it "makes a title tag" {
actual = title {} "foobar"; expected = html.tag "title" {} "foobar";
asString = true; actual = title {} "foobar";
}) asString = true;
})
(it "makes an a tag" { (it "makes an a tag" {
expected = html.tag "a" {href = "https://example.com";} "example"; expected = html.tag "a" {href = "https://example.com";} "example";
actual = a {href = "https://example.com";} "example"; actual = a {href = "https://example.com";} "example";
asString = true; asString = true;
}) })
(it "lets the a tag drop the props" { (it "lets the a tag drop the props" {
expected = html.tag "a" {href = "https://example.com";} "example"; expected = html.tag "a" {href = "https://example.com";} "example";
actual = a "https://example.com" "example"; actual = a "https://example.com" "example";
asString = true; asString = true;
}) })
(it "lets you extend the a tag" { (it "lets you extend the a tag" (let
expected = ["linky"]; extA = a {class = ["linky"];};
actual = in {
((style.component a "linky" {}) "https://example.com" expected = ["linky"];
"example") actual =
.attrs (extA "https://example.com" "example")
.class; .attrs
asString = true; .class;
}) asString = true;
}))
(it "makes a stylesheet link" { (it "makes a stylesheet link" {
expected = html.tag "link" { expected = html.tag "link" {
href = "/style"; href = "/style";
rel = "stylesheet"; rel = "stylesheet";
} ""; } "";
actual = Stylesheet {href = "/style";}; actual = Stylesheet {href = "/style";};
asString = true; asString = true;
}) })
(it "makes a list" { (it "makes a list" {
expected = html.tag "ul" {__ = "";} [ expected = html.tag "ul" {__ = "";} [
(html.tag "li" {} "foo") (html.tag "li" {} "foo")
(html.tag "li" {} "bar") (html.tag "li" {} "bar")
(html.tag "li" {} "baz") (html.tag "li" {} "baz")
]; ];
actual = List {} ["foo" "bar" "baz"]; actual = List {} ["foo" "bar" "baz"];
asString = true; asString = true;
}) })
(it "makes an html doc" { (it "makes an html doc" {
expected = html.tag "html" { expected = html.tag "html" {
__child = ""; __child = "";
class = []; class = [];
lang = "en"; lang = "en";
} [(html.tag "head" {} ["foo"]) (html.tag "body" {} "bar")]; } [(html.tag "head" {} ["foo"]) (html.tag "body" {} "bar")];
actual = Doc {} [["foo"] "bar"]; actual = Doc {} [["foo"] "bar"];
asString = true; asString = true;
}) })
] ]

View file

@ -1,149 +1,155 @@
{it, ...}: let {
describe,
it,
...
}: let
html = import ../nixite/html.nix; html = import ../nixite/html.nix;
in in
with html; [ with html;
(it "keeps info in the tag" (let describe "tag" [
p = tag "p"; (it "keeps info in the tag" (let
in { p = tag "p";
actual = p.tag; in {
expected = "p"; actual = p.tag;
})) expected = "p";
}))
(it "keeps attr info in the tag" (let (it "keeps attr info in the tag" (let
p = tag "p" {class = "";}; p = tag "p" {class = "";};
in { in {
actual = p.attrs; actual = p.attrs;
expected = {class = "";}; expected = {class = "";};
})) }))
(it "keeps tag after setting attrs" (let (it "keeps tag after setting attrs" (let
p = tag "p" {class = "";}; p = tag "p" {class = "";};
in { in {
actual = p.tag; actual = p.tag;
expected = "p"; expected = "p";
})) }))
(it "makes a p tag" { (it "makes a p tag" {
actual = tag "p" {} "Hello"; actual = tag "p" {} "Hello";
expected = { expected = {
tag = "p"; tag = "p";
attrs = {}; attrs = {};
child = "Hello"; child = "Hello";
}; };
removeDunders = true; removeDunders = true;
}) })
(it "makes element" (let (it "makes element" (let
para = tag "p" {}; para = tag "p" {};
in { in {
expected = "p"; expected = "p";
actual = para.tag; actual = para.tag;
})) }))
(it "keeps attrs on element" (let (it "keeps attrs on element" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = attrs; expected = attrs;
actual = para.attrs; actual = para.attrs;
})) }))
(it "makes renderable element" (let (it "makes renderable element" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = "<p ></p>"; expected = "<p ></p>";
actual = toString (para ""); actual = toString (para "");
})) }))
(it "keeps tag" (let (it "keeps tag" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = "p"; expected = "p";
actual = (para "").tag; actual = (para "").tag;
})) }))
(it "keeps style" (let (it "keeps style" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
in { in {
expected = {foo = "bar";}; expected = {foo = "bar";};
actual = (para "").attrs.style; actual = (para "").attrs.style;
})) }))
(it "needs no args to make string" (let (it "needs no args to make string" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString p; actual = toString p;
expected = "<p ></p>"; expected = "<p ></p>";
})) }))
(it "needs no content to make string" (let (it "needs no content to make string" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString (p {class = "foobar";}); actual = toString (p {class = "foobar";});
expected = ''<p class="foobar"></p>''; expected = ''<p class="foobar"></p>'';
})) }))
(it "can take many sets of props" (let (it "can take many sets of props" (let
p = tag "p"; p = tag "p";
in { in {
actual = toString (p {class = "foobar";} {style = "a style";}); actual = toString (p {class = "foobar";} {style = "a style";});
expected = ''<p class="foobar" style="a style"></p>''; expected = ''<p class="foobar" style="a style"></p>'';
})) }))
(it "works recursively" (let (it "works recursively" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = tag "p" attrs; para = tag "p" attrs;
a = tag "a" {}; a = tag "a" {};
in { in {
expected = "<p ><a >hello</a></p>"; expected = "<p ><a >hello</a></p>";
actual = toString (para (a "hello")); actual = toString (para (a "hello"));
})) }))
(it "throws with function child" { (it "throws with function child" {
actual = toString (tag "p" (i: "")); actual = toString (tag "p" (i: ""));
throws = true; throws = true;
}) })
(it "throws with a number" { (it "throws with a number" {
actual = toString (tag "p" 5); actual = toString (tag "p" 5);
throws = true; throws = true;
}) })
(it "throws with a bool" { (it "throws with a bool" {
actual = toString (tag "p" true); actual = toString (tag "p" true);
throws = true; throws = true;
}) })
(it "throws with a null" { (it "throws with a null" {
actual = toString (tag "p" null); actual = toString (tag "p" null);
throws = true; throws = true;
}) })
(it "concatinates classes" { (it "concatinates classes" {
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello"); actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
expected = ''<p class="class1 class2">Hello</p>''; expected = ''<p class="class1 class2">Hello</p>'';
}) })
(it "applies style" (let (it "renders on / off attrs" {
page = tag "html" {} [(tag "head" {} ["foo"])]; actual = toString (tag "p" {
in { on = true;
actual = addToHead page ["bar"]; off = false;
expected = { });
tag = "html"; expected = "<p on></p>";
attrs = {}; })
child = [(tag "head" {} ["foo" "bar"])]; ]
}; ++ describe "addToHead" [
removeDunders = true; (it "applies style" (let
})) page = tag "html" {} [(tag "head" {} ["foo"])];
in {
(it "renders on / off attrs" { actual = addToHead page ["bar"];
actual = toString (tag "p" { expected = {
on = true; tag = "html";
off = false; attrs = {};
}); child = [(tag "head" {} ["foo" "bar"])];
expected = "<p on></p>"; };
}) removeDunders = true;
] }))
]

View file

@ -1,148 +1,150 @@
{it, ...}: let {
describe,
it,
...
}: let
md = import ../nixite/md.nix; md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
in in
with md; [ with md;
(it "matches a list of one element" { describe "list" [
actual = list '' (it "matches a list of one element" {
- something actual = list [
''; ''
expected = { - something
matched = true; ''
block = elems.List ["something"];
};
asJSON = true;
})
(it "makes a list of many elements" {
actual = list ''
- something
- something else
'';
expected = {
matched = true;
block = elems.List ["something" "something else"];
};
asJSON = true;
})
(it "makes a list of many checkboxes" {
actual = list ''
- [ ] something
- [X] something else
'';
expected = {
matched = true;
block = elems.List [
[
(elems.input {
type = "checkbox";
disabled = true;
checked = false;
} "")
"something"
]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = true;
} "")
"something else"
]
]; ];
}; expected = [(elems.List ["something"])];
asJSON = true; })
})
(it "matches a list with no whitespace around" { (it "makes a list of many elements" {
actual = list '' actual = list [
- something ''
- something else''; - something
expected = { - something else
matched = true; ''
block = elems.List ["something" "something else"]; ];
}; expected = [(elems.List ["something" "something else"])];
asJSON = true; })
})
(it "doesnt match not a list" (let (it "makes a list of many checkboxes" {
str = "blah blah"; actual = list [
in { ''
actual = list str; - [ ] something
expected = { - [X] something else
matched = false; ''
block = str; ];
}; expected = [
})) (elems.List [
[
(elems.input {
type = "checkbox";
disabled = true;
checked = false;
} "")
"something"
]
[
(elems.input {
type = "checkbox";
disabled = true;
checked = true;
} "")
"something else"
]
])
];
})
(it "processes whole string with all rules" { (it "matches a list with no whitespace around" {
actual = processStr '' actual = list [
this text **may** *or may not* contain **bold** words *inside* it. ''
''; - something
expected = elems.p [ - something else''
"this text" ];
(elems.strong "may") expected = [(elems.List ["something" "something else"])];
(elems.em "or may not") })
"contain"
(elems.strong "bold")
"words"
(elems.em "inside")
"it."
];
asString = true;
})
(it "makes paragraphs" { (it "doesnt match not a list" (let
actual = readMd '' str = "blah blah";
lorem ipsum in {
dolor sit 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."
];
asString = true;
})
foo bar (it "makes paragraphs" {
''; actual = processStr ''
expected = '' lorem ipsum
<p >lorem ipsum dolor sit
dolor sit
</p><p >foo bar</p>'';
asString = true;
})
(it "can fix file appendixes" { foo bar
actual = fixAppendix "index.md"; '';
expected = "index.html"; expected = ''
}) <p >lorem ipsum
dolor sit
(it "converts markdown to a page" { </p><p >foo bar</p>'';
actual = toString (mdToPage ./blog/index.md) + "\n\n"; # inflation asString = true;
expected = builtins.readFile ./out/index.html; })
asString = true; ]
}) ++ describe "fix appendix" [
(it "can fix file appendixes" {
(it "recursively reads dir" { actual = fixAppendix "index.md";
actual = recReadMd ./blog; expected = "index.html";
expected = { })
"index.md" = mdToPage ./blog/index.md; ]
"dir" = {"index.md" = mdToPage ./blog/dir/index.md;}; ++ describe "mdToPage" [
}; (it "converts markdown to a page" {
asJSON = true; actual = toString (mdToPage ./blog/index.md) + "\n\n"; # inflation
}) expected = builtins.readFile ./out/index.html;
asString = true;
(it "recursively fixes filename" { })
actual = recFixAppendix { ]
"index.md" = "something"; ++ describe "recReadMd" [
dir = {"index.md" = "something else";}; (it "recursively reads dir" {
}; actual = recReadMd ./blog;
expected = { expected = {
"index.html" = "something"; "index.md" = mdToPage ./blog/index.md;
dir = {"index.html" = "something else";}; "dir" = {"index.md" = mdToPage ./blog/dir/index.md;};
}; };
}) asJSON = true;
})
(it "recursively translates md to html" { ]
actual = builtins.toJSON (readDir ./blog); ++ describe "recFixAppendix" [
expected = builtins.toJSON { (it "recursively fixes filename" {
"index.html" = mdToPage ./blog/index.md; actual = recFixAppendix {
"dir" = {"index.html" = mdToPage ./blog/dir/index.md;}; "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;};
};
})
]

View file

@ -1,63 +1,58 @@
{it, ...}: let {
describe,
it,
...
}: let
html = import ../nixite/html.nix; html = import ../nixite/html.nix;
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix; site = import ../nixite/site.nix;
style = import ../nixite/style.nix; style = import ../nixite/style.nix;
in in
with site; [ with site;
(it "applies a style" { describe "applyStyle" [
expected = { (it "applies a style" {
"index.html" = html.tag "html" {} [ expected = {
(html.tag "head" {} [
(elems.title {} "foobar")
(elems.Stylesheet "/style.css")
])
(elems.main {} "something")
];
blog = {
"index.html" = html.tag "html" {} [ "index.html" = html.tag "html" {} [
(html.tag "head" {} [ (html.tag "head" {} [
(elems.title {} "foobar") (elems.title {} "foobar")
(elems.Stylesheet "/style.css") (elems.Stylesheet "/style.css")
]) ])
(elems.main {} "blogy blog")
];
};
"style.css" = ''
this is a stylesheet
'';
};
actual =
applyStyle ''
this is a stylesheet
'' {
"index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")])
(elems.main {} "something") (elems.main {} "something")
]; ];
blog = { blog = {
"index.html" = html.tag "html" {} [ "index.html" = html.tag "html" {} [
(html.tag "head" {} [(elems.title {} "foobar")]) (html.tag "head" {} [
(elems.title {} "foobar")
(elems.Stylesheet "/style.css")
])
(elems.main {} "blogy blog") (elems.main {} "blogy blog")
]; ];
}; };
"style.css" = ''
this is a stylesheet
'';
}; };
asJSON = true; actual =
}) applyStyle ''
this is a stylesheet
(it "applies a favicon" { '' {
expected = { "index.html" = html.tag "html" {} [
"index.html" = elems.html {} [ (html.tag "head" {} [(elems.title {} "foobar")])
(elems.head {} [ (elems.main {} "something")
(elems.title {} "foobar") ];
(elems.link { blog = {
rel = "shortcut icon"; "index.html" = html.tag "html" {} [
href = ./src/favicon.png; (html.tag "head" {} [(elems.title {} "foobar")])
}) (elems.main {} "blogy blog")
]) ];
(elems.main {} "something") };
]; };
blog = { asJSON = true;
})
]
++ describe "applyFavicon" [
(it "applies a favicon" {
expected = {
"index.html" = elems.html {} [ "index.html" = elems.html {} [
(elems.head {} [ (elems.head {} [
(elems.title {} "foobar") (elems.title {} "foobar")
@ -68,228 +63,236 @@ in
]) ])
(elems.main {} "something") (elems.main {} "something")
]; ];
blog = {
"index.html" = elems.html {} [
(elems.head {} [
(elems.title {} "foobar")
(elems.link {
rel = "shortcut icon";
href = ./src/favicon.png;
})
])
(elems.main {} "something")
];
};
}; };
}; actual = applyFavicon ./src/favicon.png {
actual = applyFavicon ./src/favicon.png {
"index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
blog = {
"index.html" = elems.html {} [ "index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")]) (elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something") (elems.main {} "something")
]; ];
blog = {
"index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
};
};
asJSON = true;
})
]
++ describe "getStyles" [
(it "gets all styles" {
expected = {
"p" = {};
"div" = {};
"p.class" = {color = "blue";};
"div.class2" = {color = "green";};
};
actual = getStyles (let
p = style.component elems.p "class" {style = {color = "blue";};};
g = style.component elems.div "class2" {style = {color = "green";};};
in {
"index.html" = p "";
blog = {"index.html" = g "";};
});
removeDunders = true;
})
]
++ describe "getPaths" [
(it "gets top level paths" {
actual = getPaths {
something = "";
src = ./src/index.md;
};
expected = {"index.md" = ./src/index.md;};
})
(it "gets lower level paths" {
actual = getPaths {
something = "yes";
a-list = [
{thingy = ./src/index.md;}
[(html.tag "img" {src = ./src/favicon.png;} "")]
];
};
expected = {
"index.md" = ./src/index.md;
"favicon.png" = ./src/favicon.png;
};
})
]
++ describe "switchPaths" [
(it "switches paths" {
actual = switchPaths {
something = "";
a-thing = {src = ./src/index.md;};
a-list = [{thingy = ./src/index.md;}];
};
expected = {
something = "";
a-thing = {src = "/static/index.md";};
a-list = [{thingy = "/static/index.md";}];
};
})
]
++ describe "extractPaths" [
(it "extracts paths" {
actual = extractPaths {
something = "";
a-thing = {src = ./src/index.md;};
a-list = [{thingy = ./src/index.md;}];
};
expected = {
something = "";
a-thing = {src = "/static/index.md";};
a-list = [{thingy = "/static/index.md";}];
static = {"index.md" = ./src/index.md;};
};
})
]
++ describe "switchLinks" [
(it "switches links" (let
coolPage = {
type = "link";
name = "cool-page";
content = "";
}; };
};
asJSON = true;
})
(it "gets all styles" {
expected = {
"p" = {};
"div" = {};
"p.class" = {color = "blue";};
"div.class2" = {color = "green";};
};
actual = getStyles (let
p = style.component elems.p "class" {style = {color = "blue";};};
g = style.component elems.div "class2" {style = {color = "green";};};
in { in {
"index.html" = p ""; actual = switchLinks {
blog = {"index.html" = g "";}; something = "";
}); a-thing = {src = coolPage;};
removeDunders = true; a-list = [{thingy = coolPage;}];
}) };
expected = {
(it "gets top level paths" { something = "";
actual = getPaths { a-thing = {src = "/static/cool-page";};
something = ""; a-list = [{thingy = "/static/cool-page";}];
src = ./src/index.md; };
}; }))
expected = {"index.md" = ./src/index.md;}; ]
}) ++ describe "getLinks" [
(it "gets lower level paths" { (it "gets links" (let
actual = getPaths { coolPage = {
something = "yes"; type = "link";
a-list = [ name = "cool-page";
{thingy = ./src/index.md;} content = "cool content";
[(html.tag "img" {src = ./src/favicon.png;} "")] };
]; otherPage = {
}; type = "link";
expected = { name = "page2";
"index.md" = ./src/index.md; content = "stuff";
"favicon.png" = ./src/favicon.png; };
}; in {
}) actual = getLinks {
something = "yes";
(it "switches paths" { a-list = [{thingy = coolPage;} [(elems.img {src = otherPage;} "")]];
actual = switchPaths { };
something = ""; expected = {
a-thing = {src = ./src/index.md;};
a-list = [{thingy = ./src/index.md;}];
};
expected = {
something = "";
a-thing = {src = "/static/index.md";};
a-list = [{thingy = "/static/index.md";}];
};
})
(it "extracts paths" {
actual = extractPaths {
something = "";
a-thing = {src = ./src/index.md;};
a-list = [{thingy = ./src/index.md;}];
};
expected = {
something = "";
a-thing = {src = "/static/index.md";};
a-list = [{thingy = "/static/index.md";}];
static = {"index.md" = ./src/index.md;};
};
})
(it "switches links" (let
coolPage = {
type = "link";
name = "cool-page";
content = "";
};
in {
actual = switchLinks {
something = "";
a-thing = {src = coolPage;};
a-list = [{thingy = coolPage;}];
};
expected = {
something = "";
a-thing = {src = "/static/cool-page";};
a-list = [{thingy = "/static/cool-page";}];
};
}))
(it "gets links" (let
coolPage = {
type = "link";
name = "cool-page";
content = "cool content";
};
otherPage = {
type = "link";
name = "page2";
content = "stuff";
};
in {
actual = getLinks {
something = "yes";
a-list = [{thingy = coolPage;} [(elems.img {src = otherPage;} "")]];
};
expected = {
"cool-page" = "cool content";
"page2" = "stuff";
};
}))
(it "extracts links" (let
coolPage = {
type = "link";
name = "cool-page";
content = "cool content";
};
otherPage = {
type = "link";
name = "page2";
content = "stuff";
};
in {
actual = extractLinks {
something = "";
a-thing = {src = coolPage;};
a-list = [{thingy = otherPage;}];
};
expected = {
something = "";
a-thing = {src = "/static/cool-page";};
a-list = [{thingy = "/static/page2";}];
static = {
"cool-page" = "cool content"; "cool-page" = "cool content";
"page2" = "stuff"; "page2" = "stuff";
}; };
}; }))
})) ]
++ describe "extractLinks" [
(it "copies all the files" { (it "extracts links" (let
actual = copyTo "." { coolPage = {
page = "this is a page"; type = "link";
subdir = { name = "cool-page";
page = "this page is in a subdir"; content = "cool content";
link = ./src;
}; };
}; otherPage = {
expected = '' type = "link";
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page name = "page2";
mkdir -p ./subdir content = "stuff";
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link };
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page in {
actual = extractLinks {
something = "";
a-thing = {src = coolPage;};
a-list = [{thingy = otherPage;}];
};
expected = {
something = "";
a-thing = {src = "/static/cool-page";};
a-list = [{thingy = "/static/page2";}];
static = {
"cool-page" = "cool content";
"page2" = "stuff";
};
};
}))
]
++ describe "copyTo" [
(it "copies all the files" {
actual = copyTo "." {
page = "this is a page";
subdir = {
page = "this page is in a subdir";
link = ./src;
};
};
expected = ''
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
mkdir -p ./subdir
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
''; '';
}) })
(it "throws with a list for a page" { (it "throws with a list for a page" {
actual = copyTo "." {page = [];}; actual = copyTo "." {page = [];};
throws = true; throws = true;
}) })
(it "throws with null for a page" { (it "throws with null for a page" {
actual = copyTo "." {page = null;}; actual = copyTo "." {page = null;};
throws = true; throws = true;
}) })
(it "throws with a bool for a page" { (it "throws with a bool for a page" {
actual = copyTo "." {page = true;}; actual = copyTo "." {page = true;};
throws = true; throws = true;
}) })
(it "throws with a number for a page" { (it "throws with a number for a page" {
actual = copyTo "." {page = 5;}; actual = copyTo "." {page = 5;};
throws = true; throws = true;
}) })
]
(it "prepares the site" { ++ describe "prepare" [
actual = prepare {favicon = ./src/favicon.png;} { (it "prepares the site" {
"index.html" = elems.html {} [ actual = prepare {favicon = ./src/favicon.png;} {
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} [
(elems.a {
href = {
type = "link";
name = "a-page";
content = "this is another page";
};
} "A Page")
])
];
blog = {
"index.html" = elems.html {} [ "index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")]) (elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something") (elems.main {} [
(elems.a {
href = {
type = "link";
name = "a-page";
content = "this is another page";
};
} "A Page")
])
]; ];
blog = {
"index.html" = elems.html {} [
(elems.head {} [(elems.title {} "foobar")])
(elems.main {} "something")
];
};
}; };
}; expected = {
expected = {
"index.html" = elems.html {} [
(elems.head {} [
(elems.title {} "foobar")
(elems.link {
rel = "shortcut icon";
href = "/static/favicon.png";
})
(elems.Stylesheet "/style.css")
])
(elems.main {} [(elems.a {href = "/static/a-page";} "A Page")])
];
blog = {
"index.html" = elems.html {} [ "index.html" = elems.html {} [
(elems.head {} [ (elems.head {} [
(elems.title {} "foobar") (elems.title {} "foobar")
@ -299,15 +302,27 @@ in
}) })
(elems.Stylesheet "/style.css") (elems.Stylesheet "/style.css")
]) ])
(elems.main {} "something") (elems.main {} [(elems.a {href = "/static/a-page";} "A Page")])
]; ];
blog = {
"index.html" = elems.html {} [
(elems.head {} [
(elems.title {} "foobar")
(elems.link {
rel = "shortcut icon";
href = "/static/favicon.png";
})
(elems.Stylesheet "/style.css")
])
(elems.main {} "something")
];
};
static = {
"favicon.png" = ./src/favicon.png;
"a-page" = "this is another page";
};
"style.css" = "";
}; };
static = { asJSON = true;
"favicon.png" = ./src/favicon.png; })
"a-page" = "this is another page"; ]
};
"style.css" = "";
};
asJSON = true;
})
]

View file

@ -1,145 +1,153 @@
{it, ...}: let {
describe,
it,
...
}: let
style = import ../nixite/style.nix; style = import ../nixite/style.nix;
elems = import ../nixite/elems.nix; elems = import ../nixite/elems.nix;
in [ in
(it "fetches empty style" (let describe "getStyle" [
para = style.component elems.p "para" {}; (it "fetches empty style" (let
in { para = style.component elems.p "para" {};
expected = { in {
"p" = {}; expected = {
"p.para" = {}; "p" = {};
}; "p.para" = {};
actual = style.getStyle (para ""); };
})) actual = style.getStyle (para "");
}))
(it "fetches style" (let (it "fetches style" (let
attrs = {style = {foo = "bar";};}; attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs; para = style.component elems.p "para" attrs;
in { in {
expected = { expected = {
"p" = {}; "p" = {};
"p.para" = attrs.style; "p.para" = attrs.style;
}; };
actual = style.getStyle (para ""); actual = style.getStyle (para "");
})) }))
(it "appliess class" (let (it "fetches style for class" (let
attrs = {style = {foo = "bar";};}; s = {foo = "bar";};
para = style.component elems.p "para" attrs; para = style.component elems.p "para" {style = s;};
in { in {
expected = ["para"]; expected = {
actual = (para "").attrs.class; "p" = {};
})) "p.para" = s;
};
actual = style.getStyle (para "");
}))
]
++ describe "component" [
(it "applies class" (let
attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs;
in {
expected = ["para"];
actual = (para "").attrs.class;
}))
(it "applies classes from props" (let (it "applies classes from props" (let
attrs = { attrs = {
style = {foo = "bar";}; style = {foo = "bar";};
class = ["other" "class"]; class = ["other" "class"];
}; };
para = style.component elems.p "para" attrs; para = style.component elems.p "para" attrs;
in { in {
expected = ["para" "other" "class"]; expected = ["para" "other" "class"];
actual = (para "").attrs.class; actual = (para "").attrs.class;
})) }))
(it "fetches style for class" (let (it "extends styled tags classes" (let
s = {foo = "bar";}; s = {
para = style.component elems.p "para" {style = s;}; "p" = {};
in { "div" = {};
expected = { "p.para" = {foo = "bar";};
"p" = {}; "p.para.oof" = {oof = "yes";};
"p.para" = s; };
}; para = style.component elems.p "para" {style = s."p.para";};
actual = style.getStyle (para ""); para2 = style.component para "oof" {style = s."p.para.oof";};
})) in {
expected = ["para" "oof"];
actual = (para2 "").attrs.class;
}))
]
++ describe "getStyles" [
(it "fetches style recursively" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
};
para = style.component elems.p "para" {style = s."p.para";};
div = style.component elems.div "link" {style = s."div.link";};
in {
expected = s;
actual = style.getStyles (para (div "hello"));
removeDunders = true;
}))
(it "fetches style recursively" (let (it "fetches style recursively through lists" (let
s = { s = {
"p" = {}; "p" = {};
"div" = {}; "div" = {};
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"div.link" = {this = "that";}; "div.link" = {this = "that";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
div = style.component elems.div "link" {style = s."div.link";}; a = style.component elems.div "link" {style = s."div.link";};
in { in {
expected = s; expected = s;
actual = style.getStyles (para (div "hello")); actual = style.getStyles (para [(a "hello")]);
removeDunders = true; removeDunders = true;
})) }))
(it "fetches style recursively through lists" (let (it "fetches style recursively with repeats" (let
s = { s = {
"p" = {}; "p" = {};
"div" = {}; "div" = {};
"p.para" = {foo = "bar";}; "p.para" = {foo = "bar";};
"div.link" = {this = "that";}; "div.link" = {this = "that";};
}; };
para = style.component elems.p "para" {style = s."p.para";}; para = style.component elems.p "para" {style = s."p.para";};
a = style.component elems.div "link" {style = s."div.link";}; a = style.component elems.div "link" {style = s."div.link";};
in { in {
expected = s; expected = s;
actual = style.getStyles (para [(a "hello")]); actual = style.getStyles (para [(a "hello") (a "hello")]);
removeDunders = true; removeDunders = true;
})) }))
(it "fetches style recursively with repeats" (let (it "extends styled tags" (let
s = { s = {
"p" = {}; "p.para" = {foo = "bar";};
"div" = {}; "p.oof" = {oof = "yes";};
"p.para" = {foo = "bar";}; };
"div.link" = {this = "that";}; para = style.component elems.p "para" {style = s."p.para";};
}; para2 = style.component para "oof" {style = s."p.oof";};
para = style.component elems.p "para" {style = s."p.para";}; in {
a = style.component elems.div "link" {style = s."div.link";}; expected = s;
in { actual = style.getStyles (para2 "");
expected = s; removeDunders = true;
actual = style.getStyles (para [(a "hello") (a "hello")]); }))
removeDunders = true; ]
})) ++ describe "stylesToString" [
(it "converts styles to string" (let
(it "converts styles to string" (let s = {
s = { "p" = {};
"p" = {}; "p.para" = {foo = "bar";};
"p.para" = {foo = "bar";}; "a.link" = {this = "that";};
"a.link" = {this = "that";}; };
}; in {
in { expected = ''
expected = '' a.link {
a.link { this: that;
this: that; }
} p.para {
p.para { foo: bar;
foo: bar; }
} '';
''; actual = style.stylesToString s;
actual = style.stylesToString s; }))
})) ]
(it "extends styled tags" (let
s = {
"p.para" = {foo = "bar";};
"p.oof" = {oof = "yes";};
};
para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.oof";};
in {
expected = s;
actual = style.getStyles (para2 "");
removeDunders = true;
}))
(it "extends styled tags classes" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"p.para.oof" = {oof = "yes";};
};
para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.para.oof";};
in {
expected = ["para" "oof"];
actual = (para2 "").attrs.class;
}))
]