convert functions into links
This commit is contained in:
parent
d723140f84
commit
b788aa4416
4 changed files with 155 additions and 51 deletions
|
@ -1,25 +1,24 @@
|
|||
msg:
|
||||
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false, }:
|
||||
let
|
||||
preProcess = v:
|
||||
if removeDunders then
|
||||
builtins.removeAttrs v [ "__toString" "__functor" ]
|
||||
else if asString then
|
||||
toString v
|
||||
else if asJSON then
|
||||
builtins.toJSON v
|
||||
else v;
|
||||
|
||||
preProcess = v:
|
||||
if removeDunders then
|
||||
builtins.removeAttrs v [ "__toString" "__functor" ]
|
||||
else if asString then
|
||||
toString v
|
||||
else if asJSON then
|
||||
builtins.toJSON v
|
||||
else
|
||||
v;
|
||||
|
||||
a = preProcess actual;
|
||||
e = preProcess expected;
|
||||
|
||||
in
|
||||
if (a == e) then ''
|
||||
echo 'it ${msg}'
|
||||
''
|
||||
else
|
||||
''
|
||||
echo 'FAILED: ${msg}'
|
||||
echo '${builtins.toJSON expected}'
|
||||
echo '${builtins.toJSON actual}'
|
||||
''
|
||||
in if (a == e) then ''
|
||||
echo 'it ${msg}'
|
||||
'' else
|
||||
builtins.trace actual
|
||||
builtins.trace expected
|
||||
''
|
||||
echo FAILED ${msg}
|
||||
''
|
||||
|
|
|
@ -84,31 +84,29 @@ in with site; [
|
|||
asJSON = true;
|
||||
})
|
||||
|
||||
(it "extracts all styles" {
|
||||
(it "gets all styles" {
|
||||
expected = {
|
||||
"p.class" = {color = "blue";};
|
||||
"a.class2" = {color = "green";};
|
||||
"p.class" = { color = "blue"; };
|
||||
"a.class2" = { color = "green"; };
|
||||
};
|
||||
actual = getStyles (let
|
||||
p = style.tag "p" "class" {style = {color = "blue";};};
|
||||
g = style.tag "a" "class2" {style = {color = "green";};};
|
||||
p = style.tag "p" "class" { style = { color = "blue"; }; };
|
||||
g = style.tag "a" "class2" { style = { color = "green"; }; };
|
||||
in {
|
||||
"index.html" = p "";
|
||||
blog = {
|
||||
"index.html" = g "";
|
||||
};
|
||||
blog = { "index.html" = g ""; };
|
||||
});
|
||||
removeDunders = true;
|
||||
})
|
||||
|
||||
(it "extracts top level paths" {
|
||||
(it "gets top level paths" {
|
||||
actual = getPaths {
|
||||
something = "";
|
||||
src = ./src/index.md;
|
||||
};
|
||||
expected = { "index.md" = ./src/index.md; };
|
||||
})
|
||||
(it "extracts lower level paths" {
|
||||
(it "gets lower level paths" {
|
||||
actual = getPaths {
|
||||
something = "yes";
|
||||
a-list = [
|
||||
|
@ -121,6 +119,7 @@ in with site; [
|
|||
"favicon.png" = ./src/favicon.png;
|
||||
};
|
||||
})
|
||||
|
||||
(it "switches paths" {
|
||||
actual = switchPaths {
|
||||
something = "";
|
||||
|
@ -147,4 +146,76 @@ in with site; [
|
|||
static = { "index.md" = ./src/index.md; };
|
||||
};
|
||||
})
|
||||
|
||||
(it "switches functions" (let
|
||||
coolPage = _: {
|
||||
type = "page";
|
||||
name = "cool-page";
|
||||
content = "";
|
||||
};
|
||||
in {
|
||||
actual = switchFunctions {
|
||||
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 functions" (let
|
||||
coolPage = _: {
|
||||
type = "page";
|
||||
name = "cool-page";
|
||||
content = "cool content";
|
||||
};
|
||||
otherPage = _: {
|
||||
type = "page";
|
||||
name = "page2";
|
||||
content = "stuff";
|
||||
};
|
||||
in {
|
||||
actual = getFunctions {
|
||||
something = "yes";
|
||||
a-list =
|
||||
[ { thingy = coolPage; } [ (elems.img { src = otherPage; } "") ] ];
|
||||
};
|
||||
expected = {
|
||||
"cool-page" = "cool content";
|
||||
"page2" = "stuff";
|
||||
};
|
||||
}))
|
||||
|
||||
(it "extracts functions" (let
|
||||
coolPage = _: {
|
||||
type = "page";
|
||||
name = "cool-page";
|
||||
content = "cool content";
|
||||
};
|
||||
otherPage = _: {
|
||||
type = "page";
|
||||
name = "page2";
|
||||
content = "stuff";
|
||||
};
|
||||
|
||||
in {
|
||||
actual = extractFunctions {
|
||||
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";
|
||||
};
|
||||
};
|
||||
}))
|
||||
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue