replace styled components
This commit is contained in:
parent
003100e691
commit
30ffa6c9b3
11 changed files with 388 additions and 444 deletions
|
@ -28,26 +28,13 @@ in with elems; [
|
|||
actual = main { } [ "yeet" ];
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an h1 tag" {
|
||||
expected = html.tag "h1" { } "foobar";
|
||||
actual = H 1 "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an h2 tag" {
|
||||
expected = html.tag "h2" { } "foobar";
|
||||
actual = H 2 "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a title tag" {
|
||||
expected = html.tag "title" { } "foobar";
|
||||
actual = title { } "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an a tag" {
|
||||
expected = html.tag "a" {
|
||||
class = [ "a" ];
|
||||
href = "https://example.com";
|
||||
} "example";
|
||||
expected = html.tag "a" { href = "https://example.com"; } "example";
|
||||
actual = a "https://example.com" "example";
|
||||
asString = true;
|
||||
})
|
||||
|
@ -60,10 +47,7 @@ in with elems; [
|
|||
asString = true;
|
||||
})
|
||||
(it "makes a list" {
|
||||
expected = html.tag "ul" {
|
||||
__ = "";
|
||||
class = [ "List" ];
|
||||
} [
|
||||
expected = html.tag "ul" { __ = ""; } [
|
||||
(html.tag "li" { } "foo")
|
||||
(html.tag "li" { } "bar")
|
||||
(html.tag "li" { } "baz")
|
||||
|
|
|
@ -31,58 +31,52 @@ in with html; [
|
|||
};
|
||||
})
|
||||
|
||||
(it "makes element"
|
||||
(let para = (tag "p" {});
|
||||
in {
|
||||
expected = "p";
|
||||
actual = para.tag;
|
||||
}))
|
||||
(it "makes element" (let para = (tag "p" { });
|
||||
in {
|
||||
expected = "p";
|
||||
actual = para.tag;
|
||||
}))
|
||||
|
||||
(it "keeps attrs on element"
|
||||
(let
|
||||
(it "keeps attrs on element" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = attrs;
|
||||
actual = para.attrs;
|
||||
}))
|
||||
in {
|
||||
expected = attrs;
|
||||
actual = para.attrs;
|
||||
}))
|
||||
|
||||
(it "makes renderable element"
|
||||
(let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = "<p ></p>";
|
||||
actual = toString ( para "" );
|
||||
}))
|
||||
(it "makes renderable element" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = "<p ></p>";
|
||||
actual = toString (para "");
|
||||
}))
|
||||
|
||||
(it "keeps tag"
|
||||
(let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = "p";
|
||||
actual = ( para "" ).tag;
|
||||
}))
|
||||
(it "keeps tag" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = "p";
|
||||
actual = (para "").tag;
|
||||
}))
|
||||
|
||||
(it "keeps style"
|
||||
(let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = { foo = "bar"; };
|
||||
actual = ( para "" ).attrs.style;
|
||||
}))
|
||||
(it "keeps style" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
in {
|
||||
expected = { foo = "bar"; };
|
||||
actual = (para "").attrs.style;
|
||||
}))
|
||||
|
||||
(it "works recursively"
|
||||
(let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
a = (tag "a" {});
|
||||
in {
|
||||
expected = "<p ><a >hello</a></p>";
|
||||
actual = toString ( para (a "hello") );
|
||||
}))
|
||||
(it "works recursively" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (tag "p" attrs);
|
||||
a = (tag "a" { });
|
||||
in {
|
||||
expected = "<p ><a >hello</a></p>";
|
||||
actual = toString (para (a "hello"));
|
||||
}))
|
||||
|
||||
(it "concatinates classes" {
|
||||
actual = toString (tag "p" { class = [ "class1" "class2" ]; } "Hello");
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
msg:
|
||||
{ actual, expected, asString ? false, asJSON ? false, }:
|
||||
{ actual, expected, asString ? false, asJSON ? false, removeDunders ? false, }:
|
||||
if (if asString then
|
||||
toString actual == toString expected
|
||||
else if asJSON then
|
||||
builtins.toJSON actual == builtins.toJSON expected
|
||||
else if removeDunders then
|
||||
builtins.removeAttrs actual [ "__toString" "__functor" ] == expected
|
||||
else
|
||||
actual == expected) then ''
|
||||
echo 'it ${msg}'
|
||||
|
|
|
@ -19,7 +19,7 @@ in with md; [
|
|||
lorem ipsum
|
||||
'';
|
||||
expected = [
|
||||
(elems.H 1 "foo bar")
|
||||
(elems.h1 { } "foo bar")
|
||||
""
|
||||
(elems.p { } ''
|
||||
lorem ipsum
|
||||
|
@ -33,6 +33,14 @@ in with md; [
|
|||
expected = "index.html";
|
||||
})
|
||||
|
||||
(it "converts markdown to a page" {
|
||||
actual = mdToPage ./blog/index.md;
|
||||
expected = ''
|
||||
<html lang="en"><head ><title >markdown file</title></head> <body ><h1 >yeee</h1> <p >ye</p> <p >&</p> <p ><a href="dir">dir</a>
|
||||
<a href="/">home</a></p> <p ></p></body></html>'';
|
||||
asString = true;
|
||||
})
|
||||
|
||||
(it "recursively reads dir" {
|
||||
actual = recReadMd ./blog;
|
||||
expected = {
|
||||
|
|
|
@ -1,256 +1,129 @@
|
|||
let
|
||||
style = import ../nixite/style.nix;
|
||||
html = import ../nixite/html.nix;
|
||||
it = import ./it.nix;
|
||||
|
||||
in [
|
||||
|
||||
(it "makes a p component" (let
|
||||
my = (style.styled "para" "p" { style = { some-style = "some value"; }; });
|
||||
(it "fetches empty style" (let para = (style.tag "p" "para" { });
|
||||
in {
|
||||
expected = html.tag "p" { class = [ "para" ]; } "yes";
|
||||
actual = my.para { } "yes";
|
||||
asString = true;
|
||||
expected = { "p.para" = { }; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "extends existing components" (let
|
||||
my = (style.styled "generic" "p" {
|
||||
foo = "bar";
|
||||
forgetme = "nothing";
|
||||
});
|
||||
this = (style.styled "quote" my.generic {
|
||||
baz = "baz";
|
||||
forgetme = "forgotten";
|
||||
});
|
||||
(it "fetches style" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (style.tag "p" "para" attrs);
|
||||
in {
|
||||
expected = html.tag "p" {
|
||||
forgetme = "forgotten";
|
||||
baz = "baz";
|
||||
foo = "bar";
|
||||
class = [ "generic" "quote" ];
|
||||
} "yes";
|
||||
actual = this.quote { } "yes";
|
||||
asString = true;
|
||||
expected = { "p.para" = attrs.style; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "makes a component with no class"
|
||||
(let my = (style.styled "classless" "div" { class = [ ]; });
|
||||
in {
|
||||
expected = html.tag "div" { class = [ ]; } "yes";
|
||||
actual = my.classless { } "yes";
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "does not error without attrs" (let
|
||||
my = (style.styled "div" "div" {
|
||||
class = [ "something" ];
|
||||
style = { this = "that"; };
|
||||
});
|
||||
in{
|
||||
expected = html.tag "div" { class = [ "div" "something" ]; } "yes";
|
||||
actual = my.div "yes";
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "makes a component" (let
|
||||
my = (style.styled "div" "div" {
|
||||
class = [ "something" ];
|
||||
style = { this = "that"; };
|
||||
});
|
||||
in{
|
||||
expected = html.tag "div" { class = [ "div" "something" ]; } "foobar";
|
||||
actual = my.div { } "foobar";
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "makes special components" (let
|
||||
|
||||
my = (style.styled "s" "div" {
|
||||
id = "s";
|
||||
class = [ "something" ];
|
||||
style = { s = "yes"; };
|
||||
});
|
||||
in{
|
||||
expected = html.tag "div" {
|
||||
id = "s";
|
||||
class = [ "s" "something" ];
|
||||
} "foobar";
|
||||
actual = my.s { } "foobar";
|
||||
asString = true;
|
||||
}))
|
||||
(it "works on many classes" (let
|
||||
my = (style.styled "foobar" "div" {
|
||||
class = [ "foo" "bar" ];
|
||||
style = { something = "something"; };
|
||||
});
|
||||
in{
|
||||
expected = html.tag "div" { class = [ "foobar" "foo" "bar" ]; } "foobar";
|
||||
actual = my.foobar { } "foobar";
|
||||
asString = true;
|
||||
}))
|
||||
(it "does custom behavour" (let
|
||||
|
||||
my = (style.styled "list" "ul" {
|
||||
__child = child:
|
||||
assert builtins.isList child;
|
||||
(map (html.tag "li" { }) child);
|
||||
});
|
||||
in {
|
||||
expected = html.tag "ul" {
|
||||
__ = "";
|
||||
class = [ "list" ];
|
||||
} [ (html.tag "li" { } "1") (html.tag "li" { } "2") ];
|
||||
actual = my.list { } [ "1" "2" ];
|
||||
asString = true;
|
||||
}))
|
||||
(it "combines attrs" (let
|
||||
|
||||
my = (style.styled "div" "div" {
|
||||
class = [ "something" ];
|
||||
style = { this = "that"; };
|
||||
}) (style.styled "s" "div" {
|
||||
id = "s";
|
||||
class = [ "something" ];
|
||||
style = { s = "yes"; };
|
||||
}) (style.styled "foobar" "div" {
|
||||
class = [ "foo" "bar" ];
|
||||
style = { something = "something"; };
|
||||
}) (style.style "body" { foo = "bar"; }) (style.styled "list" "ul" {
|
||||
__child = child:
|
||||
assert builtins.isList child;
|
||||
(map (html.tag "li" { }) child);
|
||||
});
|
||||
in {
|
||||
expected = html.tag "div" {
|
||||
id = "foo";
|
||||
class = [ "div" "something" ];
|
||||
} "foobar";
|
||||
actual = my.div { id = "foo"; } "foobar";
|
||||
asString = true;
|
||||
}))
|
||||
(it "makes a style"
|
||||
(let my = (style.styled "para" "p" { style = { foo = "bar"; }; });
|
||||
in {
|
||||
expected = { "p.para" = { foo = "bar"; }; };
|
||||
actual = removeAttrs my.style [ "__toString" ];
|
||||
}))
|
||||
|
||||
(it "retains tag"
|
||||
(let p = (style.styled "para" "p" { style = { foo = "bar"; }; });
|
||||
in {
|
||||
expected = "p";
|
||||
actual = p.para.tag;
|
||||
}))
|
||||
|
||||
(it "retains attrs"
|
||||
(let p = (style.styled "para" "p" { style = { foo = "bar"; }; });
|
||||
in {
|
||||
expected = { foo = "bar"; };
|
||||
actual = p.para.attrs.style;
|
||||
}))
|
||||
|
||||
(it "retains class" (let p = (style.styled "para" "p" { });
|
||||
(it "appliess class" (let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (style.tag "p" "para" attrs);
|
||||
in {
|
||||
expected = [ "para" ];
|
||||
actual = p.para.attrs.class;
|
||||
actual = (para "").attrs.class;
|
||||
}))
|
||||
|
||||
(it "merges styles" (let
|
||||
p = (style.styled "para" "p" { style = { foo = "bar"; }; });
|
||||
d = (style.styled "para2" p.para { style = { baz = "bar"; }; });
|
||||
my = p d;
|
||||
in {
|
||||
expected = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"p.para2.para" = {
|
||||
foo = "bar";
|
||||
baz = "bar";
|
||||
};
|
||||
(it "applies classes from props" (let
|
||||
attrs = {
|
||||
style = { foo = "bar"; };
|
||||
class = [ "other" "class" ];
|
||||
};
|
||||
actual = removeAttrs my.style [ "__toString" ];
|
||||
para = (style.tag "p" "para" attrs);
|
||||
in {
|
||||
expected = [ "para" "other" "class" ];
|
||||
actual = (para "").attrs.class;
|
||||
}))
|
||||
|
||||
(it "fetches empty style"
|
||||
(let
|
||||
para = (style.tag "p" "para" {});
|
||||
in {
|
||||
expected = {"p.para" = {};};
|
||||
actual = style.getStyle ( para "" );
|
||||
}))
|
||||
(it "fetches style for class" (let
|
||||
s = { foo = "bar"; };
|
||||
para = (style.tag "p" "para" { style = s; });
|
||||
in {
|
||||
expected = { "p.para" = s; };
|
||||
actual = style.getStyle (para "");
|
||||
}))
|
||||
|
||||
(it "fetches style"
|
||||
(let
|
||||
attrs = { style = { foo = "bar"; }; };
|
||||
para = (style.tag "p" "para" attrs);
|
||||
in {
|
||||
expected = {"p.para" = attrs.style;};
|
||||
actual = style.getStyle ( para "" );
|
||||
}))
|
||||
(it "fetches style recursively" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para (a "hello"));
|
||||
removeDunders = true;
|
||||
}))
|
||||
|
||||
(it "fetches style for class"
|
||||
(let
|
||||
s = { foo = "bar"; };
|
||||
para = (style.tag "p" "para" {style = s;});
|
||||
in {
|
||||
expected = {"p.para" = s;};
|
||||
actual = style.getStyle ( para "" );
|
||||
}))
|
||||
(it "fetches style recursively through lists" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para [ (a "hello") ]);
|
||||
removeDunders = true;
|
||||
}))
|
||||
|
||||
(it "fetches style recursively"
|
||||
(let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" {style = s."p.para";});
|
||||
a = (style.tag "a" "link" {style = s."a.link";});
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles ( para (a "hello") );
|
||||
}))
|
||||
(it "fetches style recursively with repeats" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
a = (style.tag "a" "link" { style = s."a.link"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para [ (a "hello") (a "hello") ]);
|
||||
removeDunders = true;
|
||||
}))
|
||||
|
||||
(it "fetches style recursively through lists"
|
||||
(let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" {style = s."p.para";});
|
||||
a = (style.tag "a" "link" {style = s."a.link";});
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles ( para [(a "hello")] );
|
||||
}))
|
||||
(it "converts styles to string" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
in {
|
||||
expected = ''
|
||||
a.link {
|
||||
this: that;
|
||||
}
|
||||
p.para {
|
||||
foo: bar;
|
||||
}
|
||||
'';
|
||||
actual = style.stylesToString s;
|
||||
}))
|
||||
|
||||
(it "fetches style recursively with repeats"
|
||||
(let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
para = (style.tag "p" "para" {style = s."p.para";});
|
||||
a = (style.tag "a" "link" {style = s."a.link";});
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles ( para [(a "hello") (a "hello")] );
|
||||
}))
|
||||
(it "extends styled tags" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"p.para.oof" = { oof = "yes"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
|
||||
in {
|
||||
expected = s;
|
||||
actual = style.getStyles (para2 "");
|
||||
removeDunders = true;
|
||||
}))
|
||||
|
||||
(it "converts styles to string"
|
||||
(let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"a.link" = { this = "that"; };
|
||||
};
|
||||
in {
|
||||
expected = ''
|
||||
a.link {
|
||||
this: that;
|
||||
}
|
||||
p.para {
|
||||
foo: bar;
|
||||
}
|
||||
'';
|
||||
actual = style.stylesToString s;
|
||||
}))
|
||||
(it "extends styled tags classes" (let
|
||||
s = {
|
||||
"p.para" = { foo = "bar"; };
|
||||
"p.para.oof" = { oof = "yes"; };
|
||||
};
|
||||
para = (style.tag "p" "para" { style = s."p.para"; });
|
||||
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
|
||||
in {
|
||||
expected = [ "para" "oof" ];
|
||||
actual = (para2 "").attrs.class;
|
||||
}))
|
||||
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue