fix a extensibility and test for errors

This commit is contained in:
tristan 2024-01-01 13:48:26 +00:00
parent e76305f71a
commit 3ceb580768
12 changed files with 174 additions and 58 deletions

View file

@ -1,5 +1,6 @@
let
elems = import ../nixite/elems.nix;
style = import ../nixite/style.nix;
html = import ../nixite/html.nix;
it = import ./it.nix;
in with elems; [
@ -33,11 +34,26 @@ in with elems; [
actual = title { } "foobar";
asString = true;
})
(it "makes an a tag" {
expected = html.tag "a" { href = "https://example.com"; } "example";
actual = a { href = "https://example.com"; } "example";
asString = true;
})
(it "lets the a tag drop the props" {
expected = html.tag "a" { href = "https://example.com"; } "example";
actual = a "https://example.com" "example";
asString = true;
})
(it "lets you extend the a tag" {
expected = [ "linky" ];
actual = ((style.component a "linky" { }) "https://example.com"
"example").attrs.class;
asString = true;
})
(it "makes a stylesheet link" {
expected = html.tag "link" {
href = "/style";

View file

@ -9,7 +9,7 @@ in with html; [
expected = "p";
}))
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
in {
actual = p.attrs;
expected = { class = ""; };
@ -27,8 +27,8 @@ in with html; [
tag = "p";
attrs = { };
child = "Hello";
__toString = toHTML;
};
removeDunders = true;
})
(it "makes element" (let para = (tag "p" { });
@ -96,6 +96,26 @@ in with html; [
actual = toString (para (a "hello"));
}))
(it "throws with function child" ({
actual = toString (tag "p" (i: ""));
throws = true;
}))
(it "throws with a number" ({
actual = toString (tag "p" 5);
throws = true;
}))
(it "throws with a bool" ({
actual = toString (tag "p" true);
throws = true;
}))
(it "throws with a null" ({
actual = toString (tag "p" null);
throws = true;
}))
(it "concatinates classes" {
actual = toString (tag "p" { class = [ "class1" "class2" ]; } "Hello");
expected = ''<p class="class1 class2">Hello</p>'';
@ -108,7 +128,8 @@ in with html; [
tag = "html";
attrs = { };
child = [ (tag "head" { } [ "foo" "bar" ]) ];
__toString = toHTML;
};
removeDunders = true;
}))
]

View file

@ -1,6 +1,5 @@
path:
builtins.trace ( "testing " + builtins.baseNameOf path )
''
builtins.trace ("testing " + builtins.baseNameOf path) ''
echo
echo 'TEST: ${builtins.baseNameOf path}'
echo

View file

@ -1,6 +1,6 @@
msg:
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false
, safeToPrint ? true }:
{ actual, expected ? { }, asString ? false, asJSON ? false
, removeDunders ? false, safeToPrint ? true, throws ? false }:
let
preProcess = v:
if removeDunders then
@ -15,11 +15,22 @@ let
a = preProcess actual;
e = preProcess expected;
undunder = v: if builtins.isAttrs v then builtins.removeAttrs v [ "__toString" "__functor" ] else v;
undunder = v:
if builtins.isAttrs v then
builtins.removeAttrs v [ "__toString" "__functor" ]
else
v;
out = (if safeToPrint then builtins.toJSON (undunder actual) else ''{"msg": "refusing to print"}'');
out = (if safeToPrint then
builtins.toJSON
(undunder (if throws then (builtins.tryEval actual).value else actual))
else
''{"msg": "refusing to print"}'');
in if (a == e) then ''
success =
if throws then (builtins.tryEval actual).success == false else (a == e);
in if success then ''
echo 'it ${msg}'
'' else
builtins.trace "FAILED ${msg}" ''

View file

@ -3,14 +3,24 @@ let
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")
#(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")
(it "gets md heading" {
actual = mdBlock ''
# title of the page'';
expected = elems.h1 "title of the page";
})
(it "gets md heading 2" {
actual = mdBlock ''
## a subheading'';
expected = elems.h2 "a subheading";
})
(it "limits to 6 #" {
actual = mdBlock ''
######## super ultra tiny heading'';
expected = elems.h6 "super ultra tiny heading";
})
(it "processes md block" {
actual = readMd ''

View file

@ -85,7 +85,9 @@ in with site; [
})
(it "gets all styles" {
expected = {"p"={};"div"={};
expected = {
"p" = { };
"div" = { };
"p.class" = { color = "blue"; };
"div.class2" = { color = "green"; };
};
@ -235,6 +237,34 @@ in with site; [
'';
}))
(it "throws with a list for a page" ({
actual = copyTo "." {
page = [];
};
throws = true;
}))
(it "throws with null for a page" ({
actual = copyTo "." {
page = null;
};
throws = true;
}))
(it "throws with a bool for a page" ({
actual = copyTo "." {
page = true;
};
throws = true;
}))
(it "throws with a number for a page" ({
actual = copyTo "." {
page = 5;
};
throws = true;
}))
(it "prepares the site" ({
actual = prepare { favicon = ./src/favicon.png; } {
"index.html" = elems.html { } [

View file

@ -7,7 +7,10 @@ in [
(it "fetches empty style" (let para = (style.component elems.p "para" { });
in {
expected = { "p" = {}; "p.para" = { }; };
expected = {
"p" = { };
"p.para" = { };
};
actual = style.getStyle (para "");
}))
@ -15,7 +18,10 @@ in [
attrs = { style = { foo = "bar"; }; };
para = (style.component elems.p "para" attrs);
in {
expected = {"p" = {}; "p.para" = attrs.style; };
expected = {
"p" = { };
"p.para" = attrs.style;
};
actual = style.getStyle (para "");
}))
@ -42,12 +48,17 @@ in [
s = { foo = "bar"; };
para = (style.component elems.p "para" { style = s; });
in {
expected = { "p" = {}; "p.para" = s; };
expected = {
"p" = { };
"p.para" = s;
};
actual = style.getStyle (para "");
}))
(it "fetches style recursively" (let
s = {"p" = {};"div" = {};
s = {
"p" = { };
"div" = { };
"p.para" = { foo = "bar"; };
"div.link" = { this = "that"; };
};
@ -60,7 +71,9 @@ in [
}))
(it "fetches style recursively through lists" (let
s = {"p" = {};"div" = {};
s = {
"p" = { };
"div" = { };
"p.para" = { foo = "bar"; };
"div.link" = { this = "that"; };
};
@ -73,7 +86,9 @@ in [
}))
(it "fetches style recursively with repeats" (let
s = {"p" = {};"div" = {};
s = {
"p" = { };
"div" = { };
"p.para" = { foo = "bar"; };
"div.link" = { this = "that"; };
};
@ -86,7 +101,8 @@ in [
}))
(it "converts styles to string" (let
s = {"p" = {};
s = {
"p" = { };
"p.para" = { foo = "bar"; };
"a.link" = { this = "that"; };
};
@ -116,7 +132,9 @@ in [
}))
(it "extends styled tags classes" (let
s = {"p" = {}; "div" = {};
s = {
"p" = { };
"div" = { };
"p.para" = { foo = "bar"; };
"p.para.oof" = { oof = "yes"; };
};