WIP inheritance
This commit is contained in:
parent
b734310051
commit
35b8cf7472
6 changed files with 169 additions and 84 deletions
|
@ -2,6 +2,19 @@ let
|
|||
html = import ../nixite/html.nix;
|
||||
it = import ./it.nix;
|
||||
in with html; [
|
||||
|
||||
(it "keeps info in the tag" (let p = tag "p";
|
||||
in {
|
||||
actual = p.tag;
|
||||
expected = "p";
|
||||
}))
|
||||
|
||||
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
|
||||
in {
|
||||
actual = p.attrs;
|
||||
expected = { class = ""; };
|
||||
}))
|
||||
|
||||
(it "makes a p tag" {
|
||||
actual = tag "p" { } "Hello";
|
||||
expected = {
|
||||
|
|
5
testing/run.nix
Normal file
5
testing/run.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
pkgs:
|
||||
let test = import ./import.nix;
|
||||
in files:
|
||||
(pkgs.writeShellScriptBin "test"
|
||||
(builtins.concatStringsSep "\n" (map test files)))
|
|
@ -3,55 +3,61 @@ let
|
|||
html = import ../nixite/html.nix;
|
||||
it = import ./it.nix;
|
||||
|
||||
p = style.styled "generic" "p" {
|
||||
foo = "bar";
|
||||
forgetme = "nothing";
|
||||
};
|
||||
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 [
|
||||
|
||||
my = (style.styled "p" "p" { style = { some-style = "some value"; }; })
|
||||
(style.styled "classless" "div" { class = [ ]; })
|
||||
(style.styled "quote" p.generic {
|
||||
(it "makes a p component" (let
|
||||
my = (style.styled "para" "p" { style = { some-style = "some value"; }; });
|
||||
in {
|
||||
expected = html.tag "p" { class = [ "para" ]; } "yes";
|
||||
actual = my.para { } "yes";
|
||||
asString = true;
|
||||
}))
|
||||
|
||||
(it "extends existing components" (let
|
||||
my = (style.styled "generic" "p" {
|
||||
foo = "bar";
|
||||
forgetme = "nothing";
|
||||
});
|
||||
this = (style.styled "quote" my.generic {
|
||||
baz = "baz";
|
||||
forgetme = "forgotten";
|
||||
}) (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 [
|
||||
(it "extends existing components" {
|
||||
in {
|
||||
expected = html.tag "p" {
|
||||
forgetme = "forgotten";
|
||||
baz = "baz";
|
||||
foo = "bar";
|
||||
class = [ "generic" "quote" ];
|
||||
} "yes";
|
||||
actual = my.quote { } "yes";
|
||||
actual = this.quote { } "yes";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a p component" {
|
||||
expected = html.tag "p" { class = [ "p" ]; } "yes";
|
||||
actual = my.p { } "yes";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a component with no class" {
|
||||
expected = html.tag "div" { class = [ ]; } "yes";
|
||||
actual = my.classless { } "yes";
|
||||
asString = true;
|
||||
})
|
||||
}))
|
||||
|
||||
(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" {
|
||||
expected = html.tag "p" { class = [ "p" ]; } "yes";
|
||||
actual = my.p "yes";
|
||||
expected = html.tag "div" { class = [ "div" "something" ]; } "yes";
|
||||
actual = my.div "yes";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a component" {
|
||||
|
@ -88,24 +94,46 @@ in [
|
|||
actual = my.div { id = "foo"; } "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a style" {
|
||||
expected = ''
|
||||
p.p {
|
||||
some-style: some value;
|
||||
}
|
||||
div.something {
|
||||
this: that;
|
||||
}
|
||||
div.something#s {
|
||||
s: yes;
|
||||
}
|
||||
div.foo.bar {
|
||||
something: something;
|
||||
}
|
||||
body {
|
||||
foo: bar;
|
||||
}
|
||||
'';
|
||||
actual = my.style;
|
||||
})
|
||||
(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" { });
|
||||
in {
|
||||
expected = [ "para" ];
|
||||
actual = p.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";
|
||||
};
|
||||
};
|
||||
actual = removeAttrs my.style [ "__toString" ];
|
||||
}))
|
||||
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue